private bool CanPrint(object ignored) { if (SelectedItem != null && SelectedItem.Qty > MaximumValue) { return(false); } if (SelectedItem != null && !string.IsNullOrEmpty(SelectedItem.Error)) { return(false); } if (EunKGs != null && EunKGs.Any(w => w.IsChecked == true && w.ID == 0)) { return(false); } return((CountChecked == null && CountChecked.Count.Equals(0)) ? false : (CountChecked.Where(x => x == true).Count() > 0)); }
private bool CanSave(object ignored) { if (SelectedItem != null && SelectedItem.Qty > MaximumValue) { return(false); } if (EunKGs != null && EunKGs.Sum(x => x.Qty) > MaximumValue) { return(false); } if (EunKGs != null && EunKGs.Any(x => !string.IsNullOrEmpty(x.Error))) { return(false); } return(true); }
private void DeleteCommand(object obj) { if (SelectedItem == null) { return; } if (SelectedItem.ID != 0) { this.interactionRequest.Raise( new Confirmation { Content = "Confirm to remove this?", Title = "Confirm" }, c => { if (c.Confirmed) { if (InitDelete(SelectedItem.ID)) { State = "RefreshGrid"; OnLoaded(); } } }); } else { EunKGs.Remove(SelectedItem); _PrintLblCommand.RaiseCanExecuteChanged(); CollectionView = new ListCollectionView(EunKGs); CollectionViewSource.GetDefaultView(CollectionView).Filter = EunKGFilter; } }
private void PrintLabel(object ignored) { if (EunKGs.Any(x => x.IsChecked == true)) { if (MessageBox.Show("Confirm to generate the label?", "Print", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { hlp.SetDialogDescription("Printing..."); worker.DoWork += delegate(object s, DoWorkEventArgs args) { System.Windows.Forms.PrintDialog pd = new System.Windows.Forms.PrintDialog(); pd.PrinterSettings = new PrinterSettings(); pd.PrinterSettings.PrinterName = Properties.Settings.Default.PrinterPort; try { string fileName = string.Empty; string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); fileName = path + @"\JC-WITS_KG.prn"; StreamReader txtReader = new StreamReader(fileName, false); string xTemp = txtReader.ReadToEnd(); txtReader.Close(); var parts = new Dictionary <int, string> [2]; var listObj = EunKGs.Where(x => x.IsChecked == true).ToList(); foreach (var item in listObj) { StringBuilder strPallet = new StringBuilder(); StringBuilder strPalletTemplate = new StringBuilder(); strPallet.Append(string.Empty); strPalletTemplate.Append(string.Empty); strPalletTemplate.Append(xTemp); strPallet = new StringBuilder(); strPallet.Append(strPalletTemplate.ToString()); strPallet.Replace("<PONO>", item.PO); strPallet.Replace("<SAPNO>", item.SAPNO); strPallet.Replace("<LEGACYNO>", item.SAPNO); strPallet.Replace("<BIN>", item.BIN); strPallet.Replace("<QTY>", item.Qty.ToString("G29")); strPallet.Replace("<BUN>", item.EUN); strPallet.Replace("<QRCODE>", item.SAPNO + ";" + item.Qty.ToString()); for (int x = 0; x < 2; x++) { parts[x] = new Dictionary <int, string>(); string input = string.Empty; string lbl = string.Empty; switch (x) { case 0: input = item.EN; lbl = "<EN"; break; case 1: input = item.EN; lbl = "<MS"; break; } string[] words = input.Split(' '); string part = string.Empty; int partCounter = 0; foreach (var word in words) { if (part.Length + word.Length < 33) { part += string.IsNullOrEmpty(part) ? word : " " + word; } else { parts[x].Add(partCounter, part); part = word; partCounter++; } } parts[x].Add(partCounter, part); if (partCounter == 0) { parts[x].Add((partCounter + 1), string.Empty); } foreach (var i in parts[x]) { string index = lbl + (i.Key + 1).ToString() + ">"; strPallet.Replace(index, i.Value); } } if (RawPrinterHelper.SendStringToPrinter(pd.PrinterSettings.PrinterName, strPallet.ToString()) == false) { } if (worker.CancellationPending) { args.Cancel = true; return; } hlp.Initialize(); } State = "RefreshGrid"; OnLoaded(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }; worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args) { hlp.pgdialog.Close(); }; worker.RunWorkerAsync(); hlp.pgdialog.Visibility = Visibility.Visible; } } }