private Salhead_repo Modify_data_allocation()
        {
            var gdata = new Salhead_repo {
                _id = int.Parse(salheadid.SelectedValue)
            };

            cmd.CommandText = "SELECT salhead_code,salhead_name,salhead_group_id,salhead_formula,salhead_add_to_salinfo,salhead_start_date FROM salary_head WHERE salhead_id = " + gdata._id + ";";
            _sql.Con_switch(con);
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                gdata._code      = reader["salhead_code"].ToString();
                gdata._name      = reader["salhead_name"].ToString();
                gdata._groupcode = reader["salhead_group_id"].ToString();
                gdata._formula   = reader["salhead_formula"].ToString();
                var a = reader["salhead_add_to_salinfo"].ToString();
                if (a == "1")
                {
                    gdata._add_to_salinfo = true;
                }
                else
                {
                    gdata._add_to_salinfo = false;
                }
                gdata._startdate = DateTime.Parse(reader["salhead_start_date"].ToString());
            }
            _sql.Con_switch(con);
            gdata._oldname = gdata._name;
            return(gdata);
        }
        private void Insert_data(Salhead_repo ins)
        {
            cmd.Connection = con;

            cmd.CommandText = "INSERT INTO salary_head (salhead_code, salhead_name, salhead_group_id, salhead_formula,salhead_add_to_salinfo, salhead_start_date) VALUES " +
                              "('" + ins._code + "','" + ins._name + "','" + ins._groupcode + "','" + ins._formula + "'," + ins._add_to_salinfo + ",'"
                              + ins._startdate.ToString("yyyy-MM-dd") + "');";

            _sql.Con_switch(con);
            int r = cmd.ExecuteNonQuery();

            cmd.CommandText = "";
            _sql.Con_switch(con);

            if (r == 1)
            {
                if (add_checkbox.Checked.Equals(true))
                {
                    try
                    {
                        cmd.CommandText = "ALTER TABLE salary_info ADD COLUMN `" + ins._name + "` DECIMAL(20,2);";
                        _sql.Con_switch(con);
                        var q = cmd.ExecuteNonQuery();
                        _sql.Con_switch(con);
                        cmd.CommandText = "ALTER TABLE salary_generate ADD COLUMN `" + ins._name + "` DECIMAL(20,2);";
                        _sql.Con_switch(con);
                        var t = cmd.ExecuteNonQuery();
                        _sql.Con_switch(con);
                        if (q == t && q == 1)
                        {
                            Response.Write(_response.FL_message("Salary Head " + ins._name.ToUpper() + " Successfully Created...!!!",
                                                                "salaryhead.aspx';"));
                        }
                    }
                    catch (MySqlException x)
                    {
                        Response.Write(_response.FL_message(x.Code + "\\n\\n" + x.SqlState + "\\n\\n" + x.StackTrace + "\\n\\n" + x.Message));
                    }
                    catch (Exception ex)
                    {
                        Response.Write(_response.FL_message("Message 1:" + ex.Message));
                    }
                }
                else
                {
                    Response.Write(_response.FL_message("Salary Head " + ins._name.ToUpper() + " Successfully Created...!!!",
                                                        "salaryhead.aspx';"));
                }
            }
            else
            {
                Response.Write(_response.FL_message("Salary Head Is Already Present With Name " +
                                                    add_name.ToString().ToUpper()));
            }
        }
        private void Set_data_for_updating()
        {
            char[] a = new char[]
            {
                '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '`', '|'
                , ';', '"', ':', '>', '?', '<', ',', '.', '{', '}', '[', ']', '/', '*', '-', '+'
            };
            var set = new Salhead_repo
            {
                _name           = edit_name.Text,
                _code           = edit_name.Text.Trim(a).Replace(" ", string.Empty),
                _formula        = edit_formula.Text,
                _groupcode      = edit_ddl_group.SelectedValue,
                _id             = int.Parse(salheadid.SelectedValue),
                _add_to_salinfo = edit_checkbox.Checked,
                _oldname        = edit_oldname.Text,
                _startdate      = DateTime.ParseExact(edit_startdate.Text, "yyyy-MM-dd", null)
            };

            Update_data(set);
        }
        private void add_controls_clear()
        {
            var gdata = new Salhead_repo {
                _code = "", _formula = "", _name = "", _groupcode = "", _startdate = DateTime.Today
            };

            add_code.Text = gdata._code;
            add_name.Text = gdata._name;
            add_ddl_group.ClearSelection();
            try
            {
                // ReSharper disable once AssignNullToNotNullAttribute
                add_ddl_group.Items.FindByValue(gdata._groupcode).Selected = true;
            }
            catch (Exception cv)
            {
                Console.WriteLine(cv.Message + enter + spaces + cv.StackTrace + enter + spaces + cv.Data + enter + spaces + cv.HelpLink +
                                  enter + spaces + cv.Source + enter + spaces + cv.HResult + enter + spaces + cv.InnerException);
            }

            add_formula.Text   = gdata._formula;
            add_startdate.Text = gdata._startdate.ToString("yyyy-MM-dd");
        }
        private void Set_data_for_saving()
        {
            char[] a = new char[]
            {
                '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '=', '`', '|'
                , ';', '"', ':', '>', '?', '<', ',', '.', '{', '}', '[', ']', '/', '*', '-', '+'
            };
            var setData = new Salhead_repo
            {
                _name           = add_name.Text,
                _code           = add_name.Text.Trim(a).Replace(" ", string.Empty),
                _groupcode      = add_ddl_group.SelectedItem.Value,
                _formula        = add_formula.Text,
                _add_to_salinfo = add_checkbox.Checked,
                _startdate      = DateTime.Parse(add_startdate.Text)
            };


            Insert_data(setData);


            Listing_add_ddl();
        }
        private void Update_data(Salhead_repo set)
        {
            Response.Write(set._id);
            cmd.Connection = con;
            var cmdtxt = "UPDATE salary_head SET " +
                         "salhead_code = '" + set._code + "', salhead_name = '" + set._name + "', salhead_group_id = '" +
                         set._groupcode + "', " +
                         "salhead_formula = '" + set._formula + "', salhead_add_to_salinfo = " + set._add_to_salinfo + "," +
                         " salhead_start_date = '" + set._startdate.ToString("yyyy-MM-dd") + "' WHERE salhead_id = " + set._id + "; ";

            /*cmd.CommandText = "CALL salary_head_update(" + set._id + ",'" + set._code + "','" + set._name + "','" +
             *                set._groupcode + "','" + set._formula + "',"+set._add_to_salinfo+",'" + set._startdate.ToString("yyyy-MM-dd") + "');";*/
            cmd.CommandText = cmdtxt;

            _sql.Con_switch(con);
            var r = cmd.ExecuteNonQuery();

            _sql.Con_switch(con);
            cmd.CommandText = "";

            if (r == 1)
            {
                if (edit_checkbox.Checked.Equals(true))
                {
                    if (_repo.Column_Exists("salary_info", edit_oldname.Text) && _repo.Column_Exists("salary_generate", edit_oldname.Text))
                    {
                        var q = 0;
                        var t = 0;

                        cmd.CommandText = "ALTER TABLE salary_info CHANGE COLUMN `" + edit_oldname.Text + "` `" + set._name + "` DECIMAL(20,2);";
                        _sql.Con_switch(con);
                        q = cmd.ExecuteNonQuery();
                        _sql.Con_switch(con);

                        cmd.CommandText = "ALTER TABLE salary_generate CHANGE COLUMN `" + edit_oldname.Text + "` `" + set._name + "` DECIMAL(20,2);";
                        _sql.Con_switch(con);
                        t = cmd.ExecuteNonQuery();
                        _sql.Con_switch(con);

                        if (q == t && q == 1)
                        {
                            Listing_edit_ddl();
                            Response.Write(_response.FL_message("Salary Head Column " + edit_oldname.Text.ToUpper() + " Changed To" + set._name.ToUpper() +
                                                                " Successfully...!!!", "~/salaryhead.aspx"));
                        }
                    }
                    else
                    {
                        try
                        {
                            var q = 0;
                            var t = 0;

                            if (_repo.Column_Exists("salary_info", edit_oldname.Text))
                            {
                                cmd.CommandText = "ALTER TABLE salary_info CHANGE COLUMN `" + edit_oldname.Text + "` `" + set._name + "` DECIMAL(20,2);";
                                _sql.Con_switch(con);
                                q = cmd.ExecuteNonQuery();
                                _sql.Con_switch(con);
                            }
                            else
                            {
                                cmd.CommandText = "ALTER TABLE salary_info ADD COLUMN `" + set._name + "` DECIMAL(20,2);";
                                _sql.Con_switch(con);
                                q = cmd.ExecuteNonQuery();
                                _sql.Con_switch(con);
                            }

                            if (_repo.Column_Exists("salary_generate", edit_oldname.Text))
                            {
                                cmd.CommandText = "ALTER TABLE salary_generate CHANGE COLUMN `" + edit_oldname.Text + "` `" + set._name + "` DECIMAL(20,2);";
                                _sql.Con_switch(con);
                                t = cmd.ExecuteNonQuery();
                                _sql.Con_switch(con);
                            }
                            else
                            {
                                cmd.CommandText = "ALTER TABLE salary_generate ADD COLUMN `" + set._name + "` DECIMAL(20,2);";
                                _sql.Con_switch(con);
                                t = cmd.ExecuteNonQuery();
                                _sql.Con_switch(con);
                            }

                            if (q == t && t == 1)
                            {
                                Response.Write(_response.FL_message("Salary Head " + set._name.ToUpper() + " Successfully Created...!!!",
                                                                    "salaryhead.aspx';"));
                            }
                        }
                        catch (MySqlException x)
                        {
                            Response.Write(_response.FL_message(x.Code + "\\n\\n" + x.SqlState + "\\n\\n" + x.StackTrace + "\\n\\n" + x.Message));
                        }
                        catch (Exception ex)
                        {
                            Response.Write(_response.FL_message("Message 1:" + ex.Message));
                        }
                    }
                }
                else
                {
                    /*if (_repo.Column_Exists("salary_info", edit_oldname.Text))
                     * {
                     *  cmd.CommandText = "ALTER TABLE salary_info drop COLUMN `" + edit_oldname.Text + "`;";
                     *  _sql.Con_switch(con);
                     *  var q = cmd.ExecuteNonQuery();
                     *  _sql.Con_switch(con);
                     *  cmd.CommandText = "ALTER TABLE salary_generate drop COLUMN `" + edit_oldname.Text + "`;";
                     *  _sql.Con_switch(con);
                     *  var t = cmd.ExecuteNonQuery();
                     *  _sql.Con_switch(con);
                     *  if (q == t && t == 1)
                     *  {
                     *      Response.Write(_response.FL_message("Salary Head Column " + edit_oldname.Text.ToUpper() +
                     *                                          " Changed To" + set._name.ToUpper() +
                     *                                          " Successfully...!!!", "~/salaryhead.aspx"));
                     *  }
                     * }*/
                    var q = 0;
                    var t = 0;
                    if (_repo.Column_Exists("salary_info", edit_oldname.Text))
                    {
                        cmd.CommandText = "ALTER TABLE salary_info drop COLUMN `" + edit_oldname.Text + "`;";
                        _sql.Con_switch(con);
                        q = cmd.ExecuteNonQuery();
                        _sql.Con_switch(con);
                    }

                    if (_repo.Column_Exists("salary_generate", edit_oldname.Text))
                    {
                        cmd.CommandText = "ALTER TABLE salary_generate drop COLUMN `" + edit_oldname.Text + "`;";
                        _sql.Con_switch(con);
                        t = cmd.ExecuteNonQuery();
                        _sql.Con_switch(con);
                    }
                    if (q == t && t == 1)
                    {
                        Response.Write(_response.FL_message("Salary Head Column " + edit_oldname.Text.ToUpper() +
                                                            " Changed To" + set._name.ToUpper() +
                                                            " Successfully...!!!", "~/salaryhead.aspx"));
                    }
                }
            }
            else
            {
                Response.Write(_response.FL_message("Salary Head Is Already Present With Name " +
                                                    set._name.ToUpper()));
            }
        }