protected void btnAddFabric_Click(object sender, EventArgs e) { ViewState["populateaddNewNote"] = false; int qid = int.Parse(this.ddlFabric.SelectedValue); //int.Parse(((System.Web.UI.WebControls.LinkButton)(sender)).Attributes["qid"].ToString()); if (qid > 0) { // Hide selected fabric //PRW ((System.Web.UI.WebControls.LinkButton)sender).Parent.Parent.Visible = false; FabricCodeBO objFabric = new FabricCodeBO(this.ObjContext); objFabric.ID = qid; objFabric.GetObject(); // Add selected fabric this.FabricCodesWhereThisIsPattern.Add(objFabric); // Populate active pattern fabrics this.PopulatePatternFabrics(); this.ProcessForm(qid); this.PopulatePatternFabrics(); this.PopulateFabrics(); } ViewState["PopulatePatern"] = false; ViewState["PopulateFabric"] = false; }
/// <summary> /// Process the page data. /// </summary> private void ProcessForm(int fabricID, bool isDelete) { try { using (TransactionScope ts = new TransactionScope()) { FabricCodeBO objFabricCode = new FabricCodeBO(this.ObjContext); if (fabricID > 0) { objFabricCode.ID = fabricID; objFabricCode.GetObject(); } if (isDelete) { objFabricCode.Delete(); } else { objFabricCode.Code = this.txtFabricCode.Text; objFabricCode.Name = this.txtCombinedName.Text; objFabricCode.NickName = (!String.IsNullOrEmpty(this.txtCombinedNickName.Text)) ? this.txtCombinedNickName.Text : string.Empty; objFabricCode.IsActive = (this.chkCombinedIsActive.Checked) ? true : false; objFabricCode.IsLiningFabric = false; objFabricCode.IsPure = false; objFabricCode.Country = 14; if (fabricID == 0) { objFabricCode.Add(); } } this.ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { // Log the error IndicoLogging.log.Error("Error occured while Saving Fabric", ex); } }
protected void dgvAddEditFabrics_ItemDataBound(object sender, DataGridItemEventArgs e) { DataGridItem item = e.Item; if (item.ItemIndex > -1 && item.DataItem is KeyValuePair <int, KeyValuePair <int, string> > ) // KeyValuePair<Tuple<int, int>, int>) { KeyValuePair <int, KeyValuePair <int, string> > kv = (KeyValuePair <int, KeyValuePair <int, string> >)item.DataItem; Literal litID = (Literal)item.FindControl("litID"); Literal litFabricTypeID = (Literal)item.FindControl("litFabricTypeID"); Literal litFabricType = (Literal)item.FindControl("litFabricType"); Literal litCode = (Literal)item.FindControl("litCode"); Literal litFabricNickName = (Literal)item.FindControl("litFabricNickName"); Literal litFabricSupplier = (Literal)item.FindControl("litFabricSupplier"); TextBox txtWhere = (TextBox)item.FindControl("txtWhere"); litFabricTypeID.Text = kv.Key.ToString(); int value = kv.Key; FabricType type = (FabricType)value; litFabricType.Text = type.ToString(); FabricCodeBO objFC = new FabricCodeBO(); objFC.ID = kv.Value.Key; objFC.GetObject(); txtWhere.Text = kv.Value.Value; //litVFID.Text = "0"; litID.Text = objFC.ID.ToString(); litCode.Text = objFC.Code; litFabricNickName.Text = objFC.NickName; litFabricSupplier.Text = (objFC.Supplier.HasValue && objFC.Supplier.Value > 0) ? objFC.objSupplier.Name : string.Empty; // ddlfabricCodeType.Items.FindByValue(kv.Key.Item2.ToString()).Selected = true; //} } }
private void ProcessForm(int fabricID, bool isDelete, bool isPure) { try { using (TransactionScope ts = new TransactionScope()) { FabricCodeBO objFabricCode = new FabricCodeBO(this.ObjContext); if (fabricID > 0) { objFabricCode.ID = fabricID; objFabricCode.GetObject(); } if (isDelete) { objFabricCode.Delete(); } else { //if (isPure) //{ objFabricCode.Code = this.txtCode.Text; objFabricCode.Name = this.txtName.Text; objFabricCode.NickName = (!String.IsNullOrEmpty(this.txtNickName.Text)) ? this.txtNickName.Text : string.Empty; objFabricCode.IsActive = (this.chbIsActive.Checked) ? true : false; objFabricCode.IsLiningFabric = (this.chkIsLining.Checked) ? true : false; objFabricCode.IsPure = (this.chbIsPure.Checked) ? true : false; objFabricCode.Supplier = int.Parse(this.ddlSupplier.SelectedValue); objFabricCode.Material = (!String.IsNullOrEmpty(this.txtMaterial.Text)) ? this.txtMaterial.Text : string.Empty; objFabricCode.GSM = (!String.IsNullOrEmpty(this.txtGsm.Text)) ? this.txtGsm.Text : string.Empty; objFabricCode.DenierCount = (!String.IsNullOrEmpty(this.txtDenierCount.Text)) ? this.txtDenierCount.Text : string.Empty; objFabricCode.Filaments = (!String.IsNullOrEmpty(this.txtFilaments.Text)) ? this.txtFilaments.Text : string.Empty; objFabricCode.SerialOrder = (!String.IsNullOrEmpty(this.txtSerialOrder.Text)) ? this.txtSerialOrder.Text : string.Empty; objFabricCode.FabricPrice = (!String.IsNullOrEmpty(this.txtFabricPrice.Text)) ? decimal.Parse(this.txtFabricPrice.Text) : decimal.Parse("0.0"); objFabricCode.Fabricwidth = (!String.IsNullOrEmpty(this.txtFabricWidth.Text)) ? this.txtFabricWidth.Text : string.Empty; objFabricCode.Unit = int.Parse(this.ddlUnit.SelectedValue); objFabricCode.FabricColor = int.Parse(this.ddlFabricColor.SelectedValue); objFabricCode.Country = int.Parse(this.ddlCountry.SelectedValue); if (int.Parse(this.ddlLandedCurrency.SelectedValue) > 0) { objFabricCode.LandedCurrency = int.Parse(this.ddlLandedCurrency.SelectedValue); } //} //else //{ // objFabricCode.Code = this.txtFabricCode.Text; // objFabricCode.Name = this.txtCombinedName.Text; // objFabricCode.NickName = (!String.IsNullOrEmpty(this.txtCombinedNickName.Text)) ? this.txtCombinedNickName.Text : string.Empty; // objFabricCode.IsActive = (this.chkCombinedIsActive.Checked) ? true : false; // objFabricCode.IsLiningFabric = (this.chkIsLining.Checked) ? true : false; // objFabricCode.IsPure = false; // objFabricCode.Country = 14; //} if (fabricID == 0) { objFabricCode.Add(); } } this.ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { // Log the error IndicoLogging.log.Error("Error occured while Saving Fabric", ex); } }
private List <KeyValuePair <int, KeyValuePair <int, string> > > GetFilteredFabricData(int fabricID, int typeID, bool isDeleted) { List <KeyValuePair <int, KeyValuePair <int, string> > > lst = new List <KeyValuePair <int, KeyValuePair <int, string> > >(); foreach (DataGridItem item in this.dgvAddEditFabrics.Items) { Literal litID = (Literal)item.FindControl("litID"); Literal litFabricTypeID = (Literal)item.FindControl("litFabricTypeID"); Literal litFabricType = (Literal)item.FindControl("litFabricType"); TextBox txtWhere = (TextBox)item.FindControl("txtWhere"); lst.Add(new KeyValuePair <int, KeyValuePair <int, string> >(int.Parse(litFabricTypeID.Text), new KeyValuePair <int, string>(int.Parse(litID.Text), txtWhere.Text))); } if (fabricID > 0) // Add, Delete { if (isDeleted) { KeyValuePair <int, KeyValuePair <int, string> > removeFabric = lst.Where(m => m.Key == typeID && m.Value.Key == fabricID).SingleOrDefault(); lst.Remove(removeFabric); } else { lst.Add(new KeyValuePair <int, KeyValuePair <int, string> >(typeID, new KeyValuePair <int, string>(fabricID, ""))); } } else // Page edit mode to load all data { if (this.QueryID > 0) { FabricCodeBO objFabric = new FabricCodeBO(); objFabric.ID = QueryID; objFabric.GetObject(); this.txtCombinedName.Text = objFabric.Name; this.txtCombinedNickName.Text = objFabric.NickName; this.chkCombinedIsActive.Checked = objFabric.IsActive; try { string[] codes = objFabric.Code.Split('+'); //string[] wheres = string.IsNullOrEmpty(objVL.Where) ? new string[0] : objVL.Where.Split(','); List <KeyValuePair <int, string> > lstWheres = new List <KeyValuePair <int, string> >(); //foreach (string whereText in wheres) //{ // lstWheres.Add(new KeyValuePair<int, string>(int.Parse(whereText.Split('-')[0]), whereText.Split('-')[1])); //} List <FabricCodeBO> lstFabricCodes = (List <FabricCodeBO>)Session["ListFabricCodes"]; int fabricPosition = 0; foreach (string code in codes) { FabricCodeBO objFabCode = lstFabricCodes.Where(m => m.Code == code).Single(); string whereText = lstWheres.Where(m => m.Key == objFabCode.ID).SingleOrDefault().Value; if (++fabricPosition == 1) { lst.Add(new KeyValuePair <int, KeyValuePair <int, string> >((int)FabricType.Main, new KeyValuePair <int, string>(objFabCode.ID, whereText))); } else if (objFabCode.IsLiningFabric) { lst.Add(new KeyValuePair <int, KeyValuePair <int, string> >((int)FabricType.Lining, new KeyValuePair <int, string>(objFabCode.ID, whereText))); } else { lst.Add(new KeyValuePair <int, KeyValuePair <int, string> >((int)FabricType.Secondary, new KeyValuePair <int, string>(objFabCode.ID, whereText))); } } } catch (Exception ex) { } } } Session["CombinedFabrics"] = lst; return(lst); }
private void PopulateFabricName() { string mainFabName = string.Empty; string secondaryFabName = string.Empty; string liningFabName = string.Empty; string combinedName = string.Empty; string combinedNickName = string.Empty; foreach (DataGridItem item in this.dgvAddEditFabrics.Items) { Literal litID = (Literal)item.FindControl("litID"); Literal litFabricTypeID = (Literal)item.FindControl("litFabricTypeID"); FabricCodeBO objFab = new FabricCodeBO(); objFab.ID = int.Parse(litID.Text); objFab.GetObject(); if (int.Parse(litFabricTypeID.Text) == 0) { mainFabName = objFab.Code; } else if (objFab.IsLiningFabric) { liningFabName += objFab.Code + "+"; } else { secondaryFabName += objFab.Code + "+"; } combinedName += objFab.Name + " + "; combinedNickName += objFab.NickName + " + "; } liningFabName = string.IsNullOrEmpty(liningFabName) ? "" : "+" + liningFabName.Remove(liningFabName.Length - 1, 1); secondaryFabName = string.IsNullOrEmpty(secondaryFabName) ? "" : "+" + secondaryFabName.Remove(secondaryFabName.Length - 1, 1); combinedName = string.IsNullOrEmpty(combinedName) ? "" : combinedName.Remove(combinedName.Length - 3, 3); combinedNickName = string.IsNullOrEmpty(combinedNickName) ? "" : combinedNickName.Remove(combinedNickName.Length - 3, 3); string selectedFabric = mainFabName + secondaryFabName + liningFabName; this.txtFabricCode.Text = selectedFabric; this.txtCombinedName.Text = combinedName; this.txtCombinedNickName.Text = combinedNickName; List <FabricCodeBO> lstFabricCodes = (List <FabricCodeBO>)Session["ListFabricCodes"]; if (!string.IsNullOrEmpty(selectedFabric) && lstFabricCodes != null) { try { lstFabricCodes = lstFabricCodes.Where(m => m.Code == selectedFabric).ToList(); if (lstFabricCodes.Any()) { if (this.QueryID == 0 || (this.QueryID > 0 && !lstFabricCodes.Select(m => m.ID).Contains(this.QueryID))) { CustomValidator cv = new CustomValidator(); cv.IsValid = false; cv.ValidationGroup = "valCombined"; cv.ErrorMessage = "Fabric Code exists in the system."; Page.Validators.Add(cv); } } } catch (Exception ex) { //lblVLFabricErrorText.Text = "The fabric combination selected, does not exist in Indiman Price List. Please contact Indiman administrator to include in fabric combination list."; } } }