private static PsReponse UpdateStatusSyncDanhMucDonVi(PSDanhMucDonViCoSo dvcs)
        {
            PsReponse res = new PsReponse();

            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                db.Connection.Open();
                db.Transaction = db.Connection.BeginTransaction();
                var dv = db.PSDanhMucDonViCoSos.FirstOrDefault(p => p.MaDVCS == dvcs.MaDVCS);
                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);
        }
Example #2
0
        public static bool UpdDonViCS(PSDanhMucDonViCoSo donViCS)
        {
            var db = new BioDAL();

            return(db.UpdDonViCS(donViCS));
        }
Example #3
0
        private void gridView_DonViCoSo_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                GridView view     = sender as GridView;
                int      rowfocus = e.RowHandle;
                if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_th_TenDVCS))))
                {
                    e.Valid = false;
                    view.SetColumnError(col_th_TenDVCS, "Tên đơn vị cơ sở không được để trống!");
                }
                if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_th_MaChiCuc))))
                {
                    e.Valid = false;
                    view.SetColumnError(col_th_MaChiCuc, "Chi cục không được để trống!");
                }
                if (e.Valid)
                {
                    byte[]             byteNull = ASCIIEncoding.ASCII.GetBytes("");
                    PSDanhMucDonViCoSo donVi    = new PSDanhMucDonViCoSo();
                    if (string.IsNullOrEmpty(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "RowIDDVCS").ToString()))
                    {
                        donVi.RowIDDVCS = 0;
                    }
                    else
                    {
                        donVi.RowIDDVCS = Convert.ToInt16(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "RowIDDVCS").ToString());
                    }
                    donVi.MaDVCS     = gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "MaDVCS").ToString();
                    donVi.TenDVCS    = gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "TenDVCS").ToString();
                    donVi.DiaChiDVCS = gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "DiaChiDVCS").ToString();
                    donVi.SDTCS      = gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "SDTCS").ToString();
                    if (string.IsNullOrEmpty(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "Logo").ToString()))
                    {
                        donVi.Logo = new Binary(byteNull);
                    }
                    else
                    {
                        donVi.Logo = (Binary)gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "Logo");
                    }
                    if (string.IsNullOrEmpty(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "HeaderReport").ToString()))
                    {
                        donVi.HeaderReport = new Binary(byteNull);
                    }
                    else
                    {
                        donVi.HeaderReport = (Binary)gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "HeaderReport");
                    }
                    if (string.IsNullOrEmpty(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "Stt").ToString()))
                    {
                        donVi.Stt = 0;
                    }
                    else
                    {
                        donVi.Stt = Convert.ToInt16(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "Stt").ToString());
                    }
                    if (string.IsNullOrEmpty(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "isLocked").ToString()))
                    {
                        donVi.isLocked = false;
                    }
                    else
                    {
                        donVi.isLocked = Convert.ToBoolean(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "isLocked").ToString());
                    }

                    donVi.MaChiCuc = gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "MaChiCuc").ToString();
                    if (string.IsNullOrEmpty(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "KieuTraKetQua").ToString()))
                    {
                        donVi.KieuTraKetQua = 1;
                    }
                    else
                    {
                        donVi.KieuTraKetQua = int.Parse(gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "KieuTraKetQua").ToString());
                    }
                    donVi.TenBacSiDaiDien = gridView_DonViCoSo.GetRowCellValue(e.RowHandle, "TenBacSiDaiDien").ToString();
                    donVi.isDongBo        = false;
                    if (e.RowHandle < 0)
                    {
                        string codeGen = BioBLL.GetCodeDonViCoSo(donVi.MaChiCuc);
                        this.codeGenOld = codeGen.ToString();
                        if (XtraMessageBox.Show("Danh mục đơn vị cs bạn thêm có mã tự động là " + codeGen + " bạn có muốn thay đổi không?", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.No)
                        {
                            int result = 0;
                            do
                            {
                                codeGen = this.InputForm(codeGen);
                                if (CheckCodeExist(codeGen))
                                {
                                    donVi.MaDVCS = codeGen;
                                    result       = 0;
                                }
                                else
                                {
                                    result  = 1;
                                    codeGen = this.codeGenOld;
                                }
                            } while (result == 1);
                        }
                        else
                        {
                            donVi.MaDVCS = codeGen;
                        }
                        if (BioBLL.InsDonViCS(donVi))
                        {
                            XtraMessageBox.Show("Thêm mới đơn vị cơ sở thành công!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            if (XtraMessageBox.Show("Hệ thống tự động thêm dịch vụ vào đơn vị này. \nBạn có muốn thực hiện tác vụ này không?", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.No)
                            {
                                List <PSDanhMucGoiDichVuChung>     lstGoiDV        = BioBLL.GetListGoiDichVuChung();
                                List <PSDanhMucGoiDichVuTheoDonVi> lstGoiTT        = new List <PSDanhMucGoiDichVuTheoDonVi>();
                                List <PSChiTietGoiDichVuChung>     lstChiTietGoiGV = BioBLL.GetListChiTietGoiDichVuChung();
                                foreach (var dv in lstGoiDV)
                                {
                                    PSDanhMucGoiDichVuTheoDonVi tt = new PSDanhMucGoiDichVuTheoDonVi();
                                    tt.IDGoiDichVuChung     = dv.IDGoiDichVuChung;
                                    tt.MaDVCS               = donVi.MaDVCS;
                                    tt.TenGoiDichVuTrungTam = dv.TenGoiDichVuChung;
                                    tt.DonGia               = dv.DonGia ?? 0;
                                    tt.ChietKhau            = dv.ChietKhau ?? 0;
                                    tt.isXoa    = false;
                                    tt.isDongBo = false;
                                    lstGoiTT.Add(tt);
                                }
                                if (!BioBLL.InsMultiGoiDichVuCoSo(lstGoiTT))
                                {
                                    XtraMessageBox.Show("Tự động thêm dịch vụ vào đơn vị thất bại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                }
                            }
                        }
                        else
                        {
                            XtraMessageBox.Show("Thêm mới đơn vị cơ sở thất bại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        PSDanhMucDonViCoSo dvOld = BioBLL.GetDonViCoSoById(donVi.RowIDDVCS);
                        if (BioBLL.UpdDonViCS(donVi))
                        {
                            PSDanhMucDonViCoSo dvNew = BioBLL.GetDonViCoSoById(donVi.RowIDDVCS);
                            if (dvOld.MaChiCuc != donVi.MaChiCuc)
                            {
                                XtraMessageBox.Show("Thay đổi mã đơn vị " + donVi.MaDVCS + " thành " + dvNew.MaDVCS + " thành công!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            XtraMessageBox.Show("Cập nhật đơn vị cơ sở thành công!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else
                        {
                            XtraMessageBox.Show("Cập nhật đơn vị cơ sở thất bại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    this.gridControl_DonViCoSo.DataSource = BioBLL.GetListDonViCoSo();
                }
            }
            catch { XtraMessageBox.Show("Thao tác thất bại!", "BioNet - Chương trình sàng lọc sơ sinh", MessageBoxButtons.OK, MessageBoxIcon.Error); }
        }
        public static PsReponse GetDanhMucDonViCoSo()
        {
            PsReponse res = new PsReponse();

            res.Result = true;
            try
            {
                ProcessDataSync cn = new ProcessDataSync();
                db = cn.db;
                var account = db.PSAccount_Syncs.FirstOrDefault();
                if (account != null)
                {
                    string token = cn.GetToken(account.userName, account.passWord);
                    if (!string.IsNullOrEmpty(token))
                    {
                        var result = cn.GetRespone(cn.CreateLink(linkGetDanhMucDonVi), token);
                        if (result.Result)
                        {
                            string json = result.ValueResult;
                            JavaScriptSerializer      jss  = new JavaScriptSerializer();
                            ObjectModel.RootObjectAPI Repo = jss.Deserialize <ObjectModel.RootObjectAPI>(json);
                            if (Repo != null)
                            {
                                if (Repo.TotalCount > 0)
                                {
                                    foreach (var item in Repo.Items)
                                    {
                                        PSDanhMucDonViCoSo kt = new PSDanhMucDonViCoSo();
                                        kt = cn.CovertDynamicToObjectModel(item, kt);
                                        var resup = UpdateDMDonviCoso(kt);
                                        if (!resup.Result)
                                        {
                                            res.StringError += resup.StringError;
                                            res.Result       = false;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                res.Result      = false;
                                res.StringError = result.ErorrResult;
                            }
                        }
                        else
                        {
                            res.Result      = false;
                            res.StringError = result.ErorrResult;
                        }
                    }
                    else
                    {
                        res.Result      = false;
                        res.StringError = "Kiểm tra lại kết nối mạng hoặc tài khoản đồng bộ!";
                    }
                }
                else
                {
                    res.Result      = false;
                    res.StringError = "Chưa có  tài khoản đồng bộ!";
                }
            }
            catch (Exception ex)
            {
                res.Result      = false;
                res.StringError = DateTime.Now.ToString() + "Lỗi khi get dữ liệu Danh Mục Kỹ Thuật từ server \r\n " + ex.Message;
            }
            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);
        }