private void button1_Click(object sender, EventArgs e) { try { if (CustomeRepository.IsExistsDifferentLog( commonFunctions.ToInt(cmb_days.SelectedValue.ToString()), commonFunctions.ToInt(cmb_sessions.SelectedValue.ToString()), commonFunctions.ToInt(cmb_pumper.SelectedValue.ToString()) ) > 0) { MessageBox.Show("Already Printed for this Day ,Session and pumper ", Messaging.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MessageBox.Show("Do you want to Save and Print this record?", Messaging.MessageCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DifferentLog log = new DifferentLog(); log.CardTotal = commonFunctions.ToDecimal(lbl_card.Text.Trim()); log.CashTotal = commonFunctions.ToDecimal(lbl_cash.Text.Trim()); log.VoucherTotal = commonFunctions.ToDecimal(lbl_Voucher.Text.Trim()); log.Expenses = commonFunctions.ToDecimal(lbl_expense.Text.Trim()); log.Testing = commonFunctions.ToDecimal(lbl_othertotal.Text.Trim()); log.DayID = commonFunctions.ToInt(cmb_days.SelectedValue.ToString()); log.PumperId = commonFunctions.ToInt(cmb_pumper.SelectedValue.ToString()); log.SessionId = commonFunctions.ToInt(cmb_sessions.SelectedValue.ToString()); log.SystemTotal = commonFunctions.ToDecimal(lbl_systemtotal.Text.Trim()); log.TotalCollection = commonFunctions.ToDecimal(lbl_totalCollection.Text.Trim()); log.Differences = commonFunctions.ToDecimal(lbl_diff.Text.Trim()); log.DiffCaculated = true; log.IsFinal = true; log.IgnoreDiff = chk_ignorediff.Checked; log.ModifiedDate = DateTime.Now; log.CreatedDate = DateTime.Now; log.CreatedUser = commonFunctions.LoginuserID; log.ModifiedUser = commonFunctions.LoginuserID; log.DataTransfer = 1; CustomeRepository.InsertSalesPrint(log); string filename = PrintRepository.WriteSimpleReciept(log, cmb_pumper.Text, commonFunctions.GlobalCompany); System.Diagnostics.Process.Start(filename); } } catch (Exception ex) { MessageBox.Show("Error Has found in program. Please forword following details to technical" + Environment.NewLine + "[" + ex.Message + Environment.NewLine + ex.Source + "]", Messaging.MessageCaption, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static StreamWriter WriteToFIle(DifferentLog entuty, string pumpername, string dirname, string filename, string CompanyName) { StreamWriter sr = new StreamWriter(Path.Combine(dirname, filename)); for (int i = 0; i < 2; i++) { if (i == 0) { WriteLine(sr, "--------Cashier Copy--------"); } else { WriteLine(sr, "--------Pumper Copy--------"); } WriteLine(sr, "Daily Sales"); if (CompanyName.Length > 30) { WriteLine(sr, CompanyName.Substring(0, 30)); //"FSFS Distributors Waththala"); } else { WriteLine(sr, CompanyName); //"FSFS Distributors Waththala"); } WriteLineRight(sr, "Pumper : " + pumpername.Trim()); WriteLineRight(sr, "Date : " + DateTime.Now.ToShortDateString()); WriteLine(sr, "------------------------------"); WriteLineRight(sr, "Cash Total : " + String.Format("{0,15}", entuty.CashTotal.ToString())); WriteLineRight(sr, "Card Total : " + String.Format("{0,15}", entuty.CardTotal.ToString())); WriteLineRight(sr, "Voucher Total: " + String.Format("{0,15}", entuty.VoucherTotal.ToString())); WriteLineRight(sr, "Expenses : " + String.Format("{0,15}", entuty.Expenses.ToString())); WriteLineRight(sr, "Testing Total: " + String.Format("{0,15}", entuty.Testing.ToString())); WriteLineRight(sr, "------------------------------"); WriteLineRight(sr, "System Total: " + String.Format("{0,15}", entuty.SystemTotal.ToString())); WriteLineRight(sr, "Collection : " + String.Format("{0,15}", entuty.TotalCollection.ToString())); WriteLineRight(sr, "Difference : " + String.Format("{0,15}", entuty.Differences.ToString())); WriteLineRight(sr, String.Format("")); WriteLineRight(sr, String.Format("{0,-15}", "--------------") + String.Format("{0,15}", "--------------")); WriteLineRight(sr, String.Format("{0,-15}", pumpername.Trim()) + String.Format("{0,15}", "Cashier")); WriteLineRight(sr, String.Format("")); WriteLineRight(sr, String.Format("")); } return(sr); }
public static int InsertSalesPrint(DifferentLog entity) { try { XMLTool xmlcreate = new XMLTool(); string xmlString = xmlcreate.Serialize(entity); _connectionName = ConfigurationManager.ConnectionStrings["ConnFSMS"].ConnectionString; using (IDbConnection db = new SqlConnection(_connectionName)) { var resfult = db.QuerySingle <DifferentLog>("SP_UpdateSalesEntries", new { XMLDetails = xmlString }, commandType: CommandType.StoredProcedure); return(1); } } catch (Exception ex) { throw ex; } }
public static string WriteSimpleReciept(DifferentLog entuty, string pumpername, string CompName) { string dirname = Path.Combine(Environment.CurrentDirectory, FileFolder); string filename = DateTime.Now.Year + "_" + DateTime.Now.Month + "_" + DateTime.Now.Day + "_" + DateTime.Now.Hour + "_" + DateTime.Now.Minute + "_" + DateTime.Now.Second + "_" + DateTime.Now.Millisecond + pumpername.Trim().Replace(".", string.Empty) + ".txt"; if (!Directory.Exists(dirname)) { DirectoryInfo dir = Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, FileFolder)); } if (!File.Exists(filename)) { FileStream fs = File.Create(Path.Combine(dirname, filename)); fs.Close(); } StreamWriter sr = WriteToFIle(entuty, pumpername, dirname, filename, CompName); sr.Close(); return(Path.Combine(dirname, filename)); }