private void checkout_bt_Click(object sender, EventArgs e) { try { if (cust_contact_tb.Text == "" || cashPaid_tb.Text == "" || total_tb.Text == "" || change_tb.Text == "") { MessageBox.Show("Textbox Empty!"); } else {//////////pdf Document doc = new Document(iTextSharp.text.PageSize.A4); string fileName = "D:\\Dropbox\\Project\\Project 5.1\\Medical Store\\receipts\\" + saleId_tb.Text + ".pdf"; PdfWriter pd = PdfWriter.GetInstance(doc, new FileStream(fileName, FileMode.Create)); doc.Open(); Paragraph para; para = new Paragraph("****Medical Store****"); para.Alignment = 1; doc.Add(para); para = new Paragraph("Date: " + date.Text); para.Alignment = 0; doc.Add(para); para = new Paragraph("Time: " + DateTime.Now.TimeOfDay); para.Alignment = 2; doc.Add(para); para = new Paragraph("SaleId: " + saleId_tb.Text); para.Alignment = 2; doc.Add(para); para = new Paragraph("Customer Contact: " + cust_contact_tb.Text); para.Alignment = 2; doc.Add(para); para = new Paragraph("Salesman: " + user.UserId + "\n\n"); para.Alignment = 2; doc.Add(para); PdfPTable table = new PdfPTable(4); PdfPCell cell = new PdfPCell(new Phrase("Medicine Name")); cell.HorizontalAlignment = 1; table.AddCell(cell); cell = new PdfPCell(new Phrase("Quantity")); cell.HorizontalAlignment = 1; table.AddCell(cell); cell = new PdfPCell(new Phrase("Unit Price")); cell.HorizontalAlignment = 1; table.AddCell(cell); cell = new PdfPCell(new Phrase("Amount")); cell.HorizontalAlignment = 1; table.AddCell(cell); pursServ = new PurchaseService(); List <Purchase> purc = pursServ.GetAll(pur.SaleId); foreach (var item in purc) { table.AddCell(item.MedName); table.AddCell(item.Quantity.ToString()); table.AddCell(item.UnitPrice.ToString()); table.AddCell(item.Amount.ToString()); } doc.Add(table); para = new Paragraph("Total: " + total_tb.Text + "\nCash Paid: " + cashPaid_tb.Text + "\nChange: " + change_tb.Text + "\n"); para.Alignment = 2; doc.Add(para); doc.Close(); ///// Profit pursServ = new PurchaseService(); List <Purchase> purs2 = pursServ.GetAll(pur.SaleId); foreach (var item in purs2) { Medicine med = new Medicine(); medServ = new MedicineService(); med = medServ.GetMed(item.MedId); med.Quantity = med.Quantity - item.Quantity; medServ = new MedicineService(); int res = medServ.UpdateMed(med); prof = new Profit(); prof.SaleId = item.SaleId; prof.MedId = item.MedId; prof.Date = Convert.ToDateTime(date.Text); prof.Income = item.Amount - (med.BuyingPrice * item.Quantity); profServ = new ProfitService(); int rsl = profServ.Insert(prof); } //// History HistoryService hisServ; CustHistory custHis; pursServ = new PurchaseService(); List <Purchase> purs = pursServ.GetAll(pur.SaleId); List <CustHistory> histories = new List <CustHistory>(); foreach (var item in purs) { custHis = new CustHistory(); custHis.Date = Convert.ToDateTime(date.Text); custHis.Contact = Convert.ToInt32(cust_contact_tb.Text); custHis.SaleId = Convert.ToInt32(item.SaleId); custHis.MedName = item.MedName; custHis.Quantity = item.Quantity; hisServ = new HistoryService(); int rst = hisServ.Insert(custHis); } //////Sale pursServ = new PurchaseService(); List <Purchase> purs1 = pursServ.GetAll(pur.SaleId); List <Sale> sales = new List <Sale>(); foreach (var item in purs1) { sal = new Sale(); sal.Date = Convert.ToDateTime(date.Text); sal.SaleId = item.SaleId; sal.MedName = item.MedName; sal.Quantity = item.Quantity; salServ = new SaleService(); int rlt = salServ.Insert(sal); } new Home(user).Show(); this.Hide(); } } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } }
public int Insert(CustHistory his) { return(hisRepo.Insert(his)); }