コード例 #1
0
        private void FrmAddCompany_Load(object sender, EventArgs e)
        {
            if (_mode == 0) //add new
            {
                this.Text         = "Them moi doanh nghiep" + ConstantInfo.MESSAGE_TITLE + GlobalInfo.CompanyName;
                btnAdd.Enabled    = true;
                btnUpdate.Enabled = false;
            }

            if (_mode == 1) //update
            {
                btnAdd.Enabled    = false;
                btnUpdate.Enabled = true;

                this.Text = "Cap nhat doanh nghiep" + ConstantInfo.MESSAGE_TITLE + GlobalInfo.CompanyName;
                tblCompany company = CompanyFactory.FindByCode(_companyCode);
                if (company == null)
                {
                    MessageBox.Show("Doanh nghiệp này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                txtCompanyCode.ReadOnly = true;
                txtCompanyCode.Text     = company.CompanyCode;
                txtCompanyName.Text     = company.CompanyName;
                txtDescription.Text     = company.Description;
            }
        }
コード例 #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.grvCompany.SelectedRows.Count > 0)
                {
                    int selectedIndex = grvCompany.SelectedRows[0].Index;

                    // gets the RowID from the first column in the grid
                    var companyCode = grvCompany[0, selectedIndex].Value.ToString();

                    tblCompany company = CompanyFactory.FindByCode(companyCode);
                    if (company == null)
                    {
                        MessageBox.Show("Doanh nghiệp này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    FrmAddCompany frmAddCompany = new FrmAddCompany(companyCode, 1, _userInfo, this);
                    frmAddCompany.MdiParent = this.MdiParent;
                    frmAddCompany.Show();
                }
                else
                {
                    MessageBox.Show("Bạn cần chọn một bản ghi để cập nhật", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                if (GlobalInfo.IsDebug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
コード例 #3
0
        private void txtCompanyCode_Leave(object sender, EventArgs e)
        {
            var companyCode = txtCompanyCode.Text.Trim();
            var company     = CompanyFactory.FindByCode(companyCode);

            txtCompanyName.Text = company != null?Converter.TCVN3ToUnicode(company.CompanyName) : "";
        }
コード例 #4
0
        private void txtCompanyCode_Leave(object sender, EventArgs e)
        {
            var company = CompanyFactory.FindByCode(txtCompanyCode.Text.Trim());

            txtCompanyName.Text = company != null?Converter.TCVN3ToUnicode(company.CompanyName) : "";

            if (company == null)
            {
                txtCompanyCode.Text = string.Empty;
            }
        }
コード例 #5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.grvCompany.SelectedRows.Count > 0)
                {
                    DialogResult result = MessageBox.Show("Bạn thự sự muốn xóa doanh nghiệp đã chọn?", "Cảnh báo!", MessageBoxButtons.YesNo);
                    if (result == DialogResult.Yes)
                    {
                        int selectedIndex = grvCompany.SelectedRows[0].Index;

                        // gets the RowID from the first column in the grid
                        var companyCode = grvCompany[0, selectedIndex].Value.ToString();

                        tblCompany company = CompanyFactory.FindByCode(companyCode);
                        if (company == null)
                        {
                            MessageBox.Show("Loại hình này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }

                        if (CompanyFactory.Delete(companyCode) > 0)
                        {
                            search();
                            MessageBox.Show("Xóa doanh nghiệp thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            search();
                            MessageBox.Show("Xóa doanh nghiệp không thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Bạn cần chọn một bản ghi để xóa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                if (GlobalInfo.IsDebug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }
コード例 #6
0
        private bool validate()
        {
            bool valid = true;

            if (_mode == 0)//add new
            {
                if (String.IsNullOrEmpty(txtCompanyCode.Text.Trim()))
                {
                    valid = false;
                    MessageBox.Show("Mã doanh nghiệp không được để trống", "Dữ liệu không hợp lệ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtCompanyCode.Focus();
                }
                else if (null != CompanyFactory.FindByCode(txtCompanyCode.Text.Trim()))
                {
                    valid = false;
                    MessageBox.Show("Mã doanh nghiệp này đã tồn tại, hãy thử với mã khác", "Dữ liệu không hợp lệ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    txtCompanyCode.Focus();
                }

                if (String.IsNullOrEmpty(txtCompanyName.Text.Trim()))
                {
                    valid = false;
                    MessageBox.Show("Tên doanh nghiệp không được để trống", "Dữ liệu không hợp lệ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    txtCompanyName.Focus();
                }
            }
            if (_mode == 1) //update
            {
                tblCompany company = CompanyFactory.FindByCode(_companyCode);
                if (company == null)
                {
                    valid = false;
                    MessageBox.Show("Doanh nghiệp này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else if (String.IsNullOrEmpty(txtCompanyName.Text.Trim()))
                {
                    valid = false;
                    MessageBox.Show("Tên doanh nghiệp không được để trống", "Dữ liệu không hợp lệ", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                    txtCompanyName.Focus();
                }
            }
            return(valid);
        }
コード例 #7
0
        private void grvCompany_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (_userInfo.UserPermission.Contains(ConstantInfo.PERMISSON_QUAN_LY_THONG_TIN_DOANH_NGHIEP) == false)
            {
                return;
            }

            try
            {
                if (this.grvCompany.SelectedRows.Count > 0)
                {
                    int selectedIndex = grvCompany.SelectedRows[0].Index;

                    // gets the RowID from the first column in the grid
                    var companyCode = grvCompany[0, selectedIndex].Value.ToString();

                    tblCompany company = CompanyFactory.FindByCode(companyCode);
                    if (company == null)
                    {
                        MessageBox.Show("Doanh nghiệp này không còn tồn tại trong Cơ Sở Dữ Liệu. Bạn hãy kiểm tra lại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }


                    FrmAddCompany frmAddCompany = new FrmAddCompany(companyCode, 1, _userInfo, this);
                    frmAddCompany.MdiParent = this.MdiParent;
                    frmAddCompany.Show();
                }
                else
                {
                    MessageBox.Show("Bạn cần chọn một bản ghi để cập nhật", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                if (GlobalInfo.IsDebug)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
        }