protected void btnDangKy_Click(object sender, EventArgs e) { try { List<HosodangkychungnhanEntity> lstHonuoitrongdangky = HosodangkychungnhanBRL.GetByFK_iCosonuoiID(Convert.ToInt32(Session["iCosonuoitrongID"])); if (lstHonuoitrongdangky != null && lstHonuoitrongdangky.Count > 0) if (cbChungNhanLanDau.Checked == true) { lblLoi.Text = "Bạn không thể chọn đăng ký lần đầu! Vì bạn đã đăng ký 1 lần."; return; } List<PhatEntity> lstPhat = PhatBRL.GetByFK_iCosonuoiID(Convert.ToInt32(Session["iCosonuoitrongID"])); if (lstPhat != null && lstPhat.Count > 0) { lstPhat = PhatEntity.Sort(lstPhat, "dNgaythuchien", "DESC"); TimeSpan oDateTime = DateTime.Now - lstPhat[0].dNgaythuchien; int years = oDateTime.Days / 365; if (lstPhat[0].iMucdo != 0 && years <= 1) { lblLoi.Text = "Bạn không thể đăng ký vì đã vi phạm quy định của tổ chức VietGAP. Vui lòng liên hệ để biết thêm chi tiết"; return; } } HosodangkychungnhanEntity entity = new HosodangkychungnhanEntity(); entity.dNgaydangky = DateTime.Now; entity.FK_iCosonuoiID = Convert.ToInt32(Session["iCosonuoitrongID"]); entity.bLandau = cbChungNhanLanDau.Checked; entity.FK_iTochucchungnhanID = Convert.ToInt32(ddlTochucchungnhan.SelectedValue); entity.iTrangthai = 0; int IDHoSo = HosodangkychungnhanBRL.Add(entity); GiaytonopkemhosoEntity oGiayTo = new GiaytonopkemhosoEntity(); oGiayTo.PK_iHosodangkychungnhanID = IDHoSo; for (int i = 0; i < cblHoSoCSNTKemtheo.Items.Count; i++) { oGiayTo.FK_iGiaytoID = Convert.ToInt32(cblHoSoCSNTKemtheo.Items[i].Value); oGiayTo.bTrangthai = cblHoSoCSNTKemtheo.Items[i].Selected; GiaytonopkemhosoBRL.Add(oGiayTo); } } catch(Exception ex) { lblLoi.Text = ex.Message ; } }
protected void btnLuuGiaytonopkem_Click(object sender, EventArgs e) { if (Session["iHosodangkyCSNT"] != null) { int PK_iHosodangkyCSNT = int.Parse(Session["iHosodangkyCSNT"].ToString()); List<GiaytonopkemhosoEntity> lstGiaytonopkem = GiaytonopkemhosoBRL.GetByPK_iHosodangkychungnhanID(PK_iHosodangkyCSNT); GiaytonopkemhosoEntity oGiaytoNopkem = null; foreach(ListItem chk in cblGiaytonopkem.Items) { oGiaytoNopkem = null; oGiaytoNopkem = lstGiaytonopkem.Find( delegate(GiaytonopkemhosoEntity oGiaytonopkemFound) { return oGiaytonopkemFound.FK_iGiaytoID.ToString().Equals(chk.Value); } ); if(oGiaytoNopkem == null) { if (chk.Selected) { GiaytonopkemhosoEntity oGiaytonopkemNew = new GiaytonopkemhosoEntity(); oGiaytonopkemNew.FK_iGiaytoID = int.Parse(chk.Value); oGiaytonopkemNew.PK_iHosodangkychungnhanID = PK_iHosodangkyCSNT; oGiaytonopkemNew.bTrangthai = true; GiaytonopkemhosoBRL.Add(oGiaytonopkemNew); } } else { if(!chk.Selected) { GiaytonopkemhosoBRL.Remove(oGiaytoNopkem.PK_iGiaytoguikemID); } lstGiaytonopkem.Remove(oGiaytoNopkem); //Loại bỏ phần tử đã tìm thấy để tối ưu } } lstGiaytonopkem = null; napCblGiaytonopkem(); lblThongbao.Text = "Lưu thành công!"; } else { Response.Redirect(ResolveUrl("~/adminx/Tochucchungnhan/Default.aspx?page=DanhsachCosonuoitrong")); } }