protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e) { if (e.Values["IncomingFactureTypeID"].ToString() != IncomingFactureType.GetByCode(IncomingFactureType.ZA_POLISI).ID.ToString()) { e.Values["InsuranceCompanyID"] = null; } e.Values["UserID"] = this.PageUser.ID; e.Values["BranchID"] = this.PageBranch.ID; }
protected void dvDataSource_Updated(object sender, ObjectDataSourceStatusEventArgs e) { object o = e.ReturnValue; IncomingFacture inFac = (IncomingFacture)o; if (inFac.IncomingFactureTypeID == IncomingFactureType.GetByCode(IncomingFactureType.ZA_POLISI).ID) { List <IncomingFacturePolicyItem> lstOld = IncomingFacturePolicyItem.GetByIncomingFactureID(inFac.ID); foreach (IncomingFacturePolicyItem ifpi in lstOld) { ifpi.IsActive = false; IncomingFacturePolicyItem.Table.Context.SubmitChanges(); } GridView gvNewPolicies = (GridView)DetailsView1.FindControl("gvNewPolicies"); List <FactureInfo> lastFactureInfos = listFactureInfos; GridViewRowCollection displayedRows = gvNewPolicies.Rows; foreach (GridViewRow gvRow in displayedRows) { CheckBox cbIsForFacturing = gvRow.FindControl("cbIsForFacturing") as CheckBox; int factureInfoID = Convert.ToInt32(gvNewPolicies.DataKeys[gvRow.RowIndex].Value); FactureInfo fi = lastFactureInfos.Where(f => f.ID == factureInfoID).SingleOrDefault(); fi.IsForFacturing = cbIsForFacturing.Checked; } listFactureInfos = lastFactureInfos; List <FactureInfo> listFactureInfo = listFactureInfos.Where(c => c.IsForFacturing == true).ToList(); foreach (FactureInfo fi in listFactureInfo) { IncomingFacturePolicyItem ifpi = new IncomingFacturePolicyItem(); ifpi.IncomingFactureID = inFac.ID; ifpi.PolicyItemID = fi.ID; ifpi.IsActive = true; ifpi.Insert(); PolicyItem pi = PolicyItem.Get(fi.ID); pi.PolicyIncomeFactureStatusID = PolicyIncomeFactureStatuse.GetByCode(PolicyIncomeFactureStatuse.CELOSNO_FAKTURIRANA).ID; PolicyItem.Table.Context.SubmitChanges(); } } }