public static PsReponse GetDanhSachChuongTrinh() { PsReponse res = new PsReponse(); 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(linkGetDanhMucChuongTrinh), 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) { PSDanhMucChuongTrinh ct = new PSDanhMucChuongTrinh(); ct = cn.CovertDynamicToObjectModel(item, ct); UpdateDMChuongTrinh(ct); } res.Result = true; } } } else { res.Result = false; res.StringError = result.ErorrResult; } } } } catch (Exception ex) { res.Result = false; res.StringError = DateTime.Now.ToString() + "Lỗi khi get dữ liệu Danh Sách Chương Trình Sàng Lọc từ server \r\n " + ex.Message; } 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); }
public static bool UpdChuongTrinh(PSDanhMucChuongTrinh chuongTrinh) { var db = new BioDAL(); return(db.UpdChuongTrinh(chuongTrinh)); }
private void gridView_ChuongTrinh_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_IDChuongTrinh)))) { e.Valid = false; view.SetColumnError(col_th_IDChuongTrinh, "Mã chương trình không được để trống!"); } if (string.IsNullOrEmpty(Convert.ToString(view.GetRowCellValue(rowfocus, col_th_TenChuongTrinh)))) { e.Valid = false; view.SetColumnError(col_th_TenChuongTrinh, "Tên chương trình không được để trống!"); } if (e.Valid) { PSDanhMucChuongTrinh chuongTrinh = new PSDanhMucChuongTrinh(); if (string.IsNullOrEmpty(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "RowIDChuongTrinh").ToString())) { chuongTrinh.RowIDChuongTrinh = 0; } else { chuongTrinh.RowIDChuongTrinh = Convert.ToInt32(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "RowIDChuongTrinh").ToString()); } chuongTrinh.IDChuongTrinh = gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "IDChuongTrinh").ToString(); chuongTrinh.TenChuongTrinh = gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "TenChuongTrinh").ToString(); if (string.IsNullOrEmpty(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "Ngaytao").ToString())) { chuongTrinh.Ngaytao = null; } else { chuongTrinh.Ngaytao = Convert.ToDateTime(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "Ngaytao").ToString()); } if (string.IsNullOrEmpty(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "isLocked").ToString())) { chuongTrinh.isLocked = false; } else { chuongTrinh.isLocked = Convert.ToBoolean(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "isLocked").ToString()); } if (string.IsNullOrEmpty(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "NgayHetHieuLuc").ToString())) { chuongTrinh.NgayHetHieuLuc = null; } else { chuongTrinh.NgayHetHieuLuc = Convert.ToDateTime(gridView_ChuongTrinh.GetRowCellValue(e.RowHandle, "NgayHetHieuLuc").ToString()); } if (e.RowHandle < 0) { if (!BioBLL.CheckExistMaCT(chuongTrinh.IDChuongTrinh)) { XtraMessageBox.Show("Đã tồn tại mã chương trình!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); this.gridControl_ChuongTrinh.DataSource = BioBLL.GetListChuongTrinh(); return; } if (BioBLL.InsChuongTrinh(chuongTrinh)) { XtraMessageBox.Show("Thêm mới chương trình thành công!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("Thêm mới chương trình thất bại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (BioBLL.GetChuongTrinhById(Convert.ToInt32(chuongTrinh.RowIDChuongTrinh)).IDChuongTrinh != chuongTrinh.IDChuongTrinh) { if (!BioBLL.CheckExistMaCT(chuongTrinh.IDChuongTrinh)) { XtraMessageBox.Show("Đã tồn tại mã chương trình!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); this.gridControl_ChuongTrinh.DataSource = BioBLL.GetListChuongTrinh(); return; } } if (BioBLL.UpdChuongTrinh(chuongTrinh)) { XtraMessageBox.Show("Cập nhật chương trình thành công!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { XtraMessageBox.Show("Cập nhật chương trình thất bại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.gridControl_ChuongTrinh.DataSource = BioBLL.GetListChuongTrinh(); } } catch (Exception ex) { XtraMessageBox.Show("Thao tác thất bại thất bại!", "Bệnh viện điện tử .NET", MessageBoxButtons.OK, MessageBoxIcon.Error); this.gridControl_ChuongTrinh.DataSource = BioBLL.GetListChuongTrinh(); } }