private void DeleteAttribute(int id) { //NNM if (id > 0) { try { using (TransactionScope ts = new TransactionScope()) { ItemAttributeBO objItemAttribute = new ItemAttributeBO(this.ObjContext); objItemAttribute.ID = id; objItemAttribute.GetObject(); objItemAttribute.Delete(); this.ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while Deleting Attribute From ViewItemAttribute.aspx", ex); } } }
private void PopulateSubAttributes(bool isNewRecord = false, int parent = 0, int item = 0, int pageIndex = 0, int editIndex = -1) { if (this.IsNotRefresh) { this.dgAddEditSubItemAttributes.CurrentPageIndex = pageIndex; this.dgAddEditSubItemAttributes.EditItemIndex = editIndex; List <ItemAttributeBO> lstSubAttributes = (new ItemAttributeBO()).SearchObjects().Where(o => o.Parent == parent && o.Item == item && o.Parent > 0).ToList(); if (isNewRecord || lstSubAttributes.Count == 0) { ItemAttributeBO objSub = new ItemAttributeBO(); objSub.Parent = parent; objSub.Item = item; objSub.Name = string.Empty; objSub.Description = string.Empty; lstSubAttributes.Insert(0, objSub); if (dgAddEditSubItemAttributes.CurrentPageIndex > Math.Floor((double)(lstSubAttributes.Count / dgAddEditSubItemAttributes.PageSize))) { dgAddEditSubItemAttributes.CurrentPageIndex = Convert.ToInt32(Math.Floor((double)(lstSubAttributes.Count / dgAddEditSubItemAttributes.PageSize))); } this.dgAddEditSubItemAttributes.EditItemIndex = 0; } this.dgAddEditSubItemAttributes.DataSource = lstSubAttributes; this.dgAddEditSubItemAttributes.DataBind(); ViewState["IsSubAttribute"] = true; ViewState["IsPageValied"] = true; } }
protected void dgAddEditSubItemAttributes_ItemDataBound(object sender, DataGridItemEventArgs e) { DataGridItem item = e.Item; if ((item.ItemIndex > -1 && item.DataItem is ItemAttributeBO) && (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)) { ItemAttributeBO objSubItemAttribute = (ItemAttributeBO)item.DataItem; bool canDelete = (objSubItemAttribute.PatternItemAttributeSubsWhereThisIsItemAttribute.Count == 0 || objSubItemAttribute.ItemAttributesWhereThisIsParent.Count == 0) ? true : false; Literal litID = (Literal)item.FindControl("litID"); litID.Text = objSubItemAttribute.ID.ToString(); Literal litAttribute = (Literal)item.FindControl("litAttribute"); litAttribute.Text = objSubItemAttribute.Name.ToString(); Literal litDescription = (Literal)item.FindControl("litDescription"); litDescription.Text = (!string.IsNullOrEmpty(objSubItemAttribute.Description)) ? objSubItemAttribute.Description : string.Empty; LinkButton linkEdit = (LinkButton)item.FindControl("linkEdit"); linkEdit.Attributes.Add("qid", objSubItemAttribute.ID.ToString()); HyperLink linkDelete = (HyperLink)item.FindControl("linkDelete"); linkDelete.Attributes.Add("qid", objSubItemAttribute.ID.ToString()); linkDelete.Visible = canDelete; } else if ((item.ItemIndex > -1 && item.DataItem is ItemAttributeBO) && (item.ItemType == ListItemType.EditItem)) { ItemAttributeBO objSubItemAttribute = (ItemAttributeBO)item.DataItem; Literal litID = (Literal)item.FindControl("litID"); litID.Text = objSubItemAttribute.ID.ToString(); TextBox txtAttribute = (TextBox)item.FindControl("txtAttribute"); txtAttribute.Text = objSubItemAttribute.Name.ToString(); this.hdnAttributeName.Value = txtAttribute.Text; TextBox txtDescription = (TextBox)item.FindControl("txtDescription"); txtDescription.Text = (!string.IsNullOrEmpty(objSubItemAttribute.Description)) ? objSubItemAttribute.Description : string.Empty; this.hdnAttributeDescription.Value = txtDescription.Text; LinkButton linkSave = (LinkButton)item.FindControl("linkSave"); linkSave.Attributes.Add("qid", objSubItemAttribute.ID.ToString()); linkSave.CommandName = (!string.IsNullOrEmpty(this.hdnAttributeName.Value) || (!string.IsNullOrEmpty(this.hdnAttributeDescription.Value))) ? "Update" : "Save"; } }
private void ProcessForm(bool isNew = false, bool isSub = false) { //NNM try { using (TransactionScope ts = new TransactionScope()) { ItemAttributeBO objItemAttribute = new ItemAttributeBO(this.ObjContext); if ((!isNew) && (int.Parse(this.hdnSelectedAttributeID.Value) > 0)) { objItemAttribute.ID = int.Parse(this.hdnSelectedAttributeID.Value); objItemAttribute.GetObject(); } if (isSub) { objItemAttribute.Parent = int.Parse(this.hdnParent.Value); } objItemAttribute.Name = (isSub == false) ? this.txtAttributeName.Text : this.hdnAttributeName.Value; objItemAttribute.Description = (isSub == false) ? this.txtDescription.Text : this.hdnAttributeDescription.Value; objItemAttribute.Item = (isSub == false) ? int.Parse(this.ddlItem.SelectedItem.Value) : int.Parse(this.hdnItem.Value); if (isNew) { objItemAttribute.Add(); } this.ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { // Log the error IndicoLogging.log.Error("Error occured while Adding or Updaing Attributes from ViewItemAttributes.aspx page", ex); } }
protected void lbtnEditSUbAttributes_Click(object sender, EventArgs e) { if (this.IsNotRefresh) { int id = int.Parse(((System.Web.UI.WebControls.WebControl)(sender)).Attributes["qid"].ToString()); int item = int.Parse(((System.Web.UI.WebControls.WebControl)(sender)).Attributes["item"].ToString()); if (id > 0 && item > 0) { ItemAttributeBO objItemAttribute = new ItemAttributeBO(); objItemAttribute.ID = id; objItemAttribute.GetObject(); this.hdnParent.Value = id.ToString(); this.hdnItem.Value = item.ToString(); this.txtParent.Text = objItemAttribute.Name; this.PopulateSubAttributes(false, id, item); ViewState["IsSubAttribute"] = true; } } }