/// <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 grdRules_ItemCommand(object source, DataGridCommandEventArgs e) { Label lblId = (Label)e.Item.FindControl("lblId"); int id; Int32.TryParse(lblId.Text, out id); Label lblIdInstance = (Label)e.Item.FindControl("lblIdInstance"); int idInstance; Int32.TryParse(lblIdInstance.Text, out idInstance); if (e.CommandName == "Select") { this.grdRules.EditItemIndex = e.Item.ItemIndex; this.FetchRules(idInstance); this.FetchSubRules(id); this.FetchRuleOptions(id); this.FetchRuleHistory(id); } else if (e.CommandName == "Update") { using (Subscriber.Proxy.SubscriberWebService da = this.CreateService()) { Subscriber.Proxy.RuleInfo rule = null; if (id > 0) { rule = da.GetRule(id); } else { lblIdInstance = (Label)this.grdInstances.SelectedItem.FindControl("lblId"); Int32.TryParse(lblIdInstance.Text, out idInstance); rule = new Subscriber.Proxy.RuleInfo(); rule.Id = id; rule.RuleName = ((TextBox)e.Item.FindControl("txtRuleName")).Text; rule.IdInstance = idInstance; } rule.RuleDescription = ((TextBox)e.Item.FindControl("txtRuleDescription")).Text; rule.Enabled = ((CheckBox)e.Item.FindControl("chkRuleEnabled")).Checked; rule.RuleClassFullName = ((TextBox)e.Item.FindControl("txtRuleClassFullName")).Text; rule = da.SaveRule(rule); } this.grdRules.EditItemIndex = -1; this.FetchRules(idInstance); } else if (e.CommandName == "Cancel") { this.grdRules.EditItemIndex = -1; this.FetchRules(idInstance); } else if (e.CommandName == "Delete") { using (Subscriber.Proxy.SubscriberWebService da = this.CreateService()) { da.DeleteRule(id); this.grdRules.EditItemIndex = -1; lblIdInstance = (Label)this.grdInstances.SelectedItem.FindControl("lblId"); Int32.TryParse(lblIdInstance.Text, out idInstance); this.FetchRules(idInstance); } } }