void save() { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } //PartA.Name = txtName.Text.Trim().ToUpper(); //PartA.Code = txtCode.Text.Trim().ToUpper(); //PartA.Type = cboType.SelectedIndex; //PartA.Unit = txtUnit.Text.Trim(); PartA.QtyMin = TextUtils.ToDecimal(txtQtyMin.EditValue); PartA.QtyDM = TextUtils.ToDecimal(txtQtyDM.EditValue); PartA.ProjectPercent = TextUtils.ToDecimal(txtProjectPercent.EditValue); //PartA.Price = TextUtils.ToDecimal(txtPrice.EditValue); PartA.IsProject = PartA.ProjectPercent > 0 ? 1 : 0; PartA.Qty = TextUtils.ToDecimal(txtQty.EditValue); //PartA.Hang = txtHang.Text.Trim(); //if (PartA.ID == 0) //{ // PartA.ID = (int)pt.Insert(PartA); //} //else //{ pt.UpdateQLSX(PartA); //} pt.CommitTransaction(); _isSaved = true; MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
private void btnSave_Click(object sender, EventArgs e) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } grvData.FocusedRowHandle = -1; PaymentTable.IsDeleted = false; PaymentTable.Note = ""; PaymentTable.Number = txtNumber.Text.Trim(); PaymentTable.TotalTM = TextUtils.ToDecimal(colTM.SummaryItem.SummaryValue); PaymentTable.TotalCK = TextUtils.ToDecimal(colCK.SummaryItem.SummaryValue); PaymentTable.UpdatedBy = Global.AppUserName; PaymentTable.UpdatedDate = DateTime.Now; if (PaymentTable.ID == 0) { PaymentTable.CreatedBy = Global.AppUserName; PaymentTable.CreatedDate = DateTime.Now; PaymentTable.ID = (long)pt.Insert(PaymentTable); } else { pt.Update(PaymentTable); } for (int i = 0; i < grvData.RowCount; i++) { string code = TextUtils.ToString(grvData.GetRowCellValue(i, colCode)); if (code == "") { continue; } long id = TextUtils.ToInt64(grvData.GetRowCellValue(i, colID)); PaymentTableItemModel item = new PaymentTableItemModel(); if (id > 0) { item = (PaymentTableItemModel)PaymentTableItemBO.Instance.FindByPK(id); } item.Code = code; item.Content = TextUtils.ToString(grvData.GetRowCellValue(i, colContent)); item.ContentCheck = TextUtils.ToString(grvData.GetRowCellValue(i, colContentCheck)); item.Target = TextUtils.ToString(grvData.GetRowCellValue(i, colTarget)); item.Name = TextUtils.ToString(grvData.GetRowCellValue(i, colName)); item.Note = TextUtils.ToString(grvData.GetRowCellValue(i, colNote)); item.PaymentTableID = PaymentTable.ID; item.IsCash = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsTM)); item.Total = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTotal)); item.TotalTH = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTotalTH)); item.DeliveryCost = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colDeliveryCost)); item.DiffCost = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colDiffCost)); item.PercentPay = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colPercentPay)); item.TotalCash = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colTM)); item.TotalCK = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colCK)); item.UserId = TextUtils.ToString(grvData.GetRowCellValue(i, colOrderUserId)); item.CompanyID = TextUtils.ToInt(grvData.GetRowCellValue(i, colCompany)); item.DepartmentId = TextUtils.ToString(grvData.GetRowCellValue(i, colDepartment)); item.ProjectId = TextUtils.ToString(grvData.GetRowCellValue(i, colProject)); item.CostID = TextUtils.ToInt(grvData.GetRowCellValue(i, colCost)); item.CountProject = TextUtils.ToInt(grvData.GetRowCellValue(i, colCountProject)); item.VAT = TextUtils.ToDecimal(grvData.GetRowCellValue(i, colVAT)); item.ContractStatus = TextUtils.ToInt1(grvData.GetRowCellValue(i, colContractStatus)); item.InvoiceStatus = TextUtils.ToInt1(grvData.GetRowCellValue(i, colInvoiceStatus)); item.IsPO = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsPO)); item.IsCongNo = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsCongNo)); item.IsCuongVe = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsCuongVe)); item.IsGDD = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsGĐĐ)); item.IsTTGH = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsTTGH)); item.IsVV_DA_NCC = TextUtils.ToBoolean(grvData.GetRowCellValue(i, colIsVV_DA_NCC)); if (id > 0) { pt.Update(item); } else { pt.Insert(item); } ArrayList listOrder = OrdersBO.Instance.FindByAttribute("OrderCode", item.Code); if (listOrder.Count > 0) { OrdersModel order = (OrdersModel)listOrder[0]; order.StatusTT = 2; pt.UpdateQLSX(order); } } pt.CommitTransaction(); loadItems(); _isSaved = true; MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); if (this.LoadDataChange != null) { this.LoadDataChange(null, null); } } 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(); } }
void save() { if (IsNew) { MessageBox.Show("Bạn không thể tạo mới nhà cung cấp!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } #region NCC if (IsNew) { Supplier = new SuppliersModel(); } Supplier.Address = txtAddress.Text; Supplier.Agency = txtAgency.Text; Supplier.BangDanhGia = chkBangDanhGia.Checked; Supplier.BankAcount = txtBankAccount.Text; Supplier.BankAcountName = txtBankAccountName.Text; Supplier.BankName = txtBankName.Text; Supplier.ContactPerson = txtContactPerson.Text; Supplier.ContactPhone = txtContactPhone.Text; Supplier.Discount = TextUtils.ToDecimal(txtDiscount.Text); Supplier.DKKD = chkDKKD.Checked; Supplier.Email = txtEmail.Text; Supplier.HopDongNguyenTac = chkHopDongNguyenTac.Checked; Supplier.MaterialGroup = cboMaterialGroup.SelectedIndex; Supplier.MST = txtMST.Text; //Supplier.NhanTinStatus = 0; Supplier.Note = txtNote.Text; Supplier.Office = txtOffice.Text; Supplier.PaymentTerm = txtPaymentTerm.Text; Supplier.Phone = txtPhone.Text; Supplier.ProductProvided = txtProductProvided.Text; Supplier.StatusDisable = cboStatus.SelectedIndex; Supplier.SupplierCode = txtCode.Text; //Supplier.SupplierERPId = _supplierId; //Supplier.SupplierId = _supplierId; Supplier.SupplierName = txtName.Text; //Supplier.UserId = TextUtils.ToString(cboUser.EditValue); Supplier.UyQuyenHang = chkUyQuyenHang.Checked; Supplier.UpdatedDate = DateTime.Now; if (IsNew) { Supplier.DateArising = DateTime.Now; pt.InsertQLSX(Supplier); } else { pt.UpdateQLSX(Supplier); } #endregion #region Nguoi phu trach foreach (DataGridViewRow row in grvUser.Rows) { int id = TextUtils.ToInt(row.Cells["colULinkId"].Value); SuppliersUserLinkModel linkModel = new SuppliersUserLinkModel(); if (id > 0) { linkModel = (SuppliersUserLinkModel)SuppliersUserLinkBO.Instance.FindByPK(id); } linkModel.SupplierId = Supplier.SupplierId; linkModel.UserId = TextUtils.ToString(row.Cells["colUId"].Value); if (id > 0) { pt.Update(linkModel); } else { pt.Insert(linkModel); } } #endregion #region Hang cung cap foreach (DataGridViewRow row in grvHang.Rows) { int id = TextUtils.ToInt(row.Cells["colHLinkID"].Value); SuppliersManufacturerLinkModel linkModel = new SuppliersManufacturerLinkModel(); if (id > 0) { linkModel = (SuppliersManufacturerLinkModel)SuppliersManufacturerLinkBO.Instance.FindByPK(id); } linkModel.SupplierId = Supplier.SupplierId; linkModel.ManufacturerId = TextUtils.ToString(row.Cells["colHid"].Value); if (id > 0) { pt.Update(linkModel); } else { pt.Insert(linkModel); } } #endregion #region Hợp đồng foreach (DataGridViewRow row in grvContract.Rows) { int id = TextUtils.ToInt(row.Cells["colContractID"].Value); SupplierContractModel model = new SupplierContractModel(); if (id > 0) { model = (SupplierContractModel)SupplierContractBO.Instance.FindByPK(id); } model.SupplierId = Supplier.SupplierId; model.ContractType = TextUtils.ToInt(row.Cells["colContractType"].Value); model.SignDate = TextUtils.ToDate2(row.Cells["colSignDate"].Value); model.OutDate = TextUtils.ToDate2(row.Cells["colOutDate"].Value); if (id > 0) { pt.Update(model); } else { pt.Insert(model); } } #endregion #region Nhóm vật tư foreach (DataGridViewRow row in grvMaterialGroup.Rows) { int id = TextUtils.ToInt(row.Cells["colGroupLinkID"].Value); SupplierMaterialGroupLinkModel model = new SupplierMaterialGroupLinkModel(); if (id > 0) { model = (SupplierMaterialGroupLinkModel)SupplierMaterialGroupLinkBO.Instance.FindByPK(id); } model.SupplierId = Supplier.SupplierId; model.MaterialGroupID = TextUtils.ToInt(row.Cells["colMaterialGroupID"].Value); if (id > 0) { pt.Update(model); } else { pt.Insert(model); } } #endregion pt.CommitTransaction(); IsNew = false; _isSaved = true; loadHangGrid(); loadUserGrid(); loadContractGrid(); loadMaterialGroupGrid(); MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }
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(); } }