void save(bool close) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } grvFile.FocusedRowHandle = -1; #region Save Solution Solution.Name = txtName.Text.Trim().ToUpper(); Solution.Code = txtCode.Text.Trim(); Solution.RequireSolutionID = TextUtils.ToInt64(cboRequire.EditValue); Solution.Description = txtDescription.Text; Solution.WorkDescription = txtWorkDescription.Text; Solution.Version = 1; Solution.Status = cboStatus.SelectedIndex; Solution.NguoiPhuTrach = TextUtils.ToInt(cboNguoiPhuTrach.EditValue); Solution.TotalCost = TextUtils.ToDecimal(txtTotalCost.EditValue); Solution.Area = TextUtils.ToInt(cboArea.EditValue); Solution.SolutionTechnologyID = TextUtils.ToInt(cboTechnology.EditValue); Solution.StopReason = txtReasonStop.Text; Solution.IsDeleted = false; Solution.UpdatedDate = TextUtils.GetSystemDate(); Solution.UpdatedBy = Global.AppUserName; if (Solution.ID <= 0) { Solution.CreatedDate = TextUtils.GetSystemDate(); Solution.CreatedBy = Global.AppUserName; Solution.ID = (long)pt.Insert(Solution); } else { pt.Update(Solution); } #endregion #region Save File DataRow[] drs = _dtFile.Select("ID = 0 or ID is null"); if (drs.Length > 0) { DocUtils.InitFTPTK(); using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát...", "Đang update tên cho file...")) { for (int i = 0; i < grvFile.RowCount; i++) { long id = TextUtils.ToInt64(grvFile.GetRowCellValue(i, colFileID)); if (id > 0) { SolutionFileModel fileModel = (SolutionFileModel)SolutionFileBO.Instance.FindByPK(id); fileModel.Description = TextUtils.ToString(grvFile.GetRowCellValue(i, colFileDescription)); pt.Update(fileModel); } else { string name = TextUtils.ToString(grvFile.GetRowCellValue(i, colFileName)); string extension = Path.GetExtension(name); decimal length = TextUtils.ToDecimal(grvFile.GetRowCellValue(i, colFileLenght)); string description = TextUtils.ToString(grvFile.GetRowCellValue(i, colFileDescription)); string path = "GiaiPhap/" + Solution.Code + "/" + name; string createdBy = Global.AppUserName; DateTime?createdDate = DateTime.Now; string localPath = TextUtils.ToString(grvFile.GetRowCellValue(i, colFileLocalPath)); if (!DocUtils.CheckExits("GiaiPhap/" + Solution.Code)) { DocUtils.MakeDir("GiaiPhap/" + Solution.Code); } SolutionFileModel fileModel = new SolutionFileModel(); fileModel.CreatedBy = createdBy; fileModel.CreatedDate = createdDate; fileModel.Description = description; fileModel.Extension = extension; fileModel.Length = length; fileModel.Name = name; fileModel.Path = path; fileModel.SolutionID = Solution.ID; fileModel.SolutionFileTypeID = TextUtils.ToInt(grvGroupFile.GetFocusedRowCellValue(colGFID)); pt.Insert(fileModel); DocUtils.UploadFile(localPath, "GiaiPhap/" + Solution.Code); } } } } #endregion #region Save DMVT for (int i = 0; i < grvVT.RowCount; i++) { long id = TextUtils.ToInt64(grvVT.GetRowCellValue(i, colMaID)); SolutionItemModel item = new SolutionItemModel(); if (id > 0) { item = (SolutionItemModel)SolutionItemBO.Instance.FindByPK(id); } item.Code = TextUtils.ToString(grvVT.GetRowCellValue(i, colMaCode)); item.Name = TextUtils.ToString(grvVT.GetRowCellValue(i, colMaName)); item.Hang = TextUtils.ToString(grvVT.GetRowCellValue(i, colMaHang)); item.Qty = TextUtils.ToDecimal(grvVT.GetRowCellValue(i, colMaQty)); item.Price = TextUtils.ToDecimal(grvVT.GetRowCellValue(i, colMaPrice)); item.TotalPrice = TextUtils.ToDecimal(grvVT.GetRowCellValue(i, colMaTotalPrice)); item.QtyError = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaError)); item.QtyKPH = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaKPH)); item.QtyTon = TextUtils.ToInt(grvVT.GetRowCellValue(i, colMaTonKho)); //item.Unit = TextUtils.ToString(grvVT.GetRowCellValue(i, colMau)); //item.Status = TextUtils.ToString(grvVT.GetRowCellValue(i, colMaCode)); //item.Type = TextUtils.ToString(grvVT.GetRowCellValue(i, colMaCode)); item.SolutionID = Solution.ID; if (id > 0) { pt.Update(item); } else { pt.Insert(item); } } #endregion pt.CommitTransaction(); loadFile(); loadDMVT(); _isSaved = true; if (close) { this.DialogResult = DialogResult.OK; } else { MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } } 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 SolutionItemFacade(SolutionItemModel model) : base(model) { }