private void dlgLamMoiSoHoaDon_Load(object sender, EventArgs e)
        {
            Result result = QuanLySoHoaDonXetNghiemBus.GetThayDoiSoHoaSonSauCung();

            if (result.IsOK)
            {
                if (result.QueryResult != null)
                {
                    NgayBatDauLamMoiSoHoaDonXetNghiemYKhoa thayDoiSauCung = result.QueryResult as NgayBatDauLamMoiSoHoaDonXetNghiemYKhoa;
                    dtpkNgayThayDoiSauCung.Value = thayDoiSauCung.NgayBatDau;
                    txtMauSoCu.Text      = thayDoiSauCung.MauSo;
                    txtKiHieuCu.Text     = thayDoiSauCung.KiHieu;
                    txtSoHDBatDauCu.Text = thayDoiSauCung.SoHoaDonBatDau.ToString();
                }
                else
                {
                    dtpkNgayThayDoiSauCung.Value = Global.MinDateTime;
                }
            }
            else
            {
                MsgBox.Show(Application.ProductName, result.GetErrorAsString("QuanLySoHoaDonXetNghiemBus.GetThayDoiSoHoaSonSauCung"), IconType.Error);
                Utility.WriteToTraceLog(result.GetErrorAsString("QuanLySoHoaDonXetNghiemBus.GetThayDoiSoHoaSonSauCung"));
            }

            dtpkNgayThayDoiMoi.Value = DateTime.Now;
        }
        public static Result SetThayDoiSoHoaSon(DateTime ngayThayDoi, string mauSo, string kiHieu, int soHoaDonBatDau)
        {
            Result     result = new Result();
            MMOverride db     = null;

            try
            {
                db = new MMOverride();
                NgayBatDauLamMoiSoHoaDonXetNghiemYKhoa nbd = new NgayBatDauLamMoiSoHoaDonXetNghiemYKhoa();
                nbd.MaNgayBatDauGUID = Guid.NewGuid();
                nbd.NgayBatDau       = ngayThayDoi;
                nbd.MauSo            = mauSo;
                nbd.KiHieu           = kiHieu;
                nbd.SoHoaDonBatDau   = soHoaDonBatDau;
                db.NgayBatDauLamMoiSoHoaDonXetNghiemYKhoas.InsertOnSubmit(nbd);
                db.SubmitChanges();
            }
            catch (System.Data.SqlClient.SqlException se)
            {
                result.Error.Code        = (se.Message.IndexOf("Timeout expired") >= 0) ? ErrorCode.SQL_QUERY_TIMEOUT : ErrorCode.INVALID_SQL_STATEMENT;
                result.Error.Description = se.ToString();
            }
            catch (Exception e)
            {
                result.Error.Code        = ErrorCode.UNKNOWN_ERROR;
                result.Error.Description = e.ToString();
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                    db = null;
                }
            }

            return(result);
        }