protected ModulePartFacade(ModulePartModel model) : base(model) { }
void save(bool close) { ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } #region Module if (Module == null) { Module = new ModulesModel(); } Module.Name = txtName.Text.Trim().ToUpper(); Module.Code = txtCode.Text.Trim().ToUpper(); Module.Status = cboStatus.SelectedIndex; Module.ModuleGroupID = leParentCat.EditValue != null?TextUtils.ToInt(leParentCat.EditValue) : 0; Module.Note = txtNote.Text.Trim(); Module.Specifications = txtTSKT.Text.Trim(); Module.FileElectronic = TextUtils.ToInt(chkDienTu.Checked); Module.FileElectric = TextUtils.ToInt(chkDien.Checked); Module.FileMechanics = TextUtils.ToInt(chkCoKhi.Checked); Module.StopStatus = chkStop.Checked ? 1 : 0; Module.IsUpdatedFilm = chkIsUpdatedFilm1.Checked ? 1 : 0; Module.IsPLC = cboPLC.SelectedIndex; Module.IsHMI = cboHMI.SelectedIndex; if (Module.ID == 0 || IsCopy) { Module.ID = (int)pt.Insert(Module); } else { pt.Update(Module); } #endregion #region Phụ kiện đi kèm grvPK.FocusedRowHandle = -1; for (int i = 0; i < grvPK.RowCount; i++) { string code = TextUtils.ToString(grvPK.GetRowCellValue(i, colCodePK)); string name = TextUtils.ToString(grvPK.GetRowCellValue(i, colNamePK)); int qty = TextUtils.ToInt(grvPK.GetRowCellValue(i, colQtyPK)); int id = TextUtils.ToInt(grvPK.GetRowCellValue(i, colIDPK)); ModulePartModel part = new ModulePartModel(); if (id > 0) { part = (ModulePartModel)ModulePartBO.Instance.FindByPK(id); } part.Code = code; part.Name = name; part.ModuleID = Module.ID; part.Qty = qty; if (id > 0) { pt.Update(part); } else { pt.Insert(part); } } #endregion pt.CommitTransaction(); loadPK(); _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(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }