Example #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();
            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                WorkDiary.EndDateDK   = dtpEndDateDK.Value;
                WorkDiary.GhiChu      = txtNote.Text.Trim();
                WorkDiary.ModuleCode  = txtModuleCode.Text.Trim();
                WorkDiary.Name        = txtName.Text.Trim();
                WorkDiary.ProjectCode = txtProjectCode.Text.Trim();
                WorkDiary.StartDate   = dtpStartDate.Value;
                WorkDiary.Status      = cboStatus.SelectedIndex;
                //WorkDiary.ThoiGianDuKien = TextUtils.ToInt(txtTime.EditValue);
                WorkDiary.UserID = TextUtils.ToInt(cboUser.EditValue);

                if (cboStatus.SelectedIndex == 1)
                {
                    WorkDiary.EndDate = DateTime.Now;
                }
                else
                {
                    WorkDiary.EndDate = null;
                }

                if (WorkDiary.ID == 0)
                {
                    WorkDiary.ID = (int)pt.Insert(WorkDiary);

                    TheoDoiHistoryModel history = new TheoDoiHistoryModel();
                    history.EndDateDK = WorkDiary.EndDateDK;
                    history.TheoDoiID = WorkDiary.ID;
                    history.Reason    = "Thêm mới";
                    pt.Insert(history);
                }
                else
                {
                    pt.Update(WorkDiary);

                    if (_oldEndDateDK.Date != dtpEndDateDK.Value)
                    {
                        TheoDoiHistoryModel history = new TheoDoiHistoryModel();
                        history.EndDateDK = WorkDiary.EndDateDK;
                        history.TheoDoiID = WorkDiary.ID;
                        history.Reason    = txtReason.Text.Trim();
                        pt.Insert(history);
                    }
                }

                pt.CommitTransaction();
                loadHistory();
                _isSaved = true;
                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();
            }

            if (_isSaved && this.LoadDataChange != null)
            {
                this.LoadDataChange(null, null);
            }
        }
Example #2
0
 protected TheoDoiHistoryFacade(TheoDoiHistoryModel model) : base(model)
 {
 }