Beispiel #1
0
        void save(bool close)
        {
            ProcessTransaction pt = new ProcessTransaction();

            pt.OpenConnection();
            pt.BeginTransaction();

            try
            {
                if (!ValidateForm())
                {
                    return;
                }

                if (CoCau.ID == 0)
                {
                    CoCau = new CoCauMauModel();
                }

                CoCau.Name         = txtName.Text.Trim().ToUpper();
                CoCau.Code         = txtCode.Text.Trim().ToUpper();
                CoCau.CoCauGroupID = TextUtils.ToInt(cboGroup.EditValue);
                //CoCau.Note = txtDescription.Text.Trim();
                CoCau.Description    = txtDescription.Text.Trim();
                CoCau.Specifications = txtTSKT.Text.Trim();
                CoCau.ImagePath      = pictureBox1.ImageLocation;

                if (CoCau.ID == 0)
                {
                    CoCau.ID = (int)pt.Insert(CoCau);
                }
                else
                {
                    pt.Update(CoCau);
                }

                pt.CommitTransaction();

                _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();
            }
        }
        private void btnEdit_Click(object sender, EventArgs e)
        {
            int id = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colID));

            if (id == 0)
            {
                return;
            }
            CoCauMauModel model = (CoCauMauModel)CoCauMauBO.Instance.FindByPK(id);
            int           catId = TextUtils.ToInt(grvData.GetFocusedRowCellValue(colGroup));

            _rownIndex = grvData.FocusedRowHandle;

            frmCoCauMau frm = new frmCoCauMau();

            frm.GroupID         = catId;
            frm.CoCau           = model;
            frm.LoadDataChange += main_LoadDataChange;
            frm.Show();
        }
Beispiel #3
0
 protected CoCauMauFacade(CoCauMauModel model) : base(model)
 {
 }
Beispiel #4
0
        private void btnCreateCoCau_Click(object sender, EventArgs e)
        {
            if (grvCoCau.Rows.Count == 0)
            {
                MessageBox.Show("Không tìm thấy cơ cấu để tạo!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            string saveImagePath = TextUtils.GetConfigValue("CoCauPath");
            int    count         = 0;

            foreach (DataGridViewRow row in grvCoCau.Rows)
            {
                string    code = TextUtils.ToString(row.Cells["colMaCoCau"].Value);
                DataTable dt   = TextUtils.Select("select top 1 Code from CoCauMau with(nolock) where Code = '" + code + "'");
                if (dt.Rows.Count > 0)
                {
                    continue;
                }

                string name      = TextUtils.ToString(row.Cells["colTenCoCau"].Value);
                string localPath = TextUtils.ToString(row.Cells["colImagePath"].Value);
                int    isSaved   = TextUtils.ToInt(row.Cells["colIsSaved"].Value);
                if (code == "")
                {
                    continue;
                }
                if (isSaved == 1)
                {
                    continue;
                }

                CoCauMauModel CoCau = new CoCauMauModel();
                CoCau.Name           = name.ToUpper();
                CoCau.Code           = code.ToUpper();
                CoCau.CoCauGroupID   = GroupID;
                CoCau.Note           = "";
                CoCau.Specifications = "";

                try
                {
                    File.Copy(localPath, saveImagePath + "//" + Path.GetFileName(localPath), true);
                    CoCau.ImagePath = saveImagePath + "//" + Path.GetFileName(localPath);
                    CoCau.ID        = (int)CoCauMauBO.Instance.Insert(CoCau);
                    count++;

                    frmCoCauMau frm = new frmCoCauMau();
                    frm.CoCau   = CoCau;
                    frm.GroupID = GroupID;
                    frm.ShowDialog();

                    _dtCoCau.Rows[row.Index]["IsSaved"] = 1;
                }
                catch
                {
                }
            }

            if (count > 0)
            {
                MessageBox.Show("Tạo cơ cấu thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);

                if (this.LoadDataChange != null)
                {
                    this.LoadDataChange(null, null);
                }
            }
            else
            {
                MessageBox.Show("Các cơ cấu này đã được tạo!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }