Ejemplo n.º 1
0
    public static int DeleteFiles(Tools.Tables tableName, int filesId)
    {
        using (SqlCommand com = new SqlCommand())
        {
            com.CommandText = $"Delete From " +
                              $"{tableName} " +
                              $"Where Id=@ProductsId";
            com.Parameters.Add("@ProductsId", SqlDbType.Int).Value = filesId;
            com.Connection = SqlConn;

            try
            {
                com.Connection.Open();
                return(com.ExecuteNonQuery());
            }
            catch (Exception er)
            {
                DALC.ErrorLog(string.Format("DALCA.DeleteFiles [{0}] catch error: {1}", tableName, er.Message));
                return(-1);
            }
            finally
            {
                com.Connection.Close();
                com.Connection.Dispose();
            }
        }
    }
Ejemplo n.º 2
0
    public static void ControlsBind(this Control Panel, Dictionary <string, object> FilterDictionary, Tools.Tables TableName, string addSessionName = "", bool ClearSession = false)
    {
        string SessionName = $"{TableName._ToString()}{addSessionName}";

        if (ClearSession)
        {
            HttpContext.Current.Session[SessionName] = null;
        }

        if (HttpContext.Current.Session[SessionName] != null)
        {
            if (FilterDictionary.Count < 1)
            {
                FilterDictionary = (Dictionary <string, object>)HttpContext.Current.Session[SessionName];
            }
            foreach (Control item in Panel.Controls)
            {
                if (item.HasControls())
                {
                    ControlsBind(item, FilterDictionary, TableName, addSessionName);
                }

                try
                {
                    if (item is TextBox)
                    {
                        TextBox Txt = item as TextBox;
                        Txt.Text = FilterDictionary[Txt.ID]._ToString();
                    }
                    else if (item is DropDownList)
                    {
                        DropDownList DList = item as DropDownList;
                        DList.SelectedValue = FilterDictionary[DList.ID]._ToString();
                    }
                    else if (item is ListBox)
                    {
                        ListBox LstBx = item as ListBox;
                        for (int i = 0; i < LstBx.Items.Count; i++)
                        {
                            ListItem Item = LstBx.Items[i];
                            if (FilterDictionary[LstBx.ID]._ToString().IndexOf(Item.Value) > -1)
                            {
                                Item.Selected = true;
                            }
                        }
                    }
                    else if (item is CheckBox)
                    {
                        CheckBox Check = item as CheckBox;
                        Check.Checked = (bool)FilterDictionary[Check.ID];
                    }
                }
                catch
                {
                    HttpContext.Current.Session[SessionName] = null;
                    FilterDictionary.Clear();
                    ControlsBind(Panel, FilterDictionary, TableName);
                }
            }
        }
        else
        {
            foreach (Control item in Panel.Controls)
            {
                if (item.HasControls())
                {
                    ControlsBind(item, FilterDictionary, TableName, addSessionName, true);
                }

                if (item is TextBox)
                {
                    TextBox Txt = item as TextBox;
                    FilterDictionary.Add(Txt.ID, Txt.Text);
                }
                else if (item is DropDownList)
                {
                    DropDownList DList = item as DropDownList;
                    FilterDictionary.Add(DList.ID, DList.SelectedValue);
                }
                else if (item is ListBox)
                {
                    ListBox       LstBx  = item as ListBox;
                    StringBuilder Values = new StringBuilder();
                    for (int i = 0; i < LstBx.Items.Count; i++)
                    {
                        ListItem Item = LstBx.Items[i];
                        if (Item.Selected)
                        {
                            Values.Append(Item.Value + ",");
                        }
                    }
                    FilterDictionary.Add(LstBx.ID, Values._ToString().Trim(','));
                }
                else if (item is CheckBox)
                {
                    CheckBox Check = item as CheckBox;
                    FilterDictionary.Add(Check.ID, Check.Checked);
                }
            }
            HttpContext.Current.Session[SessionName] = FilterDictionary;
        }
    }