private async void BtnPrnt_Click(object sender, RoutedEventArgs e) { protoWeightLabel = await ApplicationData.Current.LocalFolder.GetFileAsync(@"Labels\Supplier.x"); //edit label with real dat if (txtBoxLot.Text == string.Empty || txtBoxLot.Text == null) { App.PrintOkMessage(ResourceLoader.GetForViewIndependentUse("Resources").GetString("msgLot"), ResourceLoader.GetForViewIndependentUse("Resources").GetString("titleLabelError")); return; } if (protoWeightLabel != null) { //fill the data IBuffer bf = await FileIO.ReadBufferAsync(protoWeightLabel); DataReader reader = DataReader.FromBuffer(bf); byte[] fileContent = new byte[reader.UnconsumedBufferLength]; reader.ReadBytes(fileContent); string protoVal = encoding.GetString(fileContent, 0, fileContent.Length); string newVal = protoVal.Replace("supplierdescr", SelectedSupplier.SupplierDescr); newVal = newVal.Replace("grsupplier", SelectedSupplier.GrSupplier); newVal = newVal.Replace("lot", txtBoxLot.Text); newVal = newVal.Replace("datereceipt", DateTime.Now.ToString("dd-MM-yyyy")); newVal = newVal.Replace("nums", printsSpinner.TextValueProperty.ToString()); dataWeightLabel = await ApplicationData.Current.LocalFolder.CreateFileAsync("Data" + protoWeightLabel.Name, CreationCollisionOption.ReplaceExisting); File.WriteAllText(dataWeightLabel.Path, newVal, encoding); } PrinterUtil.SendToPrinterFile(dataWeightLabel); }
private async void BtnPrnt_Click(object sender, RoutedEventArgs e) { protoWeightLabel = await ApplicationData.Current.LocalFolder.GetFileAsync(@"Labels\Customer.x"); //edit label with real data if (protoWeightLabel != null) { //fill the data IBuffer bf = await FileIO.ReadBufferAsync(protoWeightLabel); DataReader reader = DataReader.FromBuffer(bf); byte[] fileContent = new byte[reader.UnconsumedBufferLength]; reader.ReadBytes(fileContent); string protoVal = App.encoding.GetString(fileContent, 0, fileContent.Length); string newVal = protoVal.Replace("customerdescr", SelectedCustomer.CustomerDescr); newVal = newVal.Replace("nums", printsSpinner.TextValueProperty.ToString()); dataWeightLabel = await ApplicationData.Current.LocalFolder.CreateFileAsync("Data" + protoWeightLabel.Name, CreationCollisionOption.ReplaceExisting); File.WriteAllText(dataWeightLabel.Path, newVal, App.encoding); } PrinterUtil.SendToPrinterFile(dataWeightLabel); }
private async void BtnPrnt_Click(object sender, RoutedEventArgs e) { //edit label with real data if (SelectedSupplier.Code == "000" && (SelectedMaterial.Type == PackagedMaterialItem.MaterialType.BIO || SelectedMaterial.Type == PackagedMaterialItem.MaterialType.SEMIBIO)) { App.PrintOkMessage(ResourceLoader.GetForViewIndependentUse("Resources").GetString("msgGrSupplier"), ResourceLoader.GetForViewIndependentUse("Resources").GetString("titleLabelError")); return; } if (String.IsNullOrEmpty(CBoxLotNums.Text) || String.IsNullOrEmpty(SelectedLot.Code)) { App.PrintOkMessage(ResourceLoader.GetForViewIndependentUse("Resources").GetString("msgLot"), ResourceLoader.GetForViewIndependentUse("Resources").GetString("titleLabelError")); return; } //Check printer settings if (AppSettings.SumPrints > 1 || AppSettings.PalletsNum > 1) { step++; sum += Double.Parse(txtNetW.Text.Remove(txtNetW.Text.Length - 3, 3)); txtSum.Text = ResourceLoader.GetForCurrentView().GetString("lblPallet") + pallet.ToString() + " - " + ResourceLoader.GetForCurrentView().GetString("Step") + step.ToString() + "/" + AppSettings.SumPrints + " - " + ResourceLoader.GetForCurrentView().GetString("lblTotal") + sum.ToString() + AppSettings.TrailingUnit; } if (currentLabel != null) { //copy label file to public folder for editing rights //await protoWeightLabel.CopyAsync(ApplicationData.Current.LocalFolder, "WeightData.x",NameCollisionOption.ReplaceExisting); //fill the data IBuffer bf = await FileIO.ReadBufferAsync(currentLabel); DataReader reader = DataReader.FromBuffer(bf); byte[] fileContent = new byte[reader.UnconsumedBufferLength]; reader.ReadBytes(fileContent); string protoVal = App.encoding.GetString(fileContent, 0, fileContent.Length); string newVal = protoVal.Replace("materialdescr", SelectedMaterial.MaterialReadableDescr); newVal = newVal.Replace("country", SelectedMaterial.Country); newVal = newVal.Replace("region", SelectedMaterial.Region); newVal = newVal.Replace("grsupplier", SelectedSupplier.GrSupplier + SelectedMaterial.GRmaterial); newVal = newVal.Replace("category", SelectedMaterial.Category); newVal = newVal.Replace("variety", SelectedMaterial.Variety); newVal = newVal.Replace("datereceipt", DateTime.Now.ToString("dd-MM-yyyy")); if (Decimal.Parse(txtNetW.Text.Substring(0, txtNetW.Text.Length - 3)) > 0) { newVal = newVal.Replace("descrweightval", "Καθαρό Βάρος:"); newVal = newVal.Replace("weightval", txtNetW.Text); } else { newVal = newVal.Replace("descrweightval", " "); newVal = newVal.Replace("weightval", " "); } newVal = newVal.Replace("lot", SelectedLot.Code); newVal = newVal.Replace("nums", printsSpinner.TextValueProperty.ToString()); dataLabel = await ApplicationData.Current.LocalFolder.CreateFileAsync("Data" + currentLabel.Name, CreationCollisionOption.ReplaceExisting); File.WriteAllText(dataLabel.Path, newVal, App.encoding); //StorageFolder publicFolder = ApplicationData.Current.LocalFolder; //dataLabelFile = await publicFolder.GetFileAsync("WeightData.x"); } PrinterUtil.SendToPrinterFile(dataLabel); if (step == AppSettings.SumPrints) { await Task.Delay(TimeSpan.FromSeconds(2)); //Thread.Sleep(2000); if ((pallet + 1) == AppSettings.PalletsNum) { //print last pallet sum PrinterUtil.SendTestToPrinter(sum.ToString() + AppSettings.TrailingUnit, AppSettings.CopiesPrints.ToString()); AppSettings.CopiesPrints = 1; AppSettings.SumPrints = 1; AppSettings.PalletsNum = 1; txtSum.Text = String.Empty; } else { PrinterUtil.SendTestToPrinter(sum.ToString() + AppSettings.TrailingUnit, AppSettings.CopiesPrints.ToString()); pallet++; step = 0; sum = 0; txtSum.Text = ResourceLoader.GetForCurrentView().GetString("lblPallet") + pallet.ToString() + " - " + ResourceLoader.GetForCurrentView().GetString("Step") + step.ToString() + "/" + AppSettings.SumPrints + " - " + ResourceLoader.GetForCurrentView().GetString("lblTotal") + sum.ToString() + AppSettings.TrailingUnit; } } }