private bool IsEqual(ProductPriceOverviewModel item1, ProductPriceOverviewModel item2) { PropertyInfo[] properties1 = item1.GetType().GetProperties(); PropertyInfo[] properties2 = item2.GetType().GetProperties(); object value1; object value2; Type type = item1.GetType(); bool isEqual = false; for (int i = 0; i < properties1.Length; i++) { value1 = properties1[i].GetValue(item1, null); value2 = properties2[i].GetValue(item2, null); if (value1 != null && value2 != null) { isEqual = value1.Equals(value2); } if (!isEqual) { break; } } return(isEqual); }
protected void gvPrices_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { var price = (ProductPriceOverviewModel)e.Row.DataItem; ProductPriceOverviewModel chosenPrice = null; if (ExistInChosenPrices(price)) { chosenPrice = ChosenPrices.Find(delegate(ProductPriceOverviewModel item) { return(item.Id == price.Id); }); } CheckBox cb = e.Row.FindControl("cbChosen") as CheckBox; if (chosenPrice != null) { TextBox txtWeight = e.Row.FindControl("txtWeight") as TextBox; TextBox txtPrice = e.Row.FindControl("txtPrice") as TextBox; TextBox txtStock = e.Row.FindControl("txtStock") as TextBox; TextBox txtBarcode = e.Row.FindControl("txtBarcode") as TextBox; cb.Checked = true; txtWeight.Text = chosenPrice.Weight.ToString(); txtPrice.Text = AdminStoreUtility.GetFormattedPrice(chosenPrice.Price, CurrencySettings.PrimaryStoreCurrencyCode, CurrencyType.None); txtStock.Text = chosenPrice.Stock.ToString(); txtBarcode.Text = chosenPrice.Barcode; } } }
protected void gvPrices_PreRender(object sender, EventArgs e) { if (gvPrices.TopPagerRow != null) { gvPrices.TopPagerRow.Visible = true; ((TextBox)gvPrices.HeaderRow.FindControl("txtFilterProductId")).Text = GetStringState(PRODUCT_ID_FILTER); ((TextBox)gvPrices.HeaderRow.FindControl("txtFilterName")).Text = GetStringState(NAME_FILTER); ((DropDownList)gvPrices.HeaderRow.FindControl("ddlStatus")).Items.FindByValue(GetStringState(STATUS_FILTER)).Selected = true; ((TextBox)gvPrices.HeaderRow.FindControl("txtFilterBarcode")).Text = GetStringState(BARCODE_FILTER); } for (int i = 0; i < gvPrices.Rows.Count; i++) { CheckBox cb = gvPrices.Rows[i].FindControl("cbChosen") as CheckBox; ProductPriceOverviewModel price = BuildPrice(Convert.ToInt32(gvPrices.DataKeys[i].Value), gvPrices.Rows[i]); if (cb != null) { SetChosenPrices(price, cb.Checked); } } if (gvPrices.Rows.Count == 1 && (int)gvPrices.DataKeys[0].Value == 0 && gvPrices.TopPagerRow != null) { gvPrices.TopPagerRow.FindControl(PH_RECORD_FOUND).Visible = false; gvPrices.TopPagerRow.FindControl(PH_RECORD_NOT_FOUND).Visible = true; } }
private bool ExistInNotChosenPrices(ProductPriceOverviewModel price) { bool exist = false; for (int j = 0; j < NotChosenPrices.Count; j++) { exist = IsEqual(NotChosenPrices[j], price); if (!exist) { exist = NotChosenPrices[j].Id == price.Id; } if (exist) { break; } } return(exist); }
private void SetChosenPrices(ProductPriceOverviewModel price, bool chosen) { if (price != null) { if (chosen) { if (ExistInChosenPrices(price)) { ChosenPrices.RemoveAll(delegate(ProductPriceOverviewModel arg) { return(arg.Id == price.Id); }); } ChosenPrices.Add(price); NotChosenPrices.RemoveAll(delegate(ProductPriceOverviewModel arg) { return(arg.Id == price.Id); }); } else { ChosenPrices.RemoveAll(delegate(ProductPriceOverviewModel arg) { return(arg.Id == price.Id); }); if (ExistInNotChosenPrices(price)) { NotChosenPrices.RemoveAll(delegate(ProductPriceOverviewModel arg) { return(arg.Id == price.Id); }); } NotChosenPrices.Add(price); } } }