private void PerformActionInsert()
        {
            DmucDiachinh.Insert(txtSurveyCode.Text, txtSurveyName.Text,
                                cboDiachinhcaptren.Enabled && cboDiachinhcaptren.SelectedIndex > 0? Utility.sDbnull(cboDiachinhcaptren.SelectedValue, ""):"",
                                Utility.Int16Dbnull(txtIntOrder.Text, ""),
                                Convert.ToByte(cboSurveyType.SelectedIndex), txtsDesc.Text);

            DataRow dr = globalVariables.gv_dtDmucDiachinh.NewRow();

            // dr[DmucDiachinh.Columns.MaDiachinh] = Utility.Int16Dbnull(_Query.GetMax(LDisease.Columns.DiseaseId), -1);
            dr[DmucDiachinh.Columns.MaDiachinh]   = txtSurveyCode.Text;
            dr[DmucDiachinh.Columns.TenDiachinh]  = Utility.sDbnull(txtSurveyName.Text, "");
            dr[DmucDiachinh.Columns.MaCha]        = cboDiachinhcaptren.Enabled && cboDiachinhcaptren.SelectedIndex > 0 ? Utility.sDbnull(cboDiachinhcaptren.SelectedValue, "") : "";
            dr[DmucDiachinh.Columns.MotaThem]     = Utility.sDbnull(txtsDesc.Text, "");
            dr[DmucDiachinh.Columns.LoaiDiachinh] = Convert.ToByte(cboSurveyType.SelectedIndex);
            dr["ten_loaidiachinh"]           = Utility.getTenloaiDiachinh(cboSurveyType.SelectedIndex);
            dr["ten_diachinh_captren"]       = Utility.sDbnull(cboDiachinhcaptren.Text, "");
            dr[DmucDiachinh.Columns.SttHthi] = Utility.Int16Dbnull(txtIntOrder.Text, "0");
            globalVariables.gv_dtDmucDiachinh.Rows.Add(dr);
            if (grdList != null)
            {
                Utility.GotoNewRowJanus(grdList, DmucDiachinh.Columns.MaDiachinh, txtSurveyCode.Text);
            }
            this.Close();
        }
        private void GetData()
        {
            DmucDiachinh objDiachinh = DmucDiachinh.FetchByID(Utility.sDbnull(txtSurveyCode.Text, ""));

            if (objDiachinh != null)
            {
                txtsDesc.Text               = objDiachinh.MotaThem;
                txtSurveyCode.Text          = objDiachinh.MaDiachinh;
                txtSurveyName.Text          = objDiachinh.TenDiachinh;
                cboDiachinhcaptren.Enabled  = lblCaptren.Enabled = objDiachinh.LoaiDiachinh <= 1;
                txtIntOrder.Value           = Utility.DecimaltoDbnull(objDiachinh.SttHthi, 0);
                cboSurveyType.SelectedIndex = (int)objDiachinh.LoaiDiachinh.Value;
                cboDiachinhcaptren.Enabled  = lblCaptren.Enabled = cboSurveyType.SelectedIndex > 0;
                if (cboDiachinhcaptren.Enabled)
                {
                    cboDiachinhcaptren.SelectedIndex = Utility.GetSelectedIndex(cboDiachinhcaptren,
                                                                                Utility.sDbnull(objDiachinh.MaCha, ""));
                }
            }
            txtSurveyCode.Enabled = false;
        }
Esempio n. 3
0
        private void TudongthemDiachinh_test(string value)
        {
            //Tạm thời khoa lại tìm giải pháp khác trực quan hơn
            return;
            bool success = false;
            bool added = false;
            string[] arrvalues = value.Split(',');
            if (arrvalues.Length != 3) return;
            string TenTP = arrvalues[2];
            string TenQH = arrvalues[1];
            string TenXP = arrvalues[0];
            string CodeTP = "";
            string CodeQH = "";
            string CodeXP = "";

            string SurveyCodeTP = Utility.GetYYMMDDHHMMSS(globalVariables.SysDate);
            string SurveyCodeQH = SurveyCodeTP + "1";
            string SurveyCodeXP = SurveyCodeQH + "1";
            DmucDiachinh _TP = null;
            var _newTP = new DmucDiachinh();

            DmucDiachinh _QH = null;
            var _newQH = new DmucDiachinh();

            DmucDiachinh _XP = null;
            var _newXP = new DmucDiachinh();

            string ShortCutXP = "kx";
            string ShortCutTP = "kx";
            string ShortCutQH = "kx";
            try
            {
                _TP =
                    new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.TenDiachinhColumn).IsEqualTo(TenTP).ExecuteSingle
                        <DmucDiachinh>();

                if (_TP == null)
                {
                    _newTP.MaDiachinh = SurveyCodeTP;
                    _newTP.TenDiachinh = TenTP;
                    _newTP.SttHthi = 1;
                    _newTP.LoaiDiachinh = 0;
                    _newTP.MotaThem = getshortcut(Utility.Bodau(BoTp(0, TenTP)));
                    ShortCutTP = _newTP.MotaThem;
                }
                else
                {
                    CodeTP = _TP.MaDiachinh;
                    ShortCutTP = _TP.MotaThem;
                }
                SqlQuery sqlQueryQH = new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.TenDiachinhColumn).IsEqualTo(TenQH);
                if (_TP != null)
                {
                    sqlQueryQH.And(DmucDiachinh.MaChaColumn).IsEqualTo(_TP.MaDiachinh);
                    _QH = sqlQueryQH.ExecuteSingle<DmucDiachinh>();
                }
                else
                    _QH = null;

                if (_QH == null)
                {
                    _newQH.MaDiachinh = SurveyCodeQH;
                    _newQH.TenDiachinh = TenQH;
                    _newQH.SttHthi = 1;
                    _newQH.LoaiDiachinh = 1;
                    _newQH.MotaThem = getshortcut(Utility.Bodau(BoTp(1, TenQH)));
                    ShortCutQH = _newQH.MotaThem;
                }
                else
                {
                    CodeQH = _QH.MaDiachinh;
                    ShortCutQH = _QH.MotaThem;
                }
                SqlQuery sqlQueryXP = new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.TenDiachinhColumn).IsEqualTo(TenXP);
                if (_QH != null)
                {
                    sqlQueryXP.And(DmucDiachinh.MaChaColumn).IsEqualTo(_QH.MaDiachinh);
                    _XP = sqlQueryXP.ExecuteSingle<DmucDiachinh>();
                }
                else
                    _XP = null;

                if (_XP == null)
                {
                    _newXP.MaDiachinh = SurveyCodeXP;
                    _newXP.TenDiachinh = TenXP;
                    _newXP.SttHthi = 1;
                    _newXP.LoaiDiachinh = 2;
                    _newXP.MotaThem = getshortcut(Utility.Bodau(BoTp(2, TenXP)));
                    ShortCutXP = _newXP.MotaThem;
                }
                else
                {
                    CodeXP = _XP.MaDiachinh;
                    ShortCutXP = _XP.MotaThem;
                }

                using (var scope = new TransactionScope())
                {
                    using (var sh = new SharedDbConnectionScope())
                    {
                        int maxCode = 0;
                        QueryCommand cmd = DmucDiachinh.CreateQuery().BuildCommand();
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandSql = "select MAX(ma_diachinh) from dmuc_diachinh where ISNUMERIC(ma_diachinh)=1";
                        DataTable temdt = DataService.GetDataSet(cmd).Tables[0];
                        maxCode = Utility.Int32Dbnull(temdt.Rows[0][0], 0);
                        if (_TP == null)
                        {
                            added = true;
                            _newTP.MaDiachinh = (maxCode + 1).ToString();
                            _newTP.Save();
                            CodeTP = _newTP.MaDiachinh;
                        }
                        if (_QH == null)
                        {
                            added = true;
                            _newQH.MaDiachinh = (maxCode + 2).ToString();
                            _newQH.MaCha = CodeTP;
                            _newQH.Save();
                            CodeQH = _newQH.MaDiachinh;
                        }
                        if (_XP == null)
                        {
                            added = true;
                            _newXP.MaDiachinh = (maxCode + 3).ToString();
                            _newXP.MaCha = CodeQH;
                            _newXP.Save();
                        }
                    }
                    scope.Complete();
                    success = true;
                }
            }
            catch
            {
            }
            if (success && added) //Thêm vào Datatable để không có thể sử dụng luôn
            {
                DataRow drShortcut = m_DC.NewRow();
                drShortcut["ShortCutXP"] = ShortCutXP;
                drShortcut["ShortCutQH"] = ShortCutQH;
                drShortcut["ShortCutTP"] = ShortCutTP;
                drShortcut["Value"] = value;
                m_DC.Rows.Add(drShortcut);
            }
        }
Esempio n. 4
0
        public void Insert(string MaDiachinh,string TenDiachinh,string MaCha,short? SttHthi,byte? LoaiDiachinh,string MotaThem)
        {
            DmucDiachinh item = new DmucDiachinh();

            item.MaDiachinh = MaDiachinh;

            item.TenDiachinh = TenDiachinh;

            item.MaCha = MaCha;

            item.SttHthi = SttHthi;

            item.LoaiDiachinh = LoaiDiachinh;

            item.MotaThem = MotaThem;

            item.Save(UserName);
        }
Esempio n. 5
0
        public void Update(string MaDiachinh,string TenDiachinh,string MaCha,short? SttHthi,byte? LoaiDiachinh,string MotaThem)
        {
            DmucDiachinh item = new DmucDiachinh();
            item.MarkOld();
            item.IsLoaded = true;

            item.MaDiachinh = MaDiachinh;

            item.TenDiachinh = TenDiachinh;

            item.MaCha = MaCha;

            item.SttHthi = SttHthi;

            item.LoaiDiachinh = LoaiDiachinh;

            item.MotaThem = MotaThem;

            item.Save(UserName);
        }
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                SqlQuery sqlTinhThanh =
              new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.Columns.MaDiachinh).IsEqualTo(
                  Utility.sDbnull(txtMaTinhThanh.Text.Trim(), ""));
                if (sqlTinhThanh.GetRecordCount() <= 0 && txtMaTinhThanh.TextLength > 0 && txtTenTinhthanh.TextLength > 0)//Thêm mới
                {
                    if (!IsValidDataTP()) return;
                    var objDmucDiachinhT = new DmucDiachinh();
                    objDmucDiachinhT.MaDiachinh = Utility.sDbnull(txtMaTinhThanh.Text.Trim(), "");
                    objDmucDiachinhT.TenDiachinh = Utility.sDbnull(txtTenTinhthanh.Text.Trim(), "");
                    objDmucDiachinhT.LoaiDiachinh = 0;
                    objDmucDiachinhT.MaCha = "";
                    objDmucDiachinhT.SttHthi = 0;
                    objDmucDiachinhT.MotaThem = Utility.sDbnull(txtMoTaTinhThanh.Text.Trim(), "");
                    objDmucDiachinhT.IsNew = true;
                    objDmucDiachinhT.Save();
                    Utility.SetMsg(lblMsgTP, "Thêm thành công TP", true);
                }
                else if (sqlTinhThanh.GetRecordCount() > 0)
                {
                    if (!IsValidDataTP()) return;
                    SqlQuery tinh = new Update(DmucDiachinh.Schema).Set(DmucDiachinh.Columns.TenDiachinh).EqualTo(Utility.sDbnull(txtTenTinhthanh.Text.Trim(), "")).Set(
                              DmucDiachinh.Columns.MotaThem).
                          EqualTo(Utility.sDbnull(txtMoTaTinhThanh.Text.Trim(), "")).Where(DmucDiachinh.Columns.MaDiachinh).
                          IsEqualTo(Utility.sDbnull(txtMaTinhThanh.Text.Trim(), ""));
                    tinh.Execute();
                    Utility.SetMsg(lblMsgTP, "Cập nhật thành công TP", true);
                }

                SqlQuery sqlQuanHuyen =
                    new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.Columns.MaDiachinh).IsEqualTo(
                        Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), ""));
                if (sqlQuanHuyen.GetRecordCount() <= 0 && txtMaQuanHuyen.TextLength > 0 && txtTenQuanHuyen.TextLength > 0)
                {
                    if (!IsValidDataQH()) return;
                    var objDmucDiachinhH = new DmucDiachinh();
                    objDmucDiachinhH.MaDiachinh = Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhH.TenDiachinh = Utility.sDbnull(txtTenQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhH.LoaiDiachinh = 1;
                    objDmucDiachinhH.MaCha = Utility.sDbnull(txtMaTinhThanh.Text.Trim(), "");
                    objDmucDiachinhH.SttHthi = 0;
                    objDmucDiachinhH.MotaThem = Utility.sDbnull(txtMoTaQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhH.IsNew = true;
                    objDmucDiachinhH.Save();
                    Utility.SetMsg(lblMsgQH, "Thêm thành công Quận/Huyện", true);
                }
                else if (sqlQuanHuyen.GetRecordCount() > 0)
                {
                    if (!IsValidDataQH()) return;
                    SqlQuery quan = new Update(DmucDiachinh.Schema).Set(DmucDiachinh.Columns.TenDiachinh).EqualTo(Utility.sDbnull(txtTenQuanHuyen.Text.Trim(), "")).Set(
                           DmucDiachinh.Columns.MotaThem).
                       EqualTo(Utility.sDbnull(txtMoTaQuanHuyen.Text.Trim(), "")).Where(DmucDiachinh.Columns.MaDiachinh).
                       IsEqualTo(Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), ""));
                    quan.Execute();
                    Utility.SetMsg(lblMsgQH, "Cập nhật thành công Quận/Huyện", true);
                }

                SqlQuery sqlXaPhuong =
                    new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.Columns.MaDiachinh).IsEqualTo(
                        Utility.sDbnull(txtMaXaPhuong.Text.Trim(), ""));
                if (sqlXaPhuong.GetRecordCount() <= 0 && txtMaXaPhuong.TextLength > 0 && txtTenXaPhuong.TextLength > 0)
                {
                    if (!IsValidDataXP()) return;
                    var objDmucDiachinhX = new DmucDiachinh();
                    objDmucDiachinhX.MaDiachinh = Utility.sDbnull(txtMaXaPhuong.Text.Trim(), "");
                    objDmucDiachinhX.TenDiachinh = Utility.sDbnull(txtTenXaPhuong.Text.Trim(), "");
                    objDmucDiachinhX.LoaiDiachinh = 2;
                    objDmucDiachinhX.MaCha = Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhX.SttHthi = 0;
                    objDmucDiachinhX.MotaThem = Utility.sDbnull(txtMoTaXaPhuong.Text.Trim(), "");
                    objDmucDiachinhX.IsNew = true;
                    objDmucDiachinhX.Save();
                    Utility.SetMsg(lblMsgXP, "Thêm thành công Xã/Phường", true);
                }
                else if (sqlXaPhuong.GetRecordCount() > 0)
                {
                    if (!IsValidDataXP()) return;
                    SqlQuery xa = new Update(DmucDiachinh.Schema).Set(DmucDiachinh.Columns.TenDiachinh).EqualTo(
                          Utility.sDbnull(txtTenXaPhuong.Text.Trim(), "")).Set(
                              DmucDiachinh.Columns.MotaThem).
                          EqualTo(Utility.sDbnull(txtMoTaXaPhuong.Text.Trim(), "")).Where(DmucDiachinh.Columns.MaDiachinh).
                          IsEqualTo(Utility.sDbnull(txtMaXaPhuong.Text.Trim(), ""));
                    xa.Execute();
                    Utility.SetMsg(lblMsgXP, "Cập nhật thành công Xã/Phường", true);
                }
                m_blnHasChanged = true;

                LoadData();
            }
            catch (Exception ex)
            {

                Utility.CatchException(ex);
            }
        }
Esempio n. 7
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                SqlQuery sqlTinhThanh =
                    new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.Columns.MaDiachinh).IsEqualTo(
                        Utility.sDbnull(txtMaTinhThanh.Text.Trim(), ""));
                if (sqlTinhThanh.GetRecordCount() <= 0 && txtMaTinhThanh.TextLength > 0 && txtTenTinhthanh.TextLength > 0)//Thêm mới
                {
                    if (!IsValidDataTP())
                    {
                        return;
                    }
                    var objDmucDiachinhT = new DmucDiachinh();
                    objDmucDiachinhT.MaDiachinh   = Utility.sDbnull(txtMaTinhThanh.Text.Trim(), "");
                    objDmucDiachinhT.TenDiachinh  = Utility.sDbnull(txtTenTinhthanh.Text.Trim(), "");
                    objDmucDiachinhT.LoaiDiachinh = 0;
                    objDmucDiachinhT.MaCha        = "";
                    objDmucDiachinhT.SttHthi      = 0;
                    objDmucDiachinhT.MotaThem     = Utility.sDbnull(txtMoTaTinhThanh.Text.Trim(), "");
                    objDmucDiachinhT.IsNew        = true;
                    objDmucDiachinhT.Save();
                    Utility.SetMsg(lblMsgTP, "Thêm thành công TP", true);
                }
                else if (sqlTinhThanh.GetRecordCount() > 0)
                {
                    if (!IsValidDataTP())
                    {
                        return;
                    }
                    SqlQuery tinh = new Update(DmucDiachinh.Schema).Set(DmucDiachinh.Columns.TenDiachinh).EqualTo(Utility.sDbnull(txtTenTinhthanh.Text.Trim(), "")).Set(
                        DmucDiachinh.Columns.MotaThem).
                                    EqualTo(Utility.sDbnull(txtMoTaTinhThanh.Text.Trim(), "")).Where(DmucDiachinh.Columns.MaDiachinh).
                                    IsEqualTo(Utility.sDbnull(txtMaTinhThanh.Text.Trim(), ""));
                    tinh.Execute();
                    Utility.SetMsg(lblMsgTP, "Cập nhật thành công TP", true);
                }

                SqlQuery sqlQuanHuyen =
                    new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.Columns.MaDiachinh).IsEqualTo(
                        Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), ""));
                if (sqlQuanHuyen.GetRecordCount() <= 0 && txtMaQuanHuyen.TextLength > 0 && txtTenQuanHuyen.TextLength > 0)
                {
                    if (!IsValidDataQH())
                    {
                        return;
                    }
                    var objDmucDiachinhH = new DmucDiachinh();
                    objDmucDiachinhH.MaDiachinh   = Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhH.TenDiachinh  = Utility.sDbnull(txtTenQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhH.LoaiDiachinh = 1;
                    objDmucDiachinhH.MaCha        = Utility.sDbnull(txtMaTinhThanh.Text.Trim(), "");
                    objDmucDiachinhH.SttHthi      = 0;
                    objDmucDiachinhH.MotaThem     = Utility.sDbnull(txtMoTaQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhH.IsNew        = true;
                    objDmucDiachinhH.Save();
                    Utility.SetMsg(lblMsgQH, "Thêm thành công Quận/Huyện", true);
                }
                else if (sqlQuanHuyen.GetRecordCount() > 0)
                {
                    if (!IsValidDataQH())
                    {
                        return;
                    }
                    SqlQuery quan = new Update(DmucDiachinh.Schema).Set(DmucDiachinh.Columns.TenDiachinh).EqualTo(Utility.sDbnull(txtTenQuanHuyen.Text.Trim(), "")).Set(
                        DmucDiachinh.Columns.MotaThem).
                                    EqualTo(Utility.sDbnull(txtMoTaQuanHuyen.Text.Trim(), "")).Where(DmucDiachinh.Columns.MaDiachinh).
                                    IsEqualTo(Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), ""));
                    quan.Execute();
                    Utility.SetMsg(lblMsgQH, "Cập nhật thành công Quận/Huyện", true);
                }


                SqlQuery sqlXaPhuong =
                    new Select().From(DmucDiachinh.Schema).Where(DmucDiachinh.Columns.MaDiachinh).IsEqualTo(
                        Utility.sDbnull(txtMaXaPhuong.Text.Trim(), ""));
                if (sqlXaPhuong.GetRecordCount() <= 0 && txtMaXaPhuong.TextLength > 0 && txtTenXaPhuong.TextLength > 0)
                {
                    if (!IsValidDataXP())
                    {
                        return;
                    }
                    var objDmucDiachinhX = new DmucDiachinh();
                    objDmucDiachinhX.MaDiachinh   = Utility.sDbnull(txtMaXaPhuong.Text.Trim(), "");
                    objDmucDiachinhX.TenDiachinh  = Utility.sDbnull(txtTenXaPhuong.Text.Trim(), "");
                    objDmucDiachinhX.LoaiDiachinh = 2;
                    objDmucDiachinhX.MaCha        = Utility.sDbnull(txtMaQuanHuyen.Text.Trim(), "");
                    objDmucDiachinhX.SttHthi      = 0;
                    objDmucDiachinhX.MotaThem     = Utility.sDbnull(txtMoTaXaPhuong.Text.Trim(), "");
                    objDmucDiachinhX.IsNew        = true;
                    objDmucDiachinhX.Save();
                    Utility.SetMsg(lblMsgXP, "Thêm thành công Xã/Phường", true);
                }
                else if (sqlXaPhuong.GetRecordCount() > 0)
                {
                    if (!IsValidDataXP())
                    {
                        return;
                    }
                    SqlQuery xa = new Update(DmucDiachinh.Schema).Set(DmucDiachinh.Columns.TenDiachinh).EqualTo(
                        Utility.sDbnull(txtTenXaPhuong.Text.Trim(), "")).Set(
                        DmucDiachinh.Columns.MotaThem).
                                  EqualTo(Utility.sDbnull(txtMoTaXaPhuong.Text.Trim(), "")).Where(DmucDiachinh.Columns.MaDiachinh).
                                  IsEqualTo(Utility.sDbnull(txtMaXaPhuong.Text.Trim(), ""));
                    xa.Execute();
                    Utility.SetMsg(lblMsgXP, "Cập nhật thành công Xã/Phường", true);
                }
                m_blnHasChanged = true;

                LoadData();
            }
            catch (Exception ex)
            {
                Utility.CatchException(ex);
            }
        }