protected void chkCond_OnCheckedChanged(object sender, EventArgs e) { lblMessage_Condiment.Text = ""; CheckBox chk = (CheckBox)sender; if (chk.Checked) { ListViewItem item = (ListViewItem)chk.Parent; HiddenField hf = (HiddenField)item.FindControl("hf_CondObject"); CCondiment cond = JsonConvert.DeserializeObject <CCondiment>(hf.Value); if (!cond.isEmpty) { ApplicationSession.SalesMaster.CollectionSalesDetail().SelectedItem().Condiments.Add(cond); List <CCondiment> lst = ApplicationSession.SalesMaster.CollectionSalesDetail().SelectedItem().Condiments; lvwModalItemCond.DataSource = lst; lvwModalItemCond.DataBind(); chk.Enabled = false; ShowModalDialog_Condiment(); } } }
protected void lvwModalItemCond_ItemDataBound(object sender, ListViewItemEventArgs e) { using (ListViewDataItem item = (ListViewDataItem)e.Item) { if (item != null) { HiddenField hf = (HiddenField)item.FindControl("hf_CondObject"); CCondiment cond = (CCondiment)item.DataItem; string sJson = JsonConvert.SerializeObject(cond); hf.Value = sJson; } } }
//old coding -just for reference protected void chkCond_OnCheckedChanged1(object sender, EventArgs e) { CheckBox chk = (CheckBox)sender; ListViewItem item0 = (ListViewItem)chk.Parent.Parent; HiddenField hf0 = (HiddenField)item0.FindControl("hf_CondObject"); CCondiment cond0 = JsonConvert.DeserializeObject <CCondiment>(hf0.Value); if (!cond0.isEmpty) { bool blnFound = false; foreach (ListViewItem item1 in lvwItemCond.Items) { HiddenField hf1 = (HiddenField)item1.FindControl("hf_CondObject"); CCondiment cond1 = (CCondiment)JsonConvert.DeserializeObject <CCondiment>(hf1.Value); if (!cond1.isEmpty) { if (cond0.ID == cond1.ID) { blnFound = true; if (!chk.Checked) { lvwItemCond.Items.RemoveAt(item1.DisplayIndex); ApplicationSession.SalesMaster.CollectionSalesDetail().SelectedItem().Condiments.Remove(cond1); } break; } } } if (!blnFound) { if (chk.Checked) { ApplicationSession.SalesMaster.CollectionSalesDetail().SelectedItem().Condiments.Add(cond0); List <CCondiment> lst = ApplicationSession.SalesMaster.CollectionSalesDetail().SelectedItem().Condiments; lvwItemCond.DataSource = lst; lvwItemCond.DataBind(); chk.Enabled = false; } } } ShowModalPopupExtender_Condiment(); }
protected void lvwCondiment_ItemDataBound(object sender, ListViewItemEventArgs e) { using (ListViewDataItem item = (ListViewDataItem)e.Item) { if (item != null) { HiddenField hf = (HiddenField)item.FindControl("hf_CondObject"); CCondiment cond = (CCondiment)item.DataItem; string sJson = JsonConvert.SerializeObject(cond); hf.Value = sJson; CheckBox chk = (CheckBox)item.FindControl("chkCond"); bool blnPicked = IsThisCondPicked(cond.ID); chk.Checked = blnPicked; chk.Enabled = !blnPicked; } } }
protected void btnDeleteItemCond_Click(object sender, EventArgs e) { HtmlButton btn = (HtmlButton)sender; ListViewItem item0 = (ListViewItem)btn.Parent; HiddenField hf0 = (HiddenField)item0.FindControl("hf_CondObject"); CCondiment cond0 = JsonConvert.DeserializeObject <CCondiment>(hf0.Value); if (!cond0.isEmpty) { ApplicationSession.SalesMaster.CollectionSalesDetail().SelectedItem().RemoveCondiment(cond0.ID); List <CCondiment> lst = ApplicationSession.SalesMaster.CollectionSalesDetail().SelectedItem().Condiments; lvwModalItemCond.DataSource = lst; lvwModalItemCond.DataBind(); foreach (ListViewDataItem item1 in lvwModalCondGroup.Items) { HiddenField hf1 = (HiddenField)item1.FindControl("hf_CGObject"); CCondGroup cg = JsonConvert.DeserializeObject <CCondGroup>(hf1.Value); if (cg != null) { if (cond0.CondGroupID == cg.ID) { ListView lvw = (ListView)item1.FindControl("lvwCondiment"); foreach (ListViewDataItem item2 in lvw.Items) { HiddenField hf2 = (HiddenField)item2.FindControl("hf_CondObject"); CCondiment cond2 = JsonConvert.DeserializeObject <CCondiment>(hf2.Value); if (cond2.ID == cond0.ID) { CheckBox chk = (CheckBox)item2.FindControl("chkCond"); chk.Checked = false; chk.Enabled = true; break; } } break; } } } ShowModalDialog_Condiment(); } }