public bool createBills(DataGrid dg, DateTime bill_date, DateTime traffic_month_and_year, bool print) { bool valid = false; foreach (Company c in dg.SelectedItems) { Bill newBill = (Bill)c.Bill.Clone(); newBill.BillDate = bill_date; newBill.BillNumForYear = BillMaxHelper.findMaxBillNumForYear(traffic_month_and_year.Year) + 1; newBill.TrafficMonth = MonthHelper.getMonthFromInt(traffic_month_and_year.Month); newBill.TrafficYear = traffic_month_and_year.Year; newBill.Id = ApplicationA.Instance.Bills[ApplicationA.Instance.Bills.Count - 1].Id + 1; valid = BillDao.Add(newBill); if (valid) { ApplicationA.Instance.Bills.Add(newBill); c.Bill = newBill; ApplicationA.WriteToLogActions(newBill.Id, "racun"); } MessageBox.Show(newBill.Items.Count.ToString()); foreach (Billitem item in newBill.Items) { valid = BillitemDao.Add(item, newBill); if (valid) { item.Id = BillMaxHelper.findMaxBillItemId(newBill); ApplicationA.WriteToLogActions(item.Id, "stavka racuna"); } } if (print) { ExcelFileEditHelper.editExcelFile(c, print); } } return(valid); }
public static void editExcelFile(Company company, bool print) { Bill b = company.Bill; int dateYvalue = 40 + b.Items.Count - 1; //Load Workbook Workbook workbook = new Workbook(); workbook.LoadFromFile(ApplicationA.FILE_NAME_BILL); //Edit Text Worksheet sheet = workbook.Worksheets[0]; sheet.Range["H3"].Text = company.Name; sheet.Range["H4"].Text = company.Address; sheet.Range["H5"].Text = company.City; sheet.Range["H3"].Style.Font.IsBold = true; sheet.Range["H4"].Style.Font.IsBold = true; sheet.Range["H5"].Style.Font.IsBold = true; sheet.Range["J7"].Text = company.Pib; sheet.Range["H13"].Text = b.BillNumForYear + "-" + MonthHelper.getIntFromMonth(b.TrafficMonth) + "-" + (b.TrafficYear - 2000); sheet.Range["H16"].Text = b.TrafficMonth; if (b.Items.Count > 1) { sheet.InsertRow(28, b.Items.Count - 1); sheet.Copy(sheet.Range["A28"], sheet.Range["A28:A" + (26 + b.Items.Count - 1)], true); sheet.Range["B40" + dateYvalue].Text = b.BillDate.Day + "-" + b.BillDate.Month + "-" + b.BillDate.Year; setBorders(27, b.Items.Count + 1, sheet); for (int i = 0; i < b.Items.Count; i++) { fillBillItem(b.Items[i], 28 + i, sheet); } sheet.Range["K" + (29 + b.Items.Count - 1)].Text = BillMaxHelper.getBillValue(b).ToString(); sheet.Range["B" + dateYvalue].Text = b.BillDate.Day + "-" + b.BillDate.Month + "-" + b.BillDate.Year; } else { Billitem item = b.Items[0]; double sum = item.Carpet.Width * item.Carpet.Length * item.Price; fillBillItem(b.Items[0], 28, sheet); sheet.Range["B40"].Text = b.BillDate.Day + "-" + b.BillDate.Month + "-" + b.BillDate.Year; sheet.Range["K29"].Text = Math.Round(sum, 2).ToString(); } //Save and Launch //workbook.SaveToFile("EditSheet.xlsx", ExcelVersion.Version2010); //System.Diagnostics.Process.Start("EditSheet.xlsx"); if (print) { if (b.Dispatcher != "") { sheet.Range["F12"].Text = ""; sheet.Range["F13"].Text = DISPATCHER; } //PrintHelper.printExcelDoc(workbook); } }