private void RibbonButtonAddToExport_OnClick(object sender, RoutedEventArgs e) { if (View.CurrentItem == null) { return; } var requests = GridViewRequests.SelectedItems; foreach (var request in requests) { RequestWithNotify requestWithNotify = (RequestWithNotify)request; int index = RequestsCollection.IndexOf(requestWithNotify); requestWithNotify.Export = true; } }
private void ButtonAdd_OnClick(object sender, RoutedEventArgs e) { ClearStatusbar(); if (TextBoxResolutionPartNo.Text.Length == 0 && TextBoxPartNo.Text.Length == 0 && TextBoxPartNoOriginal.Text.Length == 0) { ShowMessageInStatusbar("you should provide at least one part no"); return; } if (DatePickerRequestDate.SelectedValue == null) { ShowMessageInStatusbar("Request date can not be empty"); return; } if (NumericUpDownQty.Value == null) { ShowMessageInStatusbar("Qty can not be empty"); return; } RequestWithNotify requestWithNotify = new RequestWithNotify(); requestWithNotify.ResolutionPartNo = TextBoxResolutionPartNo.Text; requestWithNotify.PartNo = TextBoxPartNo.Text; requestWithNotify.PartNoOriginal = TextBoxPartNoOriginal.Text; requestWithNotify.RequestDate = (DateTime)DatePickerRequestDate.SelectedValue; requestWithNotify.Qty = (int)NumericUpDownQty.Value; requestWithNotify.EntranceDate = DatePickerEntranceDate.SelectedValue; requestWithNotify.Description = TextBoxDescription.Text; requestWithNotify.RequestStatus = (RequestStatus)ComboBoxRequestStatus.SelectedIndex; var result = RequestsCollection.AddNew(0, requestWithNotify); if (result) { ShowMessageInStatusbar("new requestd added"); } else { ShowMessageInStatusbar("Failed"); } }
private void RibbonButtonDelete_OnClick(object sender, RoutedEventArgs e) { if (View.CurrentItem == null) { ClearStatusbar(); ShowMessageInStatusbar("First select an item"); return; } var result = RequestsCollection.Delete(View.CurrentPosition); ClearStatusbar(); if (result) { ShowMessageInStatusbar("Request removed"); } else { ShowMessageInStatusbar("Failed"); } }
private void RibbonButtonExportToExcel_OnClick(object sender, RoutedEventArgs e) { FileInfo fileInfo = null; SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "Excel Workbook| *.xls;*.xlsx"; if (saveFileDialog.ShowDialog() == true) { fileInfo = new FileInfo(saveFileDialog.FileName); } if (fileInfo != null && fileInfo.Exists) { fileInfo.Delete(); } ExcelPackage excelPackage = new ExcelPackage(fileInfo); var ws = excelPackage.Workbook.Worksheets.Add("Parts"); //ws.View.RightToLeft = true; ws.Cells.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; ws.Cells["A1"].Value = "Part Name"; ws.Cells["B1"].Value = "Part no"; ws.Cells["C1"].Value = "Brand"; ws.Cells["D1"].Value = "Original Part no"; ws.Cells["E1"].Value = "Machine"; ws.Cells["F1"].Value = "Machine Code"; ws.Cells["G1"].Value = "Qty"; ws.Cells["A1:G1"].Style.Font.Bold = true; var requests = RequestsCollection.Where(x => x.Export == true); int i = 2; foreach (var requestWithNotify in requests) { IEnumerable <Part> parts = null; Part firstPart = null; string partNo = ""; if (!string.IsNullOrEmpty(requestWithNotify.PartNo)) { parts = Entities.Parts.Where(x => x.PartNo == requestWithNotify.PartNo); partNo = requestWithNotify.PartNo; } else if (!string.IsNullOrEmpty(requestWithNotify.ResolutionPartNo)) { parts = Entities.Parts.Where(x => x.ResolutionPartNo == requestWithNotify.ResolutionPartNo); partNo = requestWithNotify.ResolutionPartNo; } else if (!string.IsNullOrEmpty(requestWithNotify.PartNoOriginal)) { parts = Entities.Parts.Where(x => x.PartNoOrignal == requestWithNotify.PartNoOriginal); partNo = requestWithNotify.PartNoOriginal; } firstPart = parts.FirstOrDefault(); ws.Cells[string.Format("A{0}", i)].Value = firstPart.PartName; ws.Cells[string.Format("B{0}", i)].Value = partNo; ws.Cells[string.Format("C{0}", i)].Value = firstPart.Brand.BrandName; ws.Cells[string.Format("D{0}", i)].Value = firstPart.PartNoOrignal; var machines = from part in parts select part.Machine.MachineName; var machinesDistinct = machines.Distinct(); string machinesComma = string.Join(",", machinesDistinct); var machinesCode = from part2 in parts select part2.Machine.MachineCode; var machinesCodeDistinct = machinesCode.Distinct(); string machinesCodeComma = string.Join(",", machinesCodeDistinct); ws.Cells[string.Format("E{0}", i)].Value = machinesComma; ws.Cells[string.Format("F{0}", i)].Value = machinesCodeComma; ws.Cells[string.Format("G{0}", i)].Value = requestWithNotify.Qty; i++; } excelPackage.Save(); }