public static List <GeneralDataProviderItem> GetSelectedGridItems(RadGrid Grid, GeneralDataPage Page, Hashtable GridCheckedIds) { if (GridCheckedIds != null) { GeneralDataProviderItem GridItem = Page.GetGridProvider(Grid).GetDataProviderItem(Page.GetGridProvider(Grid).DataProvider); foreach (GridDataItem Itm in Grid.Items) { if (Itm.FindControl("CheckBox1") is CheckBox && (Itm.FindControl("CheckBox1") as CheckBox).Checked) { GridCheckedIds[Itm.KeyValues] = true; } else { GridCheckedIds.Remove(Itm.KeyValues); } } string filter = ""; foreach (DictionaryEntry KeyValue in GridCheckedIds) { string FilterPart = ""; if (KeyValue.Value is bool && (bool)KeyValue.Value) { FilterPart = "("; string[] Params = KeyValue.Key.ToString().TrimStart('{').TrimEnd('}').Split(','); foreach (string keys in Params) { if (FilterPart != "(") { FilterPart += " and "; } string[] NameValue = keys.Split(':'); FilterPart += "[" + NameValue[0] + "] = " + Page.Dao.ToSql(NameValue[1].Trim('\"'), GridItem.Fields[NameValue[0]].FieldType); } FilterPart += ")"; } if (FilterPart != "") { if (filter != "") { filter += " or "; } filter += FilterPart; } } Page.GetGridProvider(Grid).DataProvider.FiltroAtual = filter; } return(Page.GetGridProvider(Grid).DataProvider.SelectAllItems(true)); }
protected void PostB_Click(object sender, EventArgs e) { UpdateLB.Text = ""; var dataSet = FillDataSet(); With.Transaction((c, t) => { PriceRegionSettings.DataSource = dataSet; foreach (DataGridItem Itm in CostsDG.Items) { for (var i = 0; i <= dataSet.Tables[0].Rows.Count - 1; i++) { if (dataSet.Tables[0].Rows[i]["CostCode"].ToString() == ((HiddenField)Itm.FindControl("CostCode")).Value) { if (dataSet.Tables[0].Rows[i]["CostName"].ToString() != ((TextBox)(Itm.FindControl("CostName"))).Text) { dataSet.Tables[0].Rows[i]["CostName"] = ((TextBox)(Itm.FindControl("CostName"))).Text; } if (Convert.ToInt32(dataSet.Tables[0].Rows[i]["Enabled"]) != Convert.ToInt32(((CheckBox)(Itm.FindControl("Ena"))).Checked)) { dataSet.Tables[0].Rows[i]["Enabled"] = Convert.ToInt32(((CheckBox)(Itm.FindControl("Ena"))).Checked); } if (Convert.ToInt32(dataSet.Tables[0].Rows[i]["AgencyEnabled"]) != Convert.ToInt32(((CheckBox)(Itm.FindControl("Pub"))).Checked)) { dataSet.Tables[0].Rows[i]["AgencyEnabled"] = Convert.ToInt32(((CheckBox)(Itm.FindControl("Pub"))).Checked); } } } } var price = DbSession.Query <Price>().FirstOrDefault(p => p.Id == priceId); for (var i = 0; i < PriceRegionSettings.Rows.Count; i++) { dataSet.Tables["PriceRegionSettings"].Rows[i]["Enabled"] = ((CheckBox)PriceRegionSettings.Rows[i].FindControl("EnableCheck")).Checked; dataSet.Tables["PriceRegionSettings"].Rows[i]["UpCost"] = ((TextBox)PriceRegionSettings.Rows[i].FindControl("UpCostText")).Text; dataSet.Tables["PriceRegionSettings"].Rows[i]["MinReq"] = ((TextBox)PriceRegionSettings.Rows[i].FindControl("MinReqText")).Text; if (dataSet.Tables["PriceRegionSettings"].Rows[i]["BaseCost"].ToString() != ((DropDownList)PriceRegionSettings.Rows[i].FindControl("RegionalBaseCost")).SelectedValue) { dataSet.Tables["PriceRegionSettings"].Rows[i]["BaseCost"] = ((DropDownList)PriceRegionSettings.Rows[i].FindControl("RegionalBaseCost")).SelectedValue; } } var adapter = new MySqlDataAdapter("", c); adapter.UpdateCommand = new MySqlCommand("", c); var command = adapter.UpdateCommand; command.Parameters.Add(new MySqlParameter("?CostCode", MySqlDbType.Int32)); command.Parameters["?CostCode"].Direction = ParameterDirection.Input; command.Parameters["?CostCode"].SourceColumn = "CostCode"; command.Parameters["?CostCode"].SourceVersion = DataRowVersion.Current; command.Parameters.Add(new MySqlParameter("?CostName", MySqlDbType.VarChar)); command.Parameters["?CostName"].Direction = ParameterDirection.Input; command.Parameters["?CostName"].SourceColumn = "CostName"; command.Parameters["?CostName"].SourceVersion = DataRowVersion.Current; command.Parameters.Add(new MySqlParameter("?Enabled", MySqlDbType.Bit)); command.Parameters["?Enabled"].Direction = ParameterDirection.Input; command.Parameters["?Enabled"].SourceColumn = "Enabled"; command.Parameters["?Enabled"].SourceVersion = DataRowVersion.Current; command.Parameters.Add(new MySqlParameter("?AgencyEnabled", MySqlDbType.Bit)); command.Parameters["?AgencyEnabled"].Direction = ParameterDirection.Input; command.Parameters["?AgencyEnabled"].SourceColumn = "AgencyEnabled"; command.Parameters["?AgencyEnabled"].SourceVersion = DataRowVersion.Current; command.Parameters.AddWithValue("?Host", HttpContext.Current.Request.UserHostAddress); command.Parameters.AddWithValue("?UserName", SecurityContext.Administrator.UserName); command.CommandText = @" set @inHost = ?Host; set @inUser = ?UserName; UPDATE pricescosts SET CostName = ?CostName, Enabled = ?Enabled, AgencyEnabled = ?AgencyEnabled WHERE CostCode =?CostCode; "; adapter.Update(dataSet, "Costs"); command.Parameters.Clear(); command.CommandText = @" UPDATE PricesRegionalData SET UpCost = ?UpCost, MinReq = ?MinReq, Enabled = ?Enabled, BaseCost = ?BaseCost WHERE RowID = ?Id "; command.Parameters.Add("?UpCost", MySqlDbType.Decimal, 0, "UpCost"); command.Parameters.Add("?MinReq", MySqlDbType.Decimal, 0, "MinReq"); command.Parameters.Add("?Enabled", MySqlDbType.Bit, 0, "Enabled"); command.Parameters.Add("?Id", MySqlDbType.Int32, 0, "RowId"); command.Parameters.Add("?BaseCost", MySqlDbType.Decimal, 0, "BaseCost"); adapter.Update(dataSet, "PriceRegionSettings"); UpdateLB.Text = "Сохранено."; }); DbSession.SessionFactory.Evict(typeof(Price), priceId); PostDataToGrid(); }