Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class CircuitInstallationScheduledWindow : Window
- {
- DataSet mainWorkbook, Access;
- string tSubject, tCC, tHTML;
- DataTable previewTable;
- public CircuitInstallationScheduledWindow(DataSet mainWorkbook, string tSubject, string tCC, string tHTML)
- {
- this.tSubject = tSubject;
- this.tCC = tCC;
- this.tHTML = tHTML;
- this.mainWorkbook = mainWorkbook;
- InitializeComponent();
- Access = ABFS_Database.getTables();
- previewTable = MakePreview();
- previewGrid.ItemsSource = previewTable.AsDataView();
- }
- public DataTable MakePreview()
- {
- //gets all rows from the "Salesforce Report Weekly" sheet with FOC dates which are today or in the future.
- var table = (from row in mainWorkbook.Tables["Salesforce Report Weekly"].AsEnumerable()
- where row.Field<DateTime?>("Target Circuit Completion (FOC)") >= DateTime.Today
- select row).AsDataView().ToTable(false, "Opportunity: Store Number", "Target Circuit Completion (FOC)", "Vendor Name");
- //gets all rows from the ALreadySent table where the Notification Type is "Install Scheduled".
- var sentCIS = (from row in Access.Tables["AlreadySent"].AsEnumerable()
- where row.Field<string>("NotificationType") == "Install Scheduled"
- select row).AsDataView().ToTable();
- //filters out rows in 'table' which were already sent and recorded in the Access database.
- var filteredTable = table.AsEnumerable()
- .Where(t1 => !sentCIS.AsEnumerable()
- .Any(t2 => t2.Field<int>("StoreNumber") == t1.Field<double>("Opportunity: Store Number")
- && Math.Abs((t2.Field<DateTime>("TargetCircuitCompletionFOC") - t1.Field<DateTime>("Target Circuit Completion (FOC)")).TotalDays)<1)).AsDataView().ToTable();
- //join filtered table with McDonalds Contact Master.
- var contacts = mainWorkbook.Tables["MCD Contact Master"].AsDataView().ToTable(false, "National Store .","Contacts - ACM - Email", "OO - Ops Mgr Name",
- "OO - Ops Mgr Name", "Contacts - Area Sup / BC - Email", "Contacts - OTP - Email", "OTM Email Address");
- DataTable resultTable = new DataTable();
- foreach(string name in new string[]{"Opportunity: Store Number", "Target Circuit Completion (FOC)", "Vendor Name","Contacts - ACM - Email", "OO - Ops Mgr Name", "OO - Ops Mgr Name", "Contacts - Area Sup / BC - Email", "Contacts - OTP - Email", "OTM Email Address"})
- {
- resultTable.Columns.Add(name);
- }
- var joinedTables = from tableRow in filteredTable.AsEnumerable()
- join contactsRow in contacts.AsEnumerable()
- on tableRow.Field<double>("Opportunity: Store Number") equals contactsRow.Field<double>("National Store .")
- into lj
- from r in lj.DefaultIfEmpty()
- select resultTable.LoadDataRow(new object[]
- {
- tableRow.Field<double>("Opportunity: Store Number"),
- tableRow.Field<DateTime>("Target Circuit Completion (FOC)"),
- tableRow.Field<string>("Vendor Name"),
- contactsRow.Field<string>("Contacts - ACM - Email")
- }, false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement