string loadNumber(PaymentTableModel paymentTable) { string numberPT = ""; if (paymentTable.ID == 0) { string current = "BKTT." + DateTime.Now.ToString("ddMMyy"); DataTable dt = LibQLSX.Select("select * from PaymentTable with(nolock) where Number like '%" + current + "%' order by ID desc"); if (dt.Rows.Count > 0) { string number = TextUtils.ToString(dt.Rows[0]["Number"]); int index = TextUtils.ToInt(number.Split('.')[2]); numberPT = current + "." + string.Format("{0:00}", index + 1); } else { numberPT = current + ".01"; } } else { numberPT = paymentTable.Number; } return(numberPT); }
private void grvData_DoubleClick(object sender, EventArgs e) { long paymentTableID = TextUtils.ToInt64(grvData.GetFocusedRowCellValue(colPaymentTableID)); if (paymentTableID == 0) { return; } PaymentTableModel model = (PaymentTableModel)PaymentTableBO.Instance.FindByPK(paymentTableID); frmPaymentTableItem frm = new frmPaymentTableItem(); frm.PaymentTable = model; //frm.LoadDataChange += main_LoadDataChange; frm.Show(); }
private void btnEdit_Click(object sender, EventArgs e) { long id = TextUtils.ToInt64(grvData.GetFocusedRowCellValue(colID)); if (id == 0) { return; } PaymentTableModel model = (PaymentTableModel)PaymentTableBO.Instance.FindByPK(id); _rownIndex = grvData.FocusedRowHandle; frmPaymentTableItem frm = new frmPaymentTableItem(); frm.PaymentTable = model; frm.LoadDataChange += main_LoadDataChange; frm.Show(); }
private void btnDel_Click(object sender, EventArgs e) { long id = TextUtils.ToInt64(grvData.GetFocusedRowCellValue(colID)); if (id == 0) { return; } if (PaymentTableItemBO.Instance.CheckExist("PaymentTableID", id)) { MessageBox.Show("Đề nghị thanh toán này đang chứa vụ việc nên không thể xóa được.", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } if (MessageBox.Show("Bạn có chắc muốn xóa bảng kê thanh toán [" + grvData.GetFocusedRowCellValue(colNumber).ToString() + "] không?", TextUtils.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } PaymentTableModel model = (PaymentTableModel)PaymentTableBO.Instance.FindByPK(id); model.IsDeleted = true; PaymentTableBO.Instance.Update(model); LoadInfoSearch(); }
private void btnAdd_Click(object sender, EventArgs e) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); decimal tm = 0; decimal ck = 0; PaymentTableModel PaymentTable = new PaymentTableModel(); PaymentTable.IsDeleted = false; PaymentTable.Note = ""; PaymentTable.Number = loadNumber(); //PaymentTable.TotalTM = TextUtils.ToDecimal(colTM.SummaryItem.SummaryValue); //PaymentTable.TotalCK = TextUtils.ToDecimal(colCK.SummaryItem.SummaryValue); PaymentTable.UpdatedBy = Global.AppUserName; PaymentTable.UpdatedDate = DateTime.Now; PaymentTable.CreatedBy = Global.AppUserName; PaymentTable.CreatedDate = DateTime.Now; PaymentTable.ID = (long)pt.Insert(PaymentTable); grvData.FocusedRowHandle = -1; for (int i = 0; i < grvData.RowCount; i++) { if (i < 0) { continue; } bool check = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colCheck)); if (!check) { continue; } long iD = TextUtils.ToInt64(grvData.GetRowCellValue(i, colID)); PaymentTableItemModel model = (PaymentTableItemModel)PaymentTableItemBO.Instance.FindByPK(iD); PaymentTableModel pay = (PaymentTableModel)PaymentTableBO.Instance.FindByPK(model.PaymentTableID); pay.TotalTM -= model.TotalCash; pay.TotalCK -= model.TotalCK; pt.Update(pay); model.PaymentTableID = PaymentTable.ID; pt.Update(model); tm += model.TotalCash; ck += model.TotalCK; } pt.CommitTransaction(); PaymentTable.TotalTM = tm; PaymentTable.TotalCK = ck; PaymentTableItemBO.Instance.Update(PaymentTable); loadItems(); }
private void btnCreateBKTT_Click(object sender, EventArgs e) { grvYC.FocusedRowHandle = -1; DataTable dtYC = (DataTable)grdYC.DataSource; DataRow[] drsYC = dtYC.Select("Check = 1"); if (drsYC.Length == 0) { return; } ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { PaymentTableModel PaymentTable = new PaymentTableModel(); PaymentTable.IsDeleted = false; PaymentTable.Number = loadNumber(PaymentTable); //PaymentTable.TotalTM = TextUtils.ToDecimal(colTM.SummaryItem.SummaryValue); //PaymentTable.TotalCK = TextUtils.ToDecimal(colCK.SummaryItem.SummaryValue); PaymentTable.UpdatedBy = Global.AppUserName; PaymentTable.UpdatedDate = DateTime.Now; PaymentTable.CreatedBy = Global.AppUserName; PaymentTable.CreatedDate = DateTime.Now; PaymentTable.ID = (long)pt.Insert(PaymentTable); int count = 0; foreach (DataRow row in drsYC) { PaymentTableItemModel item = new PaymentTableItemModel(); item.Code = TextUtils.ToString(row["OrderCode"]); item.Target = TextUtils.ToString(row["Project"]); item.Name = TextUtils.ToString(row["SupplierName"]); item.Total = TextUtils.ToDecimal(row["TienThanhToan"]); item.TotalTH = TextUtils.ToDecimal(row["TotalPrice"]); item.DeliveryCost = TextUtils.ToDecimal(row["DeliveryCost"]); item.DiffCost = TextUtils.ToDecimal(row["DiffCost"]); item.UserId = TextUtils.ToString(row["UserId"]); //item.ProjectId = TextUtils.ToString(row["Project"]); item.VAT = TextUtils.ToDecimal(row["VAT"]); item.OrderRequirePaidID = TextUtils.ToInt(row["ID"]); item.PaymentTableID = PaymentTable.ID; item.IsCash = TextUtils.ToInt(row["PaymentType"]) == 1 ? true : false; item.PercentPay = TextUtils.ToDecimal(row["PayPercent"]); item.TotalCash = item.IsCash ? TextUtils.ToDecimal(row["TotalPay"]) : 0; item.TotalCK = item.IsCash ? 0 : TextUtils.ToDecimal(row["TotalPay"]); pt.Insert(item); OrdersModel order = (OrdersModel)OrdersBO.Instance.FindByAttribute("OrderId", TextUtils.ToString(row["OrderId"]))[0]; order.StatusTT = 2; pt.UpdateQLSX(order); OrderRequirePaidModel paid = (OrderRequirePaidModel)OrderRequirePaidBO.Instance.FindByPK(TextUtils.ToInt(row["ID"])); paid.Status = 2; pt.Update(paid); count++; } if (count > 0) { pt.CommitTransaction(); MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); loadData(); PaymentTableModel model = (PaymentTableModel)PaymentTableBO.Instance.FindByAttribute("Number", PaymentTable.Number)[0]; frmPaymentTableItem frm = new frmPaymentTableItem(); frm.PaymentTable = model; frm.Show(); } } catch (Exception ex) { MessageBox.Show("Lưu trữ không thành công!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
protected PaymentTableFacade(PaymentTableModel model) : base(model) { }
private void btnExcel_Click(object sender, EventArgs e) { long id = TextUtils.ToInt64(grvData.GetFocusedRowCellValue(colID)); if (id == 0) { return; } PaymentTableModel PaymentTable = (PaymentTableModel)PaymentTableBO.Instance.FindByPK(id); string path = ""; FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() == DialogResult.OK) { path = fbd.SelectedPath; } else { return; } string filePath = Application.StartupPath + "\\Templates\\BKTT.xlsx"; string currentPath = path + "\\" + PaymentTable.Number + ".xlsx"; try { File.Copy(filePath, currentPath, true); } catch (Exception ex) { MessageBox.Show("Có lỗi khi tạo bảng kê thanh toán!" + Environment.NewLine + ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang tạo biểu mẫu...")) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); Excel.Application app = default(Excel.Application); Excel.Workbook workBoook = default(Excel.Workbook); Excel.Worksheet workSheet = default(Excel.Worksheet); try { app = new Excel.Application(); app.Workbooks.Open(currentPath); workBoook = app.Workbooks[1]; workSheet = (Excel.Worksheet)workBoook.Worksheets[1]; workSheet.Cells[6, 1] = "(Số: " + PaymentTable.Number + ")"; workSheet.Cells[13, 8] = "Ngày " + DateTime.Now.ToString("dd/MM/yyyy"); DataTable dtItem = LibQLSX.Select("select * from PaymentTableItem with(nolock) where PaymentTableID = " + PaymentTable.ID); for (int i = dtItem.Rows.Count - 1; i >= 0; i--) { workSheet.Cells[10, 1] = i + 1; workSheet.Cells[10, 2] = TextUtils.ToString(dtItem.Rows[i]["Name"]); workSheet.Cells[10, 3] = TextUtils.ToString(dtItem.Rows[i]["Content"]); workSheet.Cells[10, 4] = TextUtils.ToString(dtItem.Rows[i]["Code"]); workSheet.Cells[10, 5] = TextUtils.ToString(dtItem.Rows[i]["Target"]); workSheet.Cells[10, 6] = TextUtils.ToString(dtItem.Rows[i]["TotalCash"]); workSheet.Cells[10, 7] = TextUtils.ToString(dtItem.Rows[i]["TotalCK"]); workSheet.Cells[10, 8] = TextUtils.ToString(dtItem.Rows[i]["ContentCheck"]); workSheet.Cells[10, 9] = TextUtils.ToString(dtItem.Rows[i]["Note"]); ((Excel.Range)workSheet.Rows[10]).Insert(); } ((Excel.Range)workSheet.Rows[9]).Delete(); ((Excel.Range)workSheet.Rows[9]).Delete(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { if (app != null) { app.ActiveWorkbook.Save(); app.Workbooks.Close(); app.Quit(); } } Process.Start(currentPath); } }