/// <summary> /// /// </summary> /// <param name="idRule"></param> protected void FetchSubRuleOptions(int idRule) { this.hdParentRuleId.Value = idRule.ToString(); this.hdIsSubRule.Value = "true"; using (Subscriber.Proxy.SubscriberWebService da = this.CreateService()) { Subscriber.Proxy.SubRuleInfo rule = da.GetSubRule(idRule); this.grdRuleOptions.DataSource = rule.Options; this.grdRuleOptions.DataBind(); } }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void grdRuleOptions_ItemCommand(object sender, DataGridCommandEventArgs e) { int idRule; Int32.TryParse(this.hdParentRuleId.Value, out idRule); bool isSubRule; bool.TryParse(this.hdIsSubRule.Value, out isSubRule); if (e.CommandName == "Select") { //this.grdRuleOptions.EditItemIndex = e.Item.ItemIndex; //this.FetchRuleOptions(idRule); } else if (e.CommandName == "Update") { using (Subscriber.Proxy.SubscriberWebService da = this.CreateService()) { if (isSubRule) { Subscriber.Proxy.SubRuleInfo rule = da.GetSubRule(idRule); string name = ((TextBox)e.Item.FindControl("txtName")).Text; string value = ((TextBox)e.Item.FindControl("txtValue")).Text; List <Subscriber.Proxy.NameValuePair> pairs = new List <Subscriber.Proxy.NameValuePair>(rule.Options); Subscriber.Proxy.NameValuePair pair = pairs.Where(itm => itm.Name.ToLowerInvariant() == name.ToLowerInvariant()).FirstOrDefault(); if (pair == null) { pair = new Subscriber.Proxy.NameValuePair(); pairs.Add(pair); } pair.Name = name; pair.Value = value; rule.Options = pairs.ToArray(); rule = da.SaveSubRule(rule); this.grdRuleOptions.EditItemIndex = -1; this.FetchSubRuleOptions(idRule); } else { Subscriber.Proxy.RuleInfo rule = da.GetRule(idRule); string name = ((TextBox)e.Item.FindControl("txtName")).Text; string value = ((TextBox)e.Item.FindControl("txtValue")).Text; List <Subscriber.Proxy.NameValuePair> pairs = new List <Subscriber.Proxy.NameValuePair>(rule.Options); Subscriber.Proxy.NameValuePair pair = pairs.Where(itm => itm.Name.ToLowerInvariant() == name.ToLowerInvariant()).FirstOrDefault(); if (pair == null) { pair = new Subscriber.Proxy.NameValuePair(); pairs.Add(pair); } pair.Name = name; pair.Value = value; rule.Options = pairs.ToArray(); rule = da.SaveRule(rule); this.grdRuleOptions.EditItemIndex = -1; this.FetchRuleOptions(idRule); } } } else if (e.CommandName == "Cancel") { this.grdRuleOptions.EditItemIndex = -1; this.FetchRuleOptions(idRule); } else if (e.CommandName == "Delete") { using (Subscriber.Proxy.SubscriberWebService da = this.CreateService()) { if (isSubRule) { Subscriber.Proxy.SubRuleInfo rule = da.GetSubRule(idRule); List <Subscriber.Proxy.NameValuePair> pairs = new List <Subscriber.Proxy.NameValuePair>(rule.Options); pairs.RemoveAt(e.Item.ItemIndex); rule.Options = pairs.ToArray(); rule = da.SaveSubRule(rule); this.grdRuleOptions.EditItemIndex = -1; this.FetchSubRuleOptions(idRule); } else { Subscriber.Proxy.RuleInfo rule = da.GetRule(idRule); List <Subscriber.Proxy.NameValuePair> pairs = new List <Subscriber.Proxy.NameValuePair>(rule.Options); pairs.RemoveAt(e.Item.ItemIndex); rule.Options = pairs.ToArray(); rule = da.SaveRule(rule); this.grdRuleOptions.EditItemIndex = -1; this.FetchRuleOptions(idRule); } } } }
/// <summary> /// /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void grdSubRules_ItemCommand(object source, DataGridCommandEventArgs e) { Label lblId = (Label)e.Item.FindControl("lblId"); int id; Int32.TryParse(lblId.Text, out id); if (e.CommandName == "Select") { Label lblIdParentRule = (Label)e.Item.FindControl("lblIdParentRule"); this.grdSubRules.EditItemIndex = e.Item.ItemIndex; this.FetchSubRules(Convert.ToInt32(lblIdParentRule.Text)); this.FetchSubRuleOptions(id); this.FetchRuleHistory(id); } else if (e.CommandName == "Update") { Label lblIdParentRule = (Label)this.grdRules.SelectedItem.FindControl("lblId"); int idParentRule = Convert.ToInt32(lblIdParentRule.Text); Label lblIdInstance = (Label)this.grdInstances.SelectedItem.FindControl("lblId"); int idInstance = Convert.ToInt32(lblIdInstance.Text); using (Subscriber.Proxy.SubscriberWebService da = this.CreateService()) { Subscriber.Proxy.SubRuleInfo rule = null; if (id > 0) { rule = da.GetSubRule(id); } else { rule = new Subscriber.Proxy.SubRuleInfo(); rule.Id = id; rule.IdInstance = idInstance; rule.IdParentRule = idParentRule; rule.SubRuleName = ((TextBox)e.Item.FindControl("txtSubRuleName")).Text; } rule.RuleDescription = ((TextBox)e.Item.FindControl("txtRuleDescription")).Text; rule.Enabled = ((CheckBox)e.Item.FindControl("chkRuleEnabled")).Checked; rule = da.SaveSubRule(rule); } this.grdSubRules.EditItemIndex = -1; this.FetchSubRules(idParentRule); } else if (e.CommandName == "Cancel") { Label lblIdParentRule = (Label)this.grdRules.SelectedItem.FindControl("lblId"); int idParentRule = Convert.ToInt32(lblIdParentRule.Text); this.grdSubRules.EditItemIndex = -1; this.FetchSubRules(idParentRule); } else if (e.CommandName == "Delete") { Label lblIdParentRule = (Label)e.Item.FindControl("lblIdParentRule"); int idParentRule = Convert.ToInt32(lblIdParentRule.Text); using (Subscriber.Proxy.SubscriberWebService da = this.CreateService()) { da.DeleteRule(id); } this.grdSubRules.EditItemIndex = -1; this.FetchSubRules(idParentRule); } }