Title: class Gis                                 If you need copy same format use firefox or chrome or safari but iexplorer not work


Preview of Code
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public class gis
{
    private string szSql;
 
    private string szRet;
 
    private string szStr;
 
    public SqlConnection objConnectSde = new SqlConnection();
 
    public SqlCommand objCommandSde = new SqlCommand();
 
    private ListItem objList;
 
    private Dates objDate = new Dates();
 
    public gis()
    {
        this.objConnectSde.ConnectionString = ConfigurationManager.ConnectionStrings["gisConString"].ConnectionString;
    }
 
    public void CloseConnectiongis()
    {
        if (this.objConnectSde.State == ConnectionState.Open)
        {
            this.objConnectSde.Close();
        }
    }
 
    public string fnAutoIdNum(string tblName, string colName)
    {
        string str = "";
        int num = 0;
        string str1 = string.Concat("SELECT MAX(", colName, ") FROM ", tblName);
        SqlDataReader sqlDataReader = this.fnOpenConnectiongis(str1);
        if (sqlDataReader.Read())
        {
            str = sqlDataReader[0].ToString();
        }
        if (str == "")
        {
            str = "0";
        }
        num = int.Parse(str);
        str = (num + 1).ToString();
        this.CloseConnectiongis();
        return str;
    }
 
    public string fnAutoIdNum(string tblName, string colName, string WhereCondition)
    {
        string str = "";
        int num = 0;
        string[] strArrays = new string[] { "SELECT MAX(", colName, ") FROM ", tblName, WhereCondition };
        SqlDataReader sqlDataReader = this.fnOpenConnectiongis(string.Concat(strArrays));
        if (sqlDataReader.Read())
        {
            str = sqlDataReader[0].ToString();
        }
        if (str == "")
        {
            str = "0";
        }
        if (str == "-1")
        {
            str = "0";
        }
        num = int.Parse(str);
        str = (num + 1).ToString();
        this.CloseConnectiongis();
        return str;
    }
 
    public int fnExecuteNonQuerygis(string szSql)
    {
        if (this.objConnectSde.State == ConnectionState.Open)
        {
            this.objConnectSde.Close();
        }
        this.objConnectSde.Open();
        this.objCommandSde.Connection = this.objConnectSde;
        this.objCommandSde.CommandText = szSql;
        int num = this.objCommandSde.ExecuteNonQuery();
        this.objConnectSde.Close();
        return num;
    }
 
    public void fnLblMsgShow(Label ctrl, string szMsg, string szClass, int nWidth)
    {
        if (szMsg == "")
        {
            ctrl.Visible = false;
            ctrl.Text = "";
            return;
        }
        ctrl.Visible = true;
        ctrl.Text = szMsg;
        ctrl.CssClass = szClass;
        ctrl.Width = nWidth;
    }
 
    public SqlDataReader fnOpenConnectiongis(string szSql)
    {
        if (this.objConnectSde.State == ConnectionState.Open)
        {
            this.objConnectSde.Close();
        }
        this.objConnectSde.Open();
        this.objCommandSde.Connection = this.objConnectSde;
        this.objCommandSde.CommandText = szSql;
        return this.objCommandSde.ExecuteReader(CommandBehavior.CloseConnection);
    }
 
    public DropDownList fnPopDropDowngis(DropDownList ctrl, string szSql, string szDefListItem, string szDefValue, string szDefSel)
    {
        string str = "";
        string str1 = "";
        int num = 0;
        bool flag = false;
        if (ctrl == null || szSql == null || szSql.Length == 0)
        {
            return ctrl;
        }
        ctrl.Items.Clear();
        if (szDefListItem != "")
        {
            this.objList = new ListItem()
            {
                Value = szDefValue,
                Text = szDefListItem
            };
            ctrl.Items.Add(this.objList);
        }
        SqlDataReader sqlDataReader = this.objDataReadergis(szSql);
        int fieldCount = sqlDataReader.FieldCount;
        while (sqlDataReader.Read())
        {
            str = sqlDataReader[0].ToString();
            str1 = sqlDataReader[1].ToString();
            if (!(str != "") || !(str1 != ""))
            {
                continue;
            }
            this.objList = new ListItem()
            {
                Value = str,
                Text = str1
            };
            ctrl.Items.Add(this.objList);
            if (szDefSel == "")
            {
                continue;
            }
            if (szDefSel == str)
            {
                if (!flag)
                {
                    ctrl.SelectedIndex = num;
                }
                num++;
            }
            num++;
        }
        this.CloseConnectiongis();
        int count = ctrl.Items.Count;
        if (count == 0)
        {
            ctrl.Items.Clear();
            this.objList = new ListItem()
            {
                Value = "",
                Text = "Not Found"
            };
            ctrl.Items.Add(this.objList);
            ctrl.Enabled = false;
        }
        else if (count != 2)
        {
            ctrl.Enabled = true;
        }
        ctrl.SelectedIndex = 0;
        return ctrl;
    }
 
    public string GetValue(string strSQL)
    {
        SqlCommand sqlCommand = new SqlCommand(strSQL, new SqlConnection(ConfigurationManager.ConnectionStrings["gisConString"].ConnectionString))
        {
            CommandText = strSQL,
            CommandType = CommandType.Text
        };
        sqlCommand.Connection.Open();
        object obj = sqlCommand.ExecuteScalar();
        sqlCommand.Connection.Close();
        if (object.ReferenceEquals(obj, null) || object.ReferenceEquals(obj, "") || object.ReferenceEquals(obj, "NULL"))
        {
            return "-1";
        }
        if (obj.ToString().Length == 0)
        {
            return "-1";
        }
        return obj.ToString();
    }
 
    public void InsertIntoDataBase(string tblName, string szColumns, string szValues)
    {
        string str = string.Concat("Insert into ", tblName);
        str = string.Concat(str, "(");
        str = string.Concat(str, szColumns);
        str = string.Concat(str, ") values (");
        str = string.Concat(str, szValues);
        this.fnOpenConnectiongis(string.Concat(str, ")"));
        this.CloseConnectiongis();
    }
 
    public void InsertIntoDataBase(string tblName, string szColumns, string szValues, Label lblCtrl)
    {
        string str = string.Concat("Insert into ", tblName);
        str = string.Concat(str, "(");
        str = string.Concat(str, szColumns);
        str = string.Concat(str, ") values (");
        str = string.Concat(str, szValues);
        this.fnOpenConnectiongis(string.Concat(str, ")"));
        this.CloseConnectiongis();
        this.fnLblMsgShow(lblCtrl, "Record saved", "mb", 100);
    }
 
    public void InsertIntoDataBase(string tblName, string szColumns, string szValues, Label lblCtrl, string szMessage, int nMsgSize)
    {
        string str = string.Concat("Insert into ", tblName);
        str = string.Concat(str, "(");
        str = string.Concat(str, szColumns);
        str = string.Concat(str, ") values (");
        str = string.Concat(str, szValues);
        this.fnOpenConnectiongis(string.Concat(str, ")"));
        this.CloseConnectiongis();
        this.fnLblMsgShow(lblCtrl, szMessage, "msgblue", nMsgSize);
    }
 
    public bool IsRecExists(string tblName, string colName, string szWhere)
    {
        bool flag = false;
        string[] strArrays = new string[] { "Select Count(", colName, ") From ", tblName, szWhere };
        this.szSql = string.Concat(strArrays);
        SqlDataReader sqlDataReader = this.objDataReadergis(this.szSql);
        if (sqlDataReader.Read())
        {
            this.szRet = sqlDataReader[0].ToString();
            this.CloseConnectiongis();
            flag = (int.Parse(this.szRet) <= 0 ? false : true);
        }
        return flag;
    }
 
    public SqlDataReader objDataReadergis(string szSql)
    {
        if (this.objConnectSde.State == ConnectionState.Open)
        {
            this.objConnectSde.Close();
        }
        this.objConnectSde.Open();
        this.objCommandSde.Connection = this.objConnectSde;
        this.objCommandSde.CommandText = szSql;
        return this.objCommandSde.ExecuteReader(CommandBehavior.CloseConnection);
    }
}