/// <summary>
 /// hàm thưucj hiện việc cập nhập lại thông tin thành công
 /// </summary>
 private void UpdateData()
 {
     objBed = createBed();
     objBed.MarkOld();
     objBed.IsNew = false;
     objBed.Save();
     if (MyGetData != null)
     {
         MyGetData();
         Utility.GonewRowJanus(grdList, NoitruDmucGiuongbenh.Columns.IdGiuong, Utility.sDbnull(txtID.Text));
     }
     if (chkApDungGia.Checked)
     {
         new Delete().From(NoitruQheDoituongBuonggiuong.Schema)
         .Where(NoitruQheDoituongBuonggiuong.Columns.IdGiuong).IsEqualTo(Utility.Int32Dbnull(txtID.Text)).Execute();
         foreach (Janus.Windows.GridEX.GridEXRow gridExRow in grdQuanheGiuong.GetCheckedRows())
         {
             NoitruQheDoituongBuonggiuong objectType = new NoitruQheDoituongBuonggiuong();
             objectType.DonGia = (objectType.MaDoituongKcb == "DV" ?
                                  Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaDichvu)
                              : (objectType.MaDoituongKcb == "BHYT" ?
                                 Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaBhyt) :
                                 Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaKhac))
                                  )
             ;
             objectType.PhuthuDungtuyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuDungtuyen].Value, 0);
             objectType.PhuthuTraituyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuTraituyen].Value, 0);
             objectType.MaDoituongKcb   = Utility.sDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.MaDoituongKcb].Value);
             SqlQuery sqlQuery =
                 new Select().From(DmucDoituongkcb.Schema).Where(DmucDoituongkcb.Columns.MaDoituongKcb).IsEqualTo(
                     objectType.MaDoituongKcb);
             DmucDoituongkcb objectType1 = sqlQuery.ExecuteSingle <DmucDoituongkcb>();
             if (objectType1 != null)
             {
                 objectType.IdLoaidoituongKcb = Utility.Int32Dbnull(objectType1.IdLoaidoituongKcb);
             }
             objectType.KieuThue = "GIUONG";
             // DmucDoituongkcb objectType1=DmucDoituongkcb.FetchByID()
             objectType.IdBuong  = Utility.Int16Dbnull(txtBuong.MyID);
             objectType.IdGiuong = Utility.Int16Dbnull(objBed.IdGiuong, -1);
             objectType.IsNew    = true;
             objectType.Save();
         }
     }
     Utility.SetMsg(lblMsg, "Bạn thực hiện sửa thông tin  thành công", true);
     if (chkthemmoilientuc.Checked)
     {
         ClearControl();
     }
     else
     {
         this.Close();
     }
 }
Example #2
0
        void grdBed_UpdatingCell(object sender, UpdatingCellEventArgs e)
        {
            try
            {
                if (!Utility.isValidGrid(grdBed))
                {
                    return;
                }
                if (e.InitialValue.ToString() != e.Value.ToString())
                {
                    NoitruDmucGiuongbenh _obj = NoitruDmucGiuongbenh.FetchByID(Utility.Int32Dbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.IdGiuong)));
                    _obj.MaGiuong        = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.MaGiuong.ToUpper() ? e.Value.ToString() : Utility.sDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.MaGiuong), "");
                    _obj.TenGiuong       = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.TenGiuong.ToUpper() ? e.Value.ToString() : Utility.sDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.TenGiuong), "");
                    _obj.GiaDichvu       = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.GiaDichvu.ToUpper() ? (decimal)e.Value : Utility.DecimaltoDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.GiaDichvu), 0);
                    _obj.GiaBhyt         = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.GiaBhyt.ToUpper() ? (decimal)e.Value : Utility.DecimaltoDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.GiaBhyt), 0);
                    _obj.GiaKhac         = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.GiaKhac.ToUpper() ? (decimal)e.Value : Utility.DecimaltoDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.GiaKhac), 0);
                    _obj.PhuthuDungtuyen = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.PhuthuDungtuyen.ToUpper() ? (decimal)e.Value : Utility.DecimaltoDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.PhuthuDungtuyen), 0);
                    _obj.PhuthuTraituyen = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.PhuthuTraituyen.ToUpper() ? (decimal)e.Value : Utility.DecimaltoDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.PhuthuTraituyen), 0);

                    _obj.SonguoiToida  = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.SonguoiToida.ToUpper() ? (byte)e.Value : Utility.Int16Dbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.SonguoiToida), 1);
                    _obj.MotaThem      = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.MotaThem.ToUpper() ? e.Value.ToString() : Utility.sDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.MotaThem), "");
                    _obj.TrangThai     = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.TrangThai.ToUpper() ? (byte)e.Value : Utility.ByteDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.TrangThai), 1);
                    _obj.TthaiTunguyen = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.TthaiTunguyen.ToUpper() ? (byte)e.Value : Utility.ByteDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.TthaiTunguyen), 0);
                    _obj.DangSudung    = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.DangSudung.ToUpper() ? (byte)e.Value : Utility.ByteDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.DangSudung), 1);
                    _obj.SttHthi       = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.SttHthi.ToUpper() ? (Int16)e.Value : Utility.Int16Dbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.SttHthi), 1);
                    _obj.TenBhyt       = e.Column.DataMember.ToUpper() == NoitruDmucGiuongbenh.Columns.TenBhyt.ToUpper() ? e.Value.ToString() : Utility.sDbnull(Utility.GetValueFromGridColumn(grdBed, NoitruDmucGiuongbenh.Columns.TenBhyt), "");
                    _obj.IsNew         = false;
                    _obj.MarkOld();
                    SqlQuery sqlQuery = new Select().From(NoitruDmucGiuongbenh.Schema)
                                        .Where(NoitruDmucGiuongbenh.Columns.IdBuong).IsEqualTo(_obj.IdBuong)
                                        .And(NoitruDmucGiuongbenh.Columns.MaGiuong).IsEqualTo(_obj.MaGiuong)
                                        .And(NoitruDmucGiuongbenh.Columns.IdGiuong).IsNotEqualTo(_obj.IdGiuong);
                    if (sqlQuery.GetRecordCount() > 0)
                    {
                        Utility.ShowMsg("Mã giường đã tồn tại. Đề nghị bạn nhập mã khác", "Thông báo", MessageBoxIcon.Warning);
                        return;
                    }
                    _obj.Save();
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void Insert(string MaGiuong,string TenGiuong,short IdKhoanoitru,short IdBuong,decimal DonGia,short SonguoiToida,string MotaThem,string MaDonvitinh,byte? TrangThai,byte? TthaiTunguyen,byte? DangSudung,short? SttHthi,string TenBhyt)
        {
            NoitruDmucGiuongbenh item = new NoitruDmucGiuongbenh();

            item.MaGiuong = MaGiuong;

            item.TenGiuong = TenGiuong;

            item.IdKhoanoitru = IdKhoanoitru;

            item.IdBuong = IdBuong;

            item.DonGia = DonGia;

            item.SonguoiToida = SonguoiToida;

            item.MotaThem = MotaThem;

            item.MaDonvitinh = MaDonvitinh;

            item.TrangThai = TrangThai;

            item.TthaiTunguyen = TthaiTunguyen;

            item.DangSudung = DangSudung;

            item.SttHthi = SttHthi;

            item.TenBhyt = TenBhyt;

            item.Save(UserName);
        }
        public void Insert(string MaGiuong,string TenGiuong,short IdKhoanoitru,short IdBuong,decimal GiaDichvu,decimal? GiaBhyt,decimal? PhuthuDungtuyen,decimal? PhuthuTraituyen,decimal? GiaKhac,short SonguoiToida,string MotaThem,string MaDonvitinh,byte? TrangThai,byte? TthaiTunguyen,byte? DangSudung,short? SttHthi,string TenBhyt)
        {
            NoitruDmucGiuongbenh item = new NoitruDmucGiuongbenh();

            item.MaGiuong = MaGiuong;

            item.TenGiuong = TenGiuong;

            item.IdKhoanoitru = IdKhoanoitru;

            item.IdBuong = IdBuong;

            item.GiaDichvu = GiaDichvu;

            item.GiaBhyt = GiaBhyt;

            item.PhuthuDungtuyen = PhuthuDungtuyen;

            item.PhuthuTraituyen = PhuthuTraituyen;

            item.GiaKhac = GiaKhac;

            item.SonguoiToida = SonguoiToida;

            item.MotaThem = MotaThem;

            item.MaDonvitinh = MaDonvitinh;

            item.TrangThai = TrangThai;

            item.TthaiTunguyen = TthaiTunguyen;

            item.DangSudung = DangSudung;

            item.SttHthi = SttHthi;

            item.TenBhyt = TenBhyt;

            item.Save(UserName);
        }
        /// <summary>
        /// hàm thưucj hiện việc cập nhập lại thông tin thành công
        /// </summary>
        private void UpdateData()
        {
            objBed=  createBed();
              objBed.MarkOld();
              objBed.IsNew = false;
              objBed.Save();
            if (MyGetData != null)
            {
                MyGetData();
                Utility.GonewRowJanus(grdList, NoitruDmucGiuongbenh.Columns.IdGiuong, Utility.sDbnull(txtID.Text));
            }
            if (chkApDungGia.Checked)
            {
                new Delete().From(NoitruQheDoituongBuonggiuong.Schema)
             .Where(NoitruQheDoituongBuonggiuong.Columns.IdGiuong).IsEqualTo(Utility.Int32Dbnull(txtID.Text)).Execute();
                foreach (Janus.Windows.GridEX.GridEXRow gridExRow in grdQuanheGiuong.GetCheckedRows())
                {
                    NoitruQheDoituongBuonggiuong objectType = new NoitruQheDoituongBuonggiuong();
                    objectType.DonGia = (objectType.MaDoituongKcb == "DV" ?
                                     Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaDichvu)
                                     : (objectType.MaDoituongKcb == "BHYT" ?
                                     Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaBhyt) :
                                     Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaKhac))
                                     )
                                     ;
                    objectType.PhuthuDungtuyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuDungtuyen].Value,0);
                    objectType.PhuthuTraituyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuTraituyen].Value,0);
                    objectType.MaDoituongKcb = Utility.sDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.MaDoituongKcb].Value);
                    SqlQuery sqlQuery =
                        new Select().From(DmucDoituongkcb.Schema).Where(DmucDoituongkcb.Columns.MaDoituongKcb).IsEqualTo(
                            objectType.MaDoituongKcb);
                    DmucDoituongkcb objectType1 = sqlQuery.ExecuteSingle<DmucDoituongkcb>();
                    if (objectType1 != null)
                    {
                        objectType.IdLoaidoituongKcb = Utility.Int32Dbnull(objectType1.IdLoaidoituongKcb);
                    }
                    objectType.KieuThue = "GIUONG";
                    // DmucDoituongkcb objectType1=DmucDoituongkcb.FetchByID()
                    objectType.IdBuong = Utility.Int16Dbnull(txtBuong.MyID);
                    objectType.IdGiuong = Utility.Int16Dbnull(objBed.IdGiuong, -1);
                    objectType.IsNew = true;
                    objectType.Save();
                }

            }
            Utility.SetMsg(lblMsg, "Bạn thực hiện sửa thông tin  thành công", true);
            if (chkthemmoilientuc.Checked)
            {
                ClearControl();
            }
            else
                this.Close();
        }
        private void MultiInsertData()
        {
            try
            {
                 Int16 STTHthi=Utility.Int16Dbnull(txt_STT_HTHI.Text);
                 for (int i = Utility.Int32Dbnull(Utility.DecimaltoDbnull(txtCodefrom.Text), 0); i <= Utility.Int32Dbnull(Utility.DecimaltoDbnull(txtCode2.Text), 0); i++)
                 {
                     NoitruDmucGiuongbenh objBed = new NoitruDmucGiuongbenh();
                     objBed.IdKhoanoitru = Utility.Int16Dbnull(cboKhoaNoiTru.SelectedValue);
                     objBed.IdBuong = Utility.Int16Dbnull(txtBuong.MyID);
                     objBed.MotaThem = Utility.sDbnull(txt_Mo_Ta.Text);
                     objBed.SonguoiToida = Utility.Int16Dbnull(txtSuChua.Value);
                     objBed.SttHthi = Utility.Int16Dbnull(txt_STT_HTHI.Value);
                     objBed.MaGiuong = Utility.sDbnull(txtMa.Text)+i.ToString();
                     objBed.TenGiuong = Utility.sDbnull(txtTEN.Text)+ " "+i.ToString();
                     objBed.TenBhyt = Utility.sDbnull(txtTEN.Text) + " " + i.ToString();
                     objBed.MaDonvitinh = txtDonvitinh.myCode;
                     objBed.TthaiTunguyen = Utility.Bool2byte(chktutuc.Checked);
                     objBed.GiaDichvu = Utility.DecimaltoDbnull(txtDongia.Text, 0);
                     objBed.GiaBhyt = Utility.DecimaltoDbnull(txtGiaBHYT.Text, 0);
                     objBed.GiaKhac = Utility.DecimaltoDbnull(txtGiakhac.Text, 0);
                     objBed.PhuthuDungtuyen = Utility.DecimaltoDbnull(txtPTDT.Text, 0);
                     objBed.PhuthuTraituyen = Utility.DecimaltoDbnull(txtPTTT.Text, 0);
                     objBed.TrangThai = (byte?)(chkTrangThai.Checked ? 1 : 0);
                     NoitruDmucGiuongbenh objcheck = new Select().From(NoitruDmucGiuongbenh.Schema)
                         .Where(NoitruDmucGiuongbenh.Columns.MaGiuong).IsEqualTo(objBed.MaGiuong)
                         .And(NoitruDmucGiuongbenh.Columns.IdKhoanoitru).IsEqualTo(objBed.IdKhoanoitru)
                         .And(NoitruDmucGiuongbenh.Columns.IdBuong).IsEqualTo(objBed.IdBuong)
                         .ExecuteSingle<NoitruDmucGiuongbenh>();
                     if (objcheck != null)
                     {
                         if (chkAutoupdate.Checked)
                         {
                             objBed.IdGiuong = objcheck.IdGiuong;
                             objBed.MarkOld();
                             objBed.IsNew = false;
                         }
                         else
                         {
                             continue;
                         }
                     }
                     else
                     {
                         STTHthi += 1;
                         objBed.IsNew = true;
                     }
                     objBed.SttHthi = STTHthi;
                     objBed.Save();

                     if (objBed != null)
                     {

                         if (chkApDungGia.Checked)
                         {
                             new Delete().From(NoitruQheDoituongBuonggiuong.Schema)
                      .Where(NoitruQheDoituongBuonggiuong.Columns.IdGiuong).IsEqualTo(Utility.Int32Dbnull(txtID.Text)).Execute();
                             foreach (Janus.Windows.GridEX.GridEXRow gridExRow in grdQuanheGiuong.GetCheckedRows())
                             {
                                 NoitruQheDoituongBuonggiuong objectType = new NoitruQheDoituongBuonggiuong();
                                 objectType.DonGia =(objectType.MaDoituongKcb=="DV"?
                                     Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaDichvu)
                                     :(objectType.MaDoituongKcb=="BHYT"?
                                     Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaBhyt):
                                     Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaKhac))
                                     )
                                     ;
                                 objectType.PhuthuDungtuyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuDungtuyen].Value,0);
                                 objectType.PhuthuTraituyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuTraituyen].Value,0);
                                 objectType.MaDoituongKcb = Utility.sDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.MaDoituongKcb].Value);
                                 // DmucDoituongkcb objectType1=DmucDoituongkcb.FetchByID()
                                 SqlQuery sqlQuery =
                                    new Select().From(DmucDoituongkcb.Schema).Where(DmucDoituongkcb.Columns.MaDoituongKcb).IsEqualTo(
                                        objectType.MaDoituongKcb);
                                 DmucDoituongkcb objectType1 = sqlQuery.ExecuteSingle<DmucDoituongkcb>();
                                 if (objectType1 != null)
                                 {
                                     objectType.IdLoaidoituongKcb = Utility.Int32Dbnull(objectType1.IdLoaidoituongKcb);
                                 }
                                 objectType.KieuThue = "GIUONG";
                                 objectType.IdBuong = Utility.Int16Dbnull(txtBuong.MyID);
                                 objectType.IdGiuong = Utility.Int16Dbnull(objBed.IdGiuong, -1);

                                 objectType.IsNew = true;
                                 objectType.Save();
                             }
                         }

                     }
                 }
                 if (MyGetData != null)
                 {
                     MyGetData();
                     Utility.GonewRowJanus(grdList, NoitruDmucGiuongbenh.Columns.IdGiuong, Utility.sDbnull(txtID.Text));
                 }
                Utility.SetMsg(lblMsg, "Bạn thực hiện thêm mới thành công", true);
                if (chkthemmoilientuc.Checked) ClearControl();
                else
                    Close();

            }
            catch (Exception)
            {

            }
        }
        private void MultiInsertData()
        {
            try
            {
                Int16 STTHthi = Utility.Int16Dbnull(txt_STT_HTHI.Text);
                for (int i = Utility.Int32Dbnull(Utility.DecimaltoDbnull(txtCodefrom.Text), 0); i <= Utility.Int32Dbnull(Utility.DecimaltoDbnull(txtCode2.Text), 0); i++)
                {
                    NoitruDmucGiuongbenh objBed = new NoitruDmucGiuongbenh();
                    objBed.IdKhoanoitru    = Utility.Int16Dbnull(cboKhoaNoiTru.SelectedValue);
                    objBed.IdBuong         = Utility.Int16Dbnull(txtBuong.MyID);
                    objBed.MotaThem        = Utility.sDbnull(txt_Mo_Ta.Text);
                    objBed.SonguoiToida    = Utility.Int16Dbnull(txtSuChua.Value);
                    objBed.SttHthi         = Utility.Int16Dbnull(txt_STT_HTHI.Value);
                    objBed.MaGiuong        = Utility.sDbnull(txtMa.Text) + i.ToString();
                    objBed.MaBhyt          = Utility.sDbnull(txtMaBHYT.Text) + i.ToString();
                    objBed.TenGiuong       = Utility.sDbnull(txtTEN.Text) + " " + i.ToString();
                    objBed.TenBhyt         = Utility.sDbnull(txtTEN.Text) + " " + i.ToString();
                    objBed.MaDonvitinh     = txtDonvitinh.myCode;
                    objBed.TthaiTunguyen   = Utility.Bool2byte(chktutuc.Checked);
                    objBed.GiaDichvu       = Utility.DecimaltoDbnull(txtDongia.Text, 0);
                    objBed.GiaBhyt         = Utility.DecimaltoDbnull(txtGiaBHYT.Text, 0);
                    objBed.GiaKhac         = Utility.DecimaltoDbnull(txtGiakhac.Text, 0);
                    objBed.PhuthuDungtuyen = Utility.DecimaltoDbnull(txtPTDT.Text, 0);
                    objBed.PhuthuTraituyen = Utility.DecimaltoDbnull(txtPTTT.Text, 0);
                    objBed.TrangThai       = (byte?)(chkTrangThai.Checked ? 1 : 0);
                    NoitruDmucGiuongbenh objcheck = new Select().From(NoitruDmucGiuongbenh.Schema)
                                                    .Where(NoitruDmucGiuongbenh.Columns.MaGiuong).IsEqualTo(objBed.MaGiuong)
                                                    .And(NoitruDmucGiuongbenh.Columns.IdKhoanoitru).IsEqualTo(objBed.IdKhoanoitru)
                                                    .And(NoitruDmucGiuongbenh.Columns.IdBuong).IsEqualTo(objBed.IdBuong)
                                                    .ExecuteSingle <NoitruDmucGiuongbenh>();
                    if (objcheck != null)
                    {
                        if (chkAutoupdate.Checked)
                        {
                            objBed.IdGiuong = objcheck.IdGiuong;
                            objBed.MarkOld();
                            objBed.IsNew = false;
                        }
                        else
                        {
                            continue;
                        }
                    }
                    else
                    {
                        STTHthi     += 1;
                        objBed.IsNew = true;
                    }
                    objBed.SttHthi = STTHthi;
                    objBed.Save();

                    if (objBed != null)
                    {
                        if (chkApDungGia.Checked)
                        {
                            new Delete().From(NoitruQheDoituongBuonggiuong.Schema)
                            .Where(NoitruQheDoituongBuonggiuong.Columns.IdGiuong).IsEqualTo(Utility.Int32Dbnull(txtID.Text)).Execute();
                            foreach (Janus.Windows.GridEX.GridEXRow gridExRow in grdQuanheGiuong.GetCheckedRows())
                            {
                                NoitruQheDoituongBuonggiuong objectType = new NoitruQheDoituongBuonggiuong();
                                objectType.DonGia = (objectType.MaDoituongKcb == "DV"?
                                                     Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaDichvu)
                                     :(objectType.MaDoituongKcb == "BHYT"?
                                       Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaBhyt):
                                       Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.DonGia].Value, objBed.GiaKhac))
                                                     )
                                ;
                                objectType.PhuthuDungtuyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuDungtuyen].Value, 0);
                                objectType.PhuthuTraituyen = Utility.DecimaltoDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.PhuthuTraituyen].Value, 0);
                                objectType.MaDoituongKcb   = Utility.sDbnull(gridExRow.Cells[NoitruQheDoituongBuonggiuong.Columns.MaDoituongKcb].Value);
                                // DmucDoituongkcb objectType1=DmucDoituongkcb.FetchByID()
                                SqlQuery sqlQuery =
                                    new Select().From(DmucDoituongkcb.Schema).Where(DmucDoituongkcb.Columns.MaDoituongKcb).IsEqualTo(
                                        objectType.MaDoituongKcb);
                                DmucDoituongkcb objectType1 = sqlQuery.ExecuteSingle <DmucDoituongkcb>();
                                if (objectType1 != null)
                                {
                                    objectType.IdLoaidoituongKcb = Utility.Int32Dbnull(objectType1.IdLoaidoituongKcb);
                                }
                                objectType.KieuThue = "GIUONG";
                                objectType.IdBuong  = Utility.Int16Dbnull(txtBuong.MyID);
                                objectType.IdGiuong = Utility.Int16Dbnull(objBed.IdGiuong, -1);

                                objectType.IsNew = true;
                                objectType.Save();
                            }
                        }
                    }
                }
                if (MyGetData != null)
                {
                    MyGetData();
                    Utility.GonewRowJanus(grdList, NoitruDmucGiuongbenh.Columns.IdGiuong, Utility.sDbnull(txtID.Text));
                }
                Utility.SetMsg(lblMsg, "Bạn thực hiện thêm mới thành công", true);
                if (chkthemmoilientuc.Checked)
                {
                    ClearControl();
                }
                else
                {
                    Close();
                }
            }
            catch (Exception)
            {
            }
        }