protected void grdDVT_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { try { SYS_Session session = (SYS_Session)Session["SYS_Session"]; CBDN.DM_ChiNhanhSelectByIDDViResult HoatDong = (CBDN.DM_ChiNhanhSelectByIDDViResult)grdDVT.GetRow(grdDVT.FocusedRowIndex); if (HoatDong.DiemDauNguon != int.Parse(session.User.ma_dviqly)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Không thể xóa giao nhận này vì không phải đơn vị bạn tạo ra');", true); return; } var check = db.DM_Trams.Where(x => x.IDChiNhanh == HoatDong.ID + ""); if (check.Count() > 0) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Không thể xóa giao nhận này vì có trạm đang hoạt động ');", true); return; } CBDN.DM_ChiNhanh cv = new CBDN.DM_ChiNhanh(); cv = db.DM_ChiNhanhs.SingleOrDefault(x => x.ID == HoatDong.ID && x.IDMADVIQLY.Contains(session.User.ma_dviqly)); db.DM_ChiNhanhs.DeleteOnSubmit(cv); db.SubmitChanges(); _DataBind(); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Xoá phương thức giao nhận thành công');", true); } catch (Exception ex) { } finally { e.Cancel = true; } }
protected void btnSua_Click(object sender, EventArgs e) { pcAddRoles.ShowOnPageLoad = true; Session["Add"] = 0; SYS_Session session = (SYS_Session)Session["SYS_Session"]; CBDN.DM_ChiNhanhSelectByIDDViResult cv = (CBDN.DM_ChiNhanhSelectByIDDViResult)grdDVT.GetRow(grdDVT.FocusedRowIndex); txtMaDuongDat.Text = cv.MaChiNhanh; if (cv.HoatDong == 1) { CkHoatDong.Checked = true; } else { CkHoatDong.Checked = false; } txtmoTa.Text = cv.MoTa; cmbloaiGiaoNhan.Value = cv.LoaiGiaoNhan; }
protected void grdDVT_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) { try { SYS_Session session = (SYS_Session)Session["SYS_Session"]; CBDN.DM_ChiNhanhSelectByIDDViResult HoatDong = (CBDN.DM_ChiNhanhSelectByIDDViResult)grdDVT.GetRow(grdDVT.FocusedRowIndex); CBDN.DM_ChiNhanh cv = new CBDN.DM_ChiNhanh(); cv = db.DM_ChiNhanhs.SingleOrDefault(x => x.ID == HoatDong.ID && x.IDMADVIQLY == int.Parse(session.User.ma_dviqly)); db.DM_ChiNhanhs.DeleteOnSubmit(cv); db.SubmitChanges(); _DataBind(); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Xoá phương thức giao nhận thành công');", true); } catch (Exception ex) { } finally { e.Cancel = true; } }
protected void btnCapNhat_Click(object sender, EventArgs e) { DM_DVQLYService dm_dviSer = new DM_DVQLYService(); SYS_Session session = (SYS_Session)Session["SYS_Session"]; string dvdaunguon = dm_dviSer.SelectDM_DVQLY(int.Parse(session.User.ma_dviqly)).MA_DVIQLY; if (Session["Add"] + "" == "0") { CBDN.DM_ChiNhanhSelectByIDDViResult cv = (CBDN.DM_ChiNhanhSelectByIDDViResult)grdDVT.GetRow(grdDVT.FocusedRowIndex); var lst = db.DM_ChiNhanhs.Where(x => x.MaChiNhanh == cv.MaChiNhanh); foreach (var qtCT in lst) { if (!CheckName(txtMaDuongDat.Text, cv.ID)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Mã phương thức giao nhận được trùng');", true); return; } qtCT.TenChiNhanh = txtmoTa.Text; qtCT.MoTa = txtmoTa.Text; if (CkHoatDong.Checked) { qtCT.HoatDong = 1; } else { qtCT.HoatDong = 0; } db.SubmitChanges(); } } else { if (txtMaDuongDat.Text + "" == "") { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Mã chi nhánh không được để trống');", true); txtMaDuongDat.Focus(); return; } if (!CheckName(txtMaDuongDat.Text, 0)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Mã chi nhánh không được trùng');", true); return; } CBDN.DM_ChiNhanh cv = new CBDN.DM_ChiNhanh(); cv.TenChiNhanh = txtmoTa.Text; cv.MaChiNhanh = txtMaDuongDat.Text; cv.IDMADVIQLY = int.Parse(session.User.ma_dviqly); cv.MoTa = txtmoTa.Text; cv.DiemDauNguon = int.Parse(session.User.ma_dviqly); cv.DiemCuoiNguon = int.Parse(session.User.ma_dviqly); if (CkHoatDong.Checked) { cv.HoatDong = 1; } else { cv.HoatDong = 0; } cv.ISNhaMay = true; cv.LoaiNhaMay = int.Parse(cmbloaiGiaoNhan.Value + ""); db.DM_ChiNhanhs.InsertOnSubmit(cv); db.SubmitChanges(); } pcAddRoles.ShowOnPageLoad = false; _DataBind(); }
protected void btnCapNhat_Click(object sender, EventArgs e) { DM_DVQLYService dm_dviSer = new DM_DVQLYService(); SYS_Session session = (SYS_Session)Session["SYS_Session"]; string dvdaunguon = dm_dviSer.SelectDM_DVQLY(int.Parse(session.User.ma_dviqly)).MA_DVIQLY; string dvcuoinguon = dm_dviSer.SelectDM_DVQLY(int.Parse(cmbCuoiNguon.Value + "")).MA_DVIQLY; if (Session["Add"] + "" == "0") { CBDN.DM_ChiNhanhSelectByIDDViResult qtCT = (CBDN.DM_ChiNhanhSelectByIDDViResult)grdDVT.GetRow(grdDVT.FocusedRowIndex); //var lst = db.DM_ChiNhanhs.Where(x => x.MaChiNhanh == cv.MaChiNhanh); //foreach (var qtCT in lst) //{ CBDN.DM_ChiNhanh cn = db.DM_ChiNhanhs.SingleOrDefault(x => x.ID == qtCT.ID); if (!CheckName(txtMaDuongDat.Text, qtCT.ID)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Mã phương thức giao nhận được trùng');", true); return; } cn.TenChiNhanh = txtmoTa.Text; cn.LoaiPhuongThuc = int.Parse(cmbLoaiPhuongThuc.Value + ""); cn.MoTa = txtmoTa.Text; if (CkHoatDong.Checked) { cn.HoatDong = 1; } else { cn.HoatDong = 0; } db.SubmitChanges(); //} } else { if (txtMaDuongDat.Text + "" == "") { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Mã chi nhánh không được để trống');", true); txtMaDuongDat.Focus(); return; } //if (txtTenDuongDay.Text == "") //{ // ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Tên chi nhánh không được để trống');", true); // txtTenDuongDay.Focus(); return; //} if (!CheckName(txtMaDuongDat.Text, 0)) { ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('Mã chi nhánh không được trùng');", true); return; } CBDN.DM_ChiNhanh cv = new CBDN.DM_ChiNhanh(); cv.TenChiNhanh = txtmoTa.Text; cv.MaChiNhanh = dvdaunguon + "_" + dvcuoinguon; if (session.User.ma_dviqly != "" + cmbCuoiNguon.Value) { cv.IDMADVIQLY = "," + session.User.ma_dviqly + "," + cmbCuoiNguon.Value + ","; } else { cv.IDMADVIQLY = session.User.ma_dviqly; } cv.LoaiPhuongThuc = int.Parse(cmbLoaiPhuongThuc.Value + ""); cv.MoTa = txtmoTa.Text; cv.DiemDauNguon = int.Parse(session.User.ma_dviqly); cv.DiemCuoiNguon = int.Parse(cmbCuoiNguon.Value + ""); if (CkHoatDong.Checked) { cv.HoatDong = 1; } else { cv.HoatDong = 0; } db.DM_ChiNhanhs.InsertOnSubmit(cv); db.SubmitChanges(); //CBDN.DM_ChiNhanh cnGiaoNhan = new CBDN.DM_ChiNhanh(); //cnGiaoNhan.TenChiNhanh = txtmoTa.Text; //cnGiaoNhan.MaChiNhanh = dvdaunguon + "_" + dvcuoinguon; //cnGiaoNhan.IDMADVIQLY = int.Parse(cmbCuoiNguon.Value + ""); //cnGiaoNhan.MoTa = txtmoTa.Text; //cnGiaoNhan.DiemCuoiNguon = int.Parse(session.User.ma_dviqly); //cnGiaoNhan.DiemDauNguon = int.Parse(cmbCuoiNguon.Value + ""); //if (CkHoatDong.Checked) // cnGiaoNhan.HoatDong = 1; //else // cnGiaoNhan.HoatDong = 0; //db.DM_ChiNhanhs.InsertOnSubmit(cnGiaoNhan); //db.SubmitChanges(); //} } pcAddRoles.ShowOnPageLoad = false; _DataBind(); }