Beispiel #1
0
        public static PsReponse UpdateDMGoiDichVuTheoDonVi(PSDanhMucGoiDichVuTheoDonVi cl)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();

                var kyt = db.PSDanhMucGoiDichVuTheoDonVis.FirstOrDefault(p => p.IDGoiDichVuChung == cl.IDGoiDichVuChung && p.MaDVCS == cl.MaDVCS);
                if (kyt != null)
                {
                    if (kyt.isDongBo != false)
                    {
                        kyt.TenGoiDichVuTrungTam = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cl.TenGoiDichVuTrungTam));
                        kyt.DonGia    = cl.DonGia;
                        kyt.ChietKhau = cl.ChietKhau;
                        kyt.isDongBo  = true;
                        db.SubmitChanges();
                    }
                }
                else
                {
                    if (kyt.isDongBo != false)
                    {
                        PSDanhMucGoiDichVuTheoDonVi kyth = new PSDanhMucGoiDichVuTheoDonVi();
                        kyth.ChietKhau            = cl.ChietKhau;
                        kyth.DonGia               = cl.DonGia;
                        kyth.MaDVCS               = cl.MaDVCS;
                        kyth.IDGoiDichVuChung     = cl.IDGoiDichVuChung;
                        kyth.TenGoiDichVuTrungTam = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cl.TenGoiDichVuTrungTam));
                        db.PSDanhMucGoiDichVuTheoDonVis.InsertOnSubmit(kyth);
                        kyt.isDongBo = true;

                        db.SubmitChanges();
                    }
                }


                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateDMDichVu(PSDanhMucDichVu dv)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();

                var div = db.PSDanhMucDichVus.FirstOrDefault(p => p.IDDichVu == dv.IDDichVu);
                if (div != null)
                {
                    div.isLocked         = dv.isLocked;
                    div.isGoiXn          = dv.isGoiXn;
                    div.GiaDichVu        = dv.GiaDichVu;
                    div.MaNhom           = dv.MaNhom;
                    div.TenDichVu        = Encoding.UTF8.GetString(Encoding.Default.GetBytes(dv.TenDichVu));
                    div.TenHienThiDichVu = Encoding.UTF8.GetString(Encoding.Default.GetBytes(dv.TenHienThiDichVu));
                    db.SubmitChanges();
                }
                else
                {
                    PSDanhMucDichVu divu = new PSDanhMucDichVu();
                    divu.IDDichVu         = dv.IDDichVu;
                    divu.isLocked         = dv.isLocked;
                    divu.isGoiXn          = dv.isGoiXn;
                    divu.GiaDichVu        = dv.GiaDichVu;
                    divu.MaNhom           = dv.MaNhom;
                    divu.TenDichVu        = Encoding.UTF8.GetString(Encoding.Default.GetBytes(dv.TenDichVu));
                    divu.TenHienThiDichVu = Encoding.UTF8.GetString(Encoding.Default.GetBytes(dv.TenHienThiDichVu));
                    db.PSDanhMucDichVus.InsertOnSubmit(divu);
                    db.SubmitChanges();
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
Beispiel #3
0
        public static PsReponse UpdateChiDinh(PSXN_KetQua ketqua)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                var dv = db.PSXN_KetQuas.FirstOrDefault(p => p.MaKetQua == ketqua.MaKetQua);
                if (dv != null)
                {
                    dv.isDongBo = true;
                    db.SubmitChanges();
                }
                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
 private static PsReponse UpdateStatusSyncDanhMucChiCuc(PSDanhMucChiCuc chicuc)
 {
     PsReponse res = new PsReponse();
    
     try
     {
         ProcessDataSync cn = new ProcessDataSync();
         db = cn.db;
         db.Connection.Open();
         db.Transaction = db.Connection.BeginTransaction();
         var dv = db.PSDanhMucChiCucs.FirstOrDefault(p => p.MaChiCuc == chicuc.MaChiCuc);
         if (dv != null)
         {
             dv.isDongBo = true;
             db.SubmitChanges();
         }
         db.Transaction.Commit();
         db.Connection.Close();
         res.Result = true;
     }
     catch (Exception ex)
     {
         db.Transaction.Rollback();
         db.Connection.Close();
         res.Result = false;
         res.StringError = ex.ToString();
     }
     return res;
 }
Beispiel #5
0
        public static PsReponse UpdateChiDinhChiTiet(PSChiDinhDichVuChiTiet cdct)
        {
            PsReponse res = new PsReponse();

            res.Result = true;

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                var dv = db.PSChiDinhDichVuChiTiets.FirstOrDefault(p => p.MaChiDinh == cdct.MaChiDinh && p.MaDichVu == cdct.MaDichVu);
                if (dv == null)
                {
                    dv.isDongBo = true;
                    db.SubmitChanges();
                }
                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateDotChuanDoan(PSDotChuanDoan dcd)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                var dv = db.PSDotChuanDoans.FirstOrDefault(p => p.MaBenhNhan == dcd.MaBenhNhan && p.MaKhachHang == dcd.MaKhachHang);
                if (dv != null)
                {
                    dv.isDongBo = true;
                    db.SubmitChanges();
                }
                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        private static PsReponse UpdateStatusSyncThongTinTrungTam(PSThongTinTrungTam tt)
        {
            PsReponse       res = new PsReponse();
            ProcessDataSync cn  = new ProcessDataSync();

            db = cn.db;
            db.Connection.Open();
            db.Transaction = db.Connection.BeginTransaction();
            try
            {
                var dv = db.PSThongTinTrungTams.FirstOrDefault(p => p.MaTrungTam == tt.MaTrungTam);
                if (dv != null)
                {
                    dv.isDongBo = true;
                    db.SubmitChanges();
                }
                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
Beispiel #8
0
        public static PsReponse UpdateDMDanToc(List <PSDanhMucDanToc> Clm)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                var account = db.PSAccount_Syncs.FirstOrDefault();
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                foreach (var cl in Clm)
                {
                    var kyt = db.PSDanhMucDanTocs.FirstOrDefault(p => p.IDDanToc == cl.IDDanToc);
                    if (kyt != null)
                    {
                        kyt.IDQuocGia = cl.IDQuocGia;
                        kyt.STT       = cl.STT;
                        kyt.TenDanToc = cl.TenDanToc;
                        db.SubmitChanges();
                    }
                    else
                    {
                        PSDanhMucDanToc kyth = new PSDanhMucDanToc();
                        kyth.IDDanToc  = cl.IDDanToc;
                        kyth.IDQuocGia = cl.IDQuocGia;
                        kyth.STT       = cl.STT;
                        kyth.TenDanToc = cl.TenDanToc;
                        db.PSDanhMucDanTocs.InsertOnSubmit(kyth);
                        db.SubmitChanges();
                    }
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
Beispiel #9
0
        public static PsReponse UpdateDMKyThuat(PSDanhMucKyThuatXN kt)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();

                var kyt = db.PSDanhMucKyThuatXNs.FirstOrDefault(p => p.IDKyThuatXN == kt.IDKyThuatXN);
                if (kyt != null)
                {
                    kyt.isLocked          = kt.isLocked;
                    kyt.STT               = kt.STT;
                    kyt.TenKyThuat        = kt.TenKyThuat;
                    kyt.TenHienThiKyThuat = kt.TenHienThiKyThuat;
                    db.SubmitChanges();
                }
                else
                {
                    PSDanhMucKyThuatXN kyth = new PSDanhMucKyThuatXN();
                    kyth.isLocked          = kt.isLocked;
                    kyth.STT               = kt.STT;
                    kyth.TenKyThuat        = Encoding.UTF8.GetString(Encoding.Default.GetBytes(kt.TenKyThuat));
                    kyth.TenHienThiKyThuat = Encoding.UTF8.GetString(Encoding.Default.GetBytes(kt.TenHienThiKyThuat));
                    kyth.IDKyThuatXN       = kt.IDKyThuatXN;
                    db.PSDanhMucKyThuatXNs.InsertOnSubmit(kyth);
                    db.SubmitChanges();
                }


                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateTiepNhan(List <PSTiepNhan> lstpsl)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                var account = db.PSPhieuSangLocs.FirstOrDefault();
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                foreach (var psl in lstpsl)
                {
                    var psldb = db.PSTiepNhans.FirstOrDefault(p => p.MaPhieu == psl.MaPhieu);
                    if (psldb != null)
                    {
                        var term = psl.RowIDPhieu;
                        psldb            = psl;
                        psldb.RowIDPhieu = term;
                        db.SubmitChanges();
                    }
                    else
                    {
                        PSTiepNhan newpsl = new PSTiepNhan();
                        newpsl            = psl;
                        newpsl.RowIDPhieu = 0;
                        newpsl.isDongBo   = true;
                        db.PSTiepNhans.InsertOnSubmit(newpsl);
                        db.SubmitChanges();
                    }
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateDMGoiDichVuChung(PSDanhMucGoiDichVuChung cl)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();

                var kyt = db.PSDanhMucGoiDichVuChungs.FirstOrDefault(p => p.IDGoiDichVuChung == cl.IDGoiDichVuChung);
                if (kyt != null)
                {
                    kyt.TenGoiDichVuChung = cl.TenGoiDichVuChung;
                    kyt.DonGia            = cl.DonGia;
                    kyt.ChietKhau         = cl.ChietKhau;
                    db.SubmitChanges();
                }
                else
                {
                    PSDanhMucGoiDichVuChung kyth = new PSDanhMucGoiDichVuChung();
                    kyth.ChietKhau         = cl.ChietKhau;
                    kyth.DonGia            = cl.DonGia;
                    kyth.IDGoiDichVuChung  = cl.IDGoiDichVuChung;
                    kyth.TenGoiDichVuChung = cl.TenGoiDichVuChung;
                    db.PSDanhMucGoiDichVuChungs.InsertOnSubmit(kyth);
                    db.SubmitChanges();
                }


                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateDMMap_ThongSo_KyThuat(List <PSMapsXN_DichVu> Clm)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                var account = db.PSAccount_Syncs.FirstOrDefault();
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                foreach (var cl in Clm)
                {
                    var kyt = db.PSMapsXN_DichVus.FirstOrDefault(p => p.IDKyThuatXN == cl.IDKyThuatXN && p.IDDichVu == cl.IDDichVu);
                    if (kyt == null)
                    {
                        PSMapsXN_DichVu kyth = new PSMapsXN_DichVu();
                        kyth.IDKyThuatXN = cl.IDKyThuatXN;
                        kyth.IDDichVu    = cl.IDDichVu;
                        db.PSMapsXN_DichVus.InsertOnSubmit(kyth);
                        db.SubmitChanges();
                    }
                    else
                    {
                        var term = kyt.RowIDDichVuMaps;
                        kyt = cl;
                        kyt.RowIDDichVuMaps = term;
                        db.SubmitChanges();
                    }
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateDMChuongTrinh(PSDanhMucChuongTrinh ct)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db             = cn.db;
                db.Transaction = db.Connection.BeginTransaction();

                var ctr = db.PSDanhMucChuongTrinhs.FirstOrDefault(p => p.IDChuongTrinh == ct.IDChuongTrinh);
                if (ctr != null)
                {
                    ctr.isLocked       = ct.isLocked;
                    ctr.NgayHetHieuLuc = ct.NgayHetHieuLuc;
                    ctr.TenChuongTrinh = Encoding.UTF8.GetString(Encoding.Default.GetBytes(ct.TenChuongTrinh));
                    db.SubmitChanges();
                }
                else
                {
                    PSDanhMucChuongTrinh chtr = new PSDanhMucChuongTrinh();
                    chtr.IDChuongTrinh  = ct.IDChuongTrinh;
                    chtr.isLocked       = ct.isLocked;
                    chtr.NgayHetHieuLuc = ct.NgayHetHieuLuc;
                    chtr.Ngaytao        = ct.Ngaytao;
                    chtr.TenChuongTrinh = Encoding.UTF8.GetString(Encoding.Default.GetBytes(ct.TenChuongTrinh));
                    db.PSDanhMucChuongTrinhs.InsertOnSubmit(chtr);
                    db.SubmitChanges();
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = DateTime.Now.ToString() + "Lỗi khi cập nhật dữ liệu Danh Mục Chương Trình \r\n" + ex.ToString();
            }
            return(res);
        }
Beispiel #14
0
        public static PsReponse UpdateDMDanhGiaChatLuongMau(PSDanhMucDanhGiaChatLuongMau cl)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();

                var kyt = db.PSDanhMucDanhGiaChatLuongMaus.FirstOrDefault(p => p.IDDanhGiaChatLuongMau == cl.IDDanhGiaChatLuongMau);
                if (kyt != null)
                {
                    kyt.isLocked     = cl.isLocked;
                    kyt.ChatLuongMau = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cl.ChatLuongMau));
                    db.SubmitChanges();
                }
                else
                {
                    PSDanhMucDanhGiaChatLuongMau kyth = new PSDanhMucDanhGiaChatLuongMau();
                    kyth.isLocked              = cl.isLocked;
                    kyth.ChatLuongMau          = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cl.ChatLuongMau));
                    kyth.IDDanhGiaChatLuongMau = cl.IDDanhGiaChatLuongMau;
                    db.PSDanhMucDanhGiaChatLuongMaus.InsertOnSubmit(kyth);
                    db.SubmitChanges();
                }


                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
Beispiel #15
0
        public static PsReponse UpdateDMMap_ThongSo_KyThuat(List <PSMapsXN_ThongSo> Clm)
        {
            PsReponse res = new PsReponse();

            try
            {
                db = new BioNetDBContextDataContext(BioNetModel.Data.DataContext.connectionString);
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                foreach (var cl in Clm)
                {
                    var kyt = db.PSMapsXN_ThongSos.FirstOrDefault(p => p.IDKyThuatXN == cl.IDKyThuatXN && p.IDThongSo == cl.IDThongSo);
                    if (kyt != null)
                    {
                    }
                    else
                    {
                        PSMapsXN_ThongSo kyth = new PSMapsXN_ThongSo();
                        kyth.IDKyThuatXN = cl.IDKyThuatXN;
                        kyth.IDThongSo   = cl.IDThongSo;
                        db.PSMapsXN_ThongSos.InsertOnSubmit(kyth);
                        db.SubmitChanges();
                    }
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
Beispiel #16
0
        public static PsReponse UpdateDMThongSo(List <PSDanhMucThongSoXN> Clm)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                foreach (var cl in Clm)
                {
                    var kyt = db.PSDanhMucThongSoXNs.FirstOrDefault(p => p.IDThongSoXN == cl.IDThongSoXN);
                    if (kyt != null)
                    {
                        kyt.DonViTinh          = cl.DonViTinh;
                        kyt.GiaTri             = cl.GiaTri;
                        kyt.GiaTriMacDinh      = cl.GiaTriMacDinh;
                        kyt.GiaTriMaxNam       = cl.GiaTriMaxNam;
                        kyt.GiaTriMaxNu        = cl.GiaTriMaxNu;
                        kyt.GiaTriMinNam       = cl.GiaTriMinNam;
                        kyt.GiaTriMinNu        = cl.GiaTriMinNu;
                        kyt.GiaTriTrungBinhNam = cl.GiaTriTrungBinhNam;
                        kyt.GiaTriTrungBinhNu  = cl.GiaTriTrungBinhNu;
                        kyt.MaDonViTinh        = cl.MaDonViTinh;
                        kyt.MaNhom             = kyt.MaNhom;
                        kyt.Stt        = cl.Stt;
                        kyt.TenThongSo = cl.TenThongSo;
                        db.SubmitChanges();
                    }
                    else
                    {
                        PSDanhMucThongSoXN kyth = new PSDanhMucThongSoXN();
                        kyth.DonViTinh          = cl.DonViTinh;
                        kyth.GiaTri             = cl.GiaTri;
                        kyth.GiaTriMacDinh      = cl.GiaTriMacDinh;
                        kyth.GiaTriMaxNam       = cl.GiaTriMaxNam;
                        kyth.GiaTriMaxNu        = cl.GiaTriMaxNu;
                        kyth.GiaTriMinNam       = cl.GiaTriMinNam;
                        kyth.GiaTriMinNu        = cl.GiaTriMinNu;
                        kyth.GiaTriTrungBinhNam = cl.GiaTriTrungBinhNam;
                        kyth.GiaTriTrungBinhNu  = cl.GiaTriTrungBinhNu;
                        kyth.MaDonViTinh        = cl.MaDonViTinh;
                        kyth.MaNhom             = kyt.MaNhom;
                        kyth.Stt         = cl.Stt;
                        kyth.TenThongSo  = cl.TenThongSo;
                        kyth.IDThongSoXN = cl.IDThongSoXN;
                        db.PSDanhMucThongSoXNs.InsertOnSubmit(kyth);
                        db.SubmitChanges();
                    }
                }

                db.Transaction.Commit();
                db.Connection.Close();
                res.Result = true;
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateDMDonviCoso(PSDanhMucDonViCoSo cc)
        {
            PsReponse res = new PsReponse();

            res.Result = true;
            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();

                var kyt = db.PSDanhMucDonViCoSos.FirstOrDefault(p => p.MaDVCS == cc.MaDVCS);
                if (kyt != null)
                {
                    if (!kyt.isDongBo ?? false)
                    {
                        kyt.isLocked        = cc.isLocked;
                        kyt.Stt             = cc.Stt;
                        kyt.TenDVCS         = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.TenDVCS));
                        kyt.SDTCS           = cc.SDTCS;
                        kyt.DiaChiDVCS      = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.DiaChiDVCS));
                        kyt.MaChiCuc        = cc.MaChiCuc;
                        kyt.isLocked        = cc.isLocked;
                        kyt.KieuTraKetQua   = cc.KieuTraKetQua;
                        kyt.TenBacSiDaiDien = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.TenBacSiDaiDien));

                        try
                        {
                            kyt.HeaderReport = cc.HeaderReport;
                            kyt.Logo         = cc.Logo;
                        }
                        catch
                        { }

                        db.SubmitChanges();
                    }
                }
                else
                {
                    PSDanhMucDonViCoSo ccnew = new PSDanhMucDonViCoSo();
                    ccnew.isLocked        = cc.isLocked;
                    ccnew.Stt             = cc.Stt;
                    ccnew.TenDVCS         = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.TenDVCS));
                    ccnew.SDTCS           = cc.SDTCS;
                    ccnew.DiaChiDVCS      = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.DiaChiDVCS));
                    ccnew.TenBacSiDaiDien = cc.TenBacSiDaiDien;
                    ccnew.isDongBo        = true;
                    ccnew.MaChiCuc        = cc.MaChiCuc;
                    ccnew.MaDVCS          = cc.MaDVCS;
                    try
                    {
                        ccnew.HeaderReport = cc.HeaderReport;
                    }
                    catch { }
                    try
                    {
                        ccnew.Logo = cc.Logo;
                    }
                    catch { }
                    db.PSDanhMucDonViCoSos.InsertOnSubmit(ccnew);
                    db.SubmitChanges();
                }


                db.Transaction.Commit();
                db.Connection.Close();
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }
        public static PsReponse UpdateDMChiCuc(PSDanhMucChiCuc cc)
        {
            PsReponse res = new PsReponse();
            res.Result = true;
            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();

                var kyt = db.PSDanhMucChiCucs.FirstOrDefault(p => p.MaChiCuc == cc.MaChiCuc);
                if (kyt != null)
                {
                    if (!kyt.isDongBo)
                    {
                        kyt.isLocked = cc.isLocked;
                        kyt.Stt = cc.Stt;
                        kyt.TenChiCuc = Encoding.UTF8.GetString(Encoding.Default.GetBytes( cc.TenChiCuc));
                        kyt.SdtChiCuc = cc.SdtChiCuc;
                        kyt.DiaChiChiCuc = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.DiaChiChiCuc));
                        kyt.MaTrungTam = cc.MaTrungTam;
                        kyt.isXoa = cc.isXoa;
                        try
                        {
                            kyt.HeaderReport = cc.HeaderReport;
                            kyt.Logo = cc.Logo;
                        }
                        catch
                        { }

                        db.SubmitChanges();
                    }
                }
                else
                {
                  
                    PSDanhMucChiCuc ccnew = new PSDanhMucChiCuc();
                    ccnew.isLocked = cc.isLocked;
                    ccnew.Stt = cc.Stt;
                    ccnew.TenChiCuc = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.TenChiCuc));
                    ccnew.SdtChiCuc = cc.SdtChiCuc;
                    ccnew.DiaChiChiCuc = Encoding.UTF8.GetString(Encoding.Default.GetBytes(cc.DiaChiChiCuc));
                    ccnew.MaTrungTam = cc.MaTrungTam;
                    ccnew.isXoa = cc.isXoa;
                    ccnew.MaChiCuc = cc.MaChiCuc;
                    try
                    {
                        ccnew.HeaderReport = cc.HeaderReport;
                        ccnew.Logo = cc.Logo;
                    }
                    catch { }
                    db.PSDanhMucChiCucs.InsertOnSubmit(ccnew);
                    db.SubmitChanges();
                    
                }


                db.Transaction.Commit();
                db.Connection.Close();
                

            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result = false;
                res.StringError = ex.ToString();
            }
            return res;
        }
        public static PsReponse UpdateThongTinTrungTam(PSThongTinTrungTam tt)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                PSThongTinTrungTam ttam = db.PSThongTinTrungTams.FirstOrDefault();
                if (ttam == null)
                {
                    PSThongTinTrungTam ttnew = new PSThongTinTrungTam();
                    ttnew.Diachi      = Encoding.UTF8.GetString(Encoding.Default.GetBytes(tt.Diachi));
                    ttnew.DienThoai   = tt.DienThoai;
                    ttnew.ID          = tt.ID;
                    ttnew.LicenseKey  = tt.LicenseKey;
                    ttnew.Logo        = tt.Logo;
                    ttnew.MaTrungTam  = tt.MaTrungTam;
                    ttnew.MaVietTat   = tt.MaTrungTam.Substring(1, 2);
                    ttnew.TenTrungTam = Encoding.UTF8.GetString(Encoding.Default.GetBytes(tt.TenTrungTam));
                    db.PSThongTinTrungTams.InsertOnSubmit(ttnew);
                    db.SubmitChanges();
                    res.Result = true;
                }
                else
                if (string.IsNullOrEmpty(ttam.ID))
                {
                    res.Result = true;
                    db.PSThongTinTrungTams.FirstOrDefault().LicenseKey = tt.LicenseKey;
                    db.PSThongTinTrungTams.FirstOrDefault().ID         = tt.ID;
                    db.SubmitChanges();
                }
                else
                if (ttam.ID == tt.ID && ttam.MaTrungTam == tt.MaTrungTam)
                {
                    if (ttam.isDongBo != false)
                    {
                        res.Result = true;
                        db.PSThongTinTrungTams.FirstOrDefault().LicenseKey = tt.LicenseKey;
                        db.PSThongTinTrungTams.FirstOrDefault().isDongBo   = true;
                        db.SubmitChanges();
                    }
                }
                else
                {
                    res.Result      = false;
                    res.StringError = "ID giữa Trung tâm và tổng cục không tương xứng, vui lòng kiểm tra lại!";
                }
                db.Transaction.Commit();
                db.Connection.Close();
            }
            catch (Exception ex)
            {
                db.Transaction.Rollback();
                db.Connection.Close();
                res.Result      = false;
                res.StringError = ex.ToString();
            }
            return(res);
        }