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


Preview of Code
using AjaxControlToolkit;
using System;
using System.Configuration;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public class common
{
    private string szSql;
 
    private string szRet;
 
    private string szStr;
 
    public SqlConnection objConnect = new SqlConnection();
 
    public SqlCommand objCommand = new SqlCommand();
 
    public SqlConnection objConnect1 = new SqlConnection();
 
    public SqlCommand objCommand1 = new SqlCommand();
 
    public SqlConnection objConnect2 = new SqlConnection();
 
    public SqlCommand objCommand2 = new SqlCommand();
 
    public SqlConnection objConnect3 = new SqlConnection();
 
    public SqlCommand objCommand3 = new SqlCommand();
 
    private ListItem objList;
 
    private Dates objDate = new Dates();
 
    private string szMuncNo;
 
    private string szDistNo;
 
    private string szStreetNo;
 
    private string szRegNo;
 
    private string szWhere;
 
    public common()
    {
        this.objConnect.ConnectionString = ConfigurationManager.ConnectionStrings["TpmmsConString"].ConnectionString;
        this.objConnect1.ConnectionString = ConfigurationManager.ConnectionStrings["TpmmsConString"].ConnectionString;
        this.objConnect2.ConnectionString = ConfigurationManager.ConnectionStrings["TpmmsConString"].ConnectionString;
        this.objConnect3.ConnectionString = ConfigurationManager.ConnectionStrings["TpmmsConString"].ConnectionString;
    }
 
    public bool checknumeric(string szSearch)
    {
        bool flag = true;
        for (int i = 0; i < szSearch.Length; i++)
        {
            if (!char.IsNumber(szSearch, i))
            {
                flag = false;
            }
        }
        return flag;
    }
 
    public void CloseConnection()
    {
        if (this.objConnect.State == ConnectionState.Open)
        {
            this.objConnect.Close();
        }
    }
 
    public void CloseConnection1()
    {
        if (this.objConnect1.State == ConnectionState.Open)
        {
            this.objConnect1.Close();
        }
    }
 
    public void CloseConnection2()
    {
        if (this.objConnect2.State == ConnectionState.Open)
        {
            this.objConnect2.Close();
        }
    }
 
    public void CloseConnection3()
    {
        if (this.objConnect3.State == ConnectionState.Open)
        {
            this.objConnect3.Close();
        }
    }
 
    public DataTable Fill_DataTable(string SQLString)
    {
        SqlConnection sqlConnection = new SqlConnection()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["TpmmsConString"].ConnectionString
        };
        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(SQLString, sqlConnection);
        DataTable dataTable = new DataTable();
        sqlDataAdapter.Fill(dataTable);
        return dataTable;
    }
 
    public string fnAutoIdNum(string tblName, string colName)
    {
        string str = "";
        int num = 0;
        string.Concat("SELECT MAX(", colName, ") FROM ", tblName);
        SqlDataReader sqlDataReader = this.fnOpenConnection(this.szSql);
        if (sqlDataReader.Read())
        {
            str = sqlDataReader[0].ToString();
        }
        if (str == "")
        {
            str = "0";
        }
        num = int.Parse(str);
        str = (num + 1).ToString();
        this.CloseConnection();
        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.fnOpenConnection(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.CloseConnection();
        return str;
    }
 
    public int fnExecuteNonQuery(string szSql)
    {
        if (this.objConnect.State == ConnectionState.Open)
        {
            this.objConnect.Close();
        }
        this.objConnect.Open();
        this.objCommand.Connection = this.objConnect;
        this.objCommand.CommandText = szSql;
        int num = this.objCommand.ExecuteNonQuery();
        this.objConnect.Close();
        return num;
    }
 
    public int fnExecuteNonQuery1(string szSql)
    {
        if (this.objConnect1.State == ConnectionState.Open)
        {
            this.objConnect1.Close();
        }
        this.objConnect1.Open();
        this.objCommand1.Connection = this.objConnect1;
        this.objCommand1.CommandText = szSql;
        int num = this.objCommand1.ExecuteNonQuery();
        this.objConnect1.Close();
        return num;
    }
 
    public int fnExecuteNonQuery2(string szSql)
    {
        if (this.objConnect2.State == ConnectionState.Open)
        {
            this.objConnect2.Close();
        }
        this.objConnect2.Open();
        this.objCommand2.Connection = this.objConnect2;
        this.objCommand2.CommandText = szSql;
        int num = this.objCommand2.ExecuteNonQuery();
        this.objConnect2.Close();
        return num;
    }
 
    public int fnExecuteNonQuery3(string szSql)
    {
        if (this.objConnect3.State == ConnectionState.Open)
        {
            this.objConnect3.Close();
        }
        this.objConnect3.Open();
        this.objCommand3.Connection = this.objConnect3;
        this.objCommand3.CommandText = szSql;
        int num = this.objCommand3.ExecuteNonQuery();
        this.objConnect3.Close();
        return num;
    }
 
    public void fnGetArea(TextBox txt1, TextBox txt2, TextBox txt3)
    {
        string text = txt1.Text;
        string str = txt2.Text;
        string text1 = txt3.Text;
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (text.Length > 0)
        {
            num = double.Parse(text);
        }
        if (str.Length > 0)
        {
            num1 = double.Parse(str);
        }
        num2 = Math.Round(num * num1, 2);
        txt3.Text = num2.ToString();
    }
 
    public void fnGetAreaLabel(TextBox txt1, TextBox txt2, Label txt3)
    {
        string text = txt1.Text;
        string str = txt2.Text;
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (text.Length > 0)
        {
            num = double.Parse(text);
        }
        if (str.Length > 0)
        {
            num1 = double.Parse(str);
        }
        num2 = Math.Round(num * num1, 2);
        txt3.Text = num2.ToString();
    }
 
    public string fnGetAreaReturn(TextBox txt1, TextBox txt2)
    {
        string text = txt1.Text;
        string str = txt2.Text;
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (text.Length > 0)
        {
            num = double.Parse(text);
        }
        if (str.Length > 0)
        {
            num1 = double.Parse(str);
        }
        num2 = num * num1;
        return Math.Round(num2, 2).ToString();
    }
 
    public string fnGetAreaValue(string szLength, string szWidth)
    {
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (szLength.Length > 0)
        {
            num = double.Parse(szLength);
        }
        if (szWidth.Length > 0)
        {
            num1 = double.Parse(szWidth);
        }
        num2 = num * num1;
        return Math.Round(num2, 2).ToString();
    }
 
    public void fnGetDensity(TextBox txt1, TextBox txt2, TextBox txt3)
    {
        string text = txt1.Text;
        string str = txt2.Text;
        string text1 = txt3.Text;
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (str.Length > 0)
        {
            if (text.Length > 0)
            {
                num = (double)float.Parse(text);
            }
            if (str.Length > 0)
            {
                num1 = (double)float.Parse(str);
            }
            num2 = num * 100 / num1;
        }
        double num3 = Math.Round(num2, 2);
        txt3.Text = num3.ToString();
    }
 
    public double fnGetDensity_RetDouble(TextBox txt1, TextBox txt2)
    {
        string text = txt1.Text;
        string str = txt2.Text;
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (str.Length > 0)
        {
            if (text.Length > 0)
            {
                num = (double)float.Parse(text);
            }
            if (str.Length > 0)
            {
                num1 = (double)float.Parse(str);
            }
            num2 = num * 100 / num1;
        }
        return Math.Round(num2, 2);
    }
 
    public double fnGetDensity_RetDoubleDirect(string szDistArea, string szSampleArea)
    {
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (szSampleArea.Length > 0)
        {
            if (szDistArea.Length > 0)
            {
                num = (double)float.Parse(szDistArea);
            }
            if (szSampleArea.Length > 0)
            {
                num1 = (double)float.Parse(szSampleArea);
            }
            num2 = num * 100 / num1;
        }
        return Math.Round(num2, 2);
    }
 
    public string fnGetDensity_Variable(string txt1, string txt2)
    {
        string str = txt1;
        string str1 = txt2;
        double num = 0;
        double num1 = 0;
        double num2 = 0;
        if (str1.Length > 0)
        {
            if (str.Length > 0)
            {
                num = (double)float.Parse(str);
            }
            if (str1.Length > 0)
            {
                num1 = (double)float.Parse(str1);
            }
            num2 = num * 100 / num1;
        }
        return Math.Round(num2, 2).ToString();
    }
 
    public string fnGetDescFromDropDown(DropDownList ctrl)
    {
        string text = "";
        if (ctrl.Items.Count > 0)
        {
            text = ctrl.SelectedItem.Text;
        }
        if (text == "اختـــــر")
        {
            text = "";
        }
        return text;
    }
 
    public string fnGetValueFromDropDown(DropDownList ctrl)
    {
        string value = "";
        if (ctrl.Items.Count > 0)
        {
            value = ctrl.SelectedItem.Value;
        }
        value = value.Trim();
        return value;
    }
 
    public void fnLaunchMsg(string szMsg, Page objPage)
    {
        string str = string.Concat("<script language=`javascript`>", "var szErr=`", szMsg, "`;");
        str = string.Concat(str, "alert(szErr);");
        objPage.RegisterStartupScript("Close", string.Concat(str, "</script>"));
    }
 
    public void fnLblMsgHide(Label ctrl)
    {
        ctrl.Visible = false;
        ctrl.Text = "";
    }
 
    public void fnLblMsgShow(Label ctrl, string szMsg)
    {
        if (szMsg == "")
        {
            ctrl.Visible = false;
            ctrl.Text = "";
            return;
        }
        ctrl.Visible = true;
        ctrl.Text = szMsg;
    }
 
    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 fnOpenConnection(string szSql)
    {
        if (this.objConnect.State == ConnectionState.Open)
        {
            this.objConnect.Close();
        }
        this.objConnect.Open();
        this.objCommand.Connection = this.objConnect;
        this.objCommand.CommandText = szSql;
        return this.objCommand.ExecuteReader(CommandBehavior.CloseConnection);
    }
 
    public SqlDataReader fnOpenConnection1(string szSql)
    {
        if (this.objConnect1.State == ConnectionState.Open)
        {
            this.objConnect1.Close();
        }
        this.objConnect1.Open();
        this.objCommand1.Connection = this.objConnect1;
        this.objCommand1.CommandText = szSql;
        return this.objCommand1.ExecuteReader(CommandBehavior.CloseConnection);
    }
 
    public SqlDataReader fnOpenConnection3(string szSql)
    {
        if (this.objConnect3.State == ConnectionState.Open)
        {
            this.objConnect3.Close();
        }
        this.objConnect3.Open();
        this.objCommand3.Connection = this.objConnect3;
        this.objCommand3.CommandText = szSql;
        return this.objCommand3.ExecuteReader(CommandBehavior.CloseConnection);
    }
 
    public ComboBox fnPopComboBox(ComboBox 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.objDataReader(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.CloseConnection();
        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 DropDownList fnPopDropDown(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.objDataReader(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.CloseConnection();
        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 void fnSetComboBoxByText(ComboBox ctrl, string szStr)
    {
        ctrl.ClearSelection();
        if (ctrl.Items.FindByText(szStr) != null)
        {
            ctrl.Items.FindByText(szStr).Selected = true;
        }
    }
 
    public void fnSetDropDownByText(DropDownList ctrl, string szStr)
    {
        ctrl.ClearSelection();
        if (ctrl.Items.FindByText(szStr) != null)
        {
            ctrl.Items.FindByText(szStr).Selected = true;
        }
    }
 
    public void fnSetDropDownByValue(DropDownList ctrl, string szStr)
    {
        ctrl.ClearSelection();
        if (ctrl.Items.FindByValue(szStr) != null)
        {
            ctrl.Items.FindByValue(szStr).Selected = true;
        }
    }
 
    public void fnSetListBoxByValue(ListBox ctrl, string szStr)
    {
        ctrl.ClearSelection();
        if (ctrl.Items.FindByValue(szStr) != null)
        {
            ctrl.Items.FindByValue(szStr).Selected = true;
        }
    }
 
    public string FormatDDMMYYYY(string szDate)
    {
        string[] str = new string[5];
        int day = DateTime.Parse(szDate).Day;
        str[0] = day.ToString();
        str[1] = "/";
        int month = DateTime.Parse(szDate).Month;
        str[2] = month.ToString();
        str[3] = "/";
        int year = DateTime.Parse(szDate).Year;
        str[4] = year.ToString();
        return string.Concat(str);
    }
 
    public string GetDeductPoint(TextBox txtSeverity1, TextBox txtDistCode1)
    {
        string text = txtSeverity1.Text;
        if (text != "L")
        {
            text = (text != "M" ? "High" : "Medium");
        }
        else
        {
            text = "Light";
        }
        return this.GetValue(string.Concat("Select ", text, " From L_DeductPoint Where UDI_DNo=", txtDistCode1.Text));
    }
 
    public string GetDeductPoint_Variable(string gszSeverity, string gszDistCode)
    {
        string str = gszSeverity;
        if (str != "L")
        {
            str = (str != "M" ? "High" : "Medium");
        }
        else
        {
            str = "Light";
        }
        return this.GetValue(string.Concat("Select ", str, " From L_DeductPoint Where UDI_DNo=", gszDistCode));
    }
 
    public string GetDeductPointDirect(string szSeverity1, string szDistCode1)
    {
        string str = szSeverity1;
        if (str != "L")
        {
            str = (str != "M" ? "High" : "Medium");
        }
        else
        {
            str = "Light";
        }
        return this.GetValue(string.Concat("Select ", str, " From L_DeductPoint Where UDI_DNo=", szDistCode1));
    }
 
    public string GetDeductValue(TextBox txtDedPoint1, TextBox txtDensityDash1)
    {
        double num = 0;
        if (txtDedPoint1.Text.Length > 0)
        {
            num = double.Parse(txtDedPoint1.Text);
        }
        double num1 = double.Parse(txtDensityDash1.Text);
        double num2 = num * num1 / 100;
        return Math.Round(num2, 2).ToString();
    }
 
    public string GetDeductValue_Variable(string txtDedPoint1, string txtDensityDash1)
    {
        double num = 0;
        if (txtDedPoint1.Length > 0)
        {
            num = double.Parse(txtDedPoint1);
        }
        double num1 = num * double.Parse(txtDensityDash1) / 100;
        return Math.Round(num1, 2).ToString();
    }
 
    public string GetDeductValueDirect(string szDedPoint1, string szDensityDash1)
    {
        double num = 0;
        if (szDedPoint1.Length > 0)
        {
            num = double.Parse(szDedPoint1);
        }
        double num1 = num * double.Parse(szDensityDash1) / 100;
        return Math.Round(num1, 2).ToString();
    }
 
    public string GetDensityDash(int nDistCode, double nDensity)
    {
        int num;
        double num1 = 0;
        if (nDistCode == 5)
        {
            num = 1;
        }
        else if (nDistCode == 1)
        {
            num = 2;
        }
        else if (nDistCode == 6 || nDistCode == 7 || nDistCode == 8)
        {
            num = 3;
        }
        else if (nDistCode == 12 || nDistCode == 13 || nDistCode == 14 || nDistCode == 15)
        {
            num = 4;
        }
        else
        {
            num = (nDistCode == 2 || nDistCode == 3 || nDistCode == 4 || nDistCode == 9 || nDistCode == 10 || nDistCode == 11 ? 5 : 0);
        }
        if (num == 1)
        {
            if (nDensity >= 0 && nDensity <= 2)
            {
                num1 = (nDensity - 0) / 2 * 30 + 0;
            }
            else if (nDensity >= 2 && nDensity <= 10)
            {
                num1 = (nDensity - 2) / 8 * 40 + 30;
            }
            else if (nDensity >= 10 && nDensity <= 25)
            {
                num1 = (nDensity - 10) / 15 * 10 + 70;
            }
            else if (nDensity < 25 || nDensity > 50)
            {
                num1 = (nDensity < 50 || nDensity > 100 ? 0 : (nDensity - 50) / 50 * 10 + 90);
            }
            else
            {
                num1 = (nDensity - 25) / 25 * 10 + 80;
            }
        }
        else if (num == 2)
        {
            if (nDensity >= 0 && nDensity <= 2)
            {
                num1 = (nDensity - 0) / 2 * 25 + 0;
            }
            else if (nDensity >= 2 && nDensity <= 10)
            {
                num1 = (nDensity - 2) / 8 * 30 + 25;
            }
            else if (nDensity >= 10 && nDensity <= 25)
            {
                num1 = (nDensity - 10) / 15 * 20 + 55;
            }
            else if (nDensity < 25 || nDensity > 50)
            {
                num1 = (nDensity < 50 || nDensity > 100 ? 0 : (nDensity - 50) / 50 * 15 + 85);
            }
            else
            {
                num1 = (nDensity - 25) / 25 * 10 + 75;
            }
        }
        else if (num == 3)
        {
            if (nDensity >= 0 && nDensity <= 2)
            {
                num1 = (nDensity - 0) / 2 * 20 + 0;
            }
            else if (nDensity >= 2 && nDensity <= 10)
            {
                num1 = (nDensity - 2) / 8 * 30 + 20;
            }
            else if (nDensity >= 10 && nDensity <= 25)
            {
                num1 = (nDensity - 10) / 15 * 20 + 50;
            }
            else if (nDensity < 25 || nDensity > 50)
            {
                num1 = (nDensity < 50 || nDensity > 100 ? 0 : (nDensity - 50) / 50 * 20 + 80);
            }
            else
            {
                num1 = (nDensity - 25) / 25 * 10 + 70;
            }
        }
        else if (num == 4)
        {
            if (nDensity >= 0 && nDensity <= 2)
            {
                num1 = (nDensity - 0) / 2 * 18 + 0;
            }
            else if (nDensity >= 2 && nDensity <= 10)
            {
                num1 = (nDensity - 2) / 8 * 30 + 18;
            }
            else if (nDensity >= 10 && nDensity <= 25)
            {
                num1 = (nDensity - 10) / 15 * 20 + 48;
            }
            else if (nDensity >= 25 && nDensity <= 50)
            {
                num1 = (nDensity - 25) / 25 * 10 + 68;
            }
            else if (nDensity >= 50 && nDensity <= 100)
            {
                num1 = (nDensity - 50) / 50 * 22 + 78;
            }
        }
        else if (nDensity >= 0 && nDensity <= 2)
        {
            num1 = (nDensity - 0) / 2 * 10 + 0;
        }
        else if (nDensity >= 2 && nDensity <= 10)
        {
            num1 = (nDensity - 2) / 8 * 20 + 10;
        }
        else if (nDensity >= 10 && nDensity <= 25)
        {
            num1 = (nDensity - 10) / 15 * 20 + 30;
        }
        else if (nDensity >= 25 && nDensity <= 50)
        {
            num1 = (nDensity - 25) / 25 * 20 + 50;
        }
        else if (nDensity >= 50 && nDensity <= 100)
        {
            num1 = (nDensity - 50) / 50 * 30 + 70;
        }
        return Math.Round(num1, 2).ToString();
    }
 
    public string GetMentDecision(int nDistCode, double nDD, string szSeverity)
    {
        int num = 1;
        if (nDistCode == 1)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 3);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 4 : 4);
                }
                else
                {
                    num = 4;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 4 : 4);
            }
            else
            {
                num = 4;
            }
        }
        else if (nDistCode == 2)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 5 : 2);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 5 : 2);
                }
                else
                {
                    num = 2;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 3 : 3);
            }
            else
            {
                num = 2;
            }
        }
        else if (nDistCode == 3)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 1 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 2 : 2);
                }
                else
                {
                    num = 2;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 3 : 2);
            }
            else
            {
                num = 2;
            }
        }
        else if (nDistCode == 4)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 1 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 1 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 1 : 1);
            }
            else
            {
                num = 1;
            }
        }
        else if (nDistCode == 5)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 3);
                }
                else
                {
                    num = 2;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 4 : 4);
            }
            else
            {
                num = 4;
            }
        }
        else if (nDistCode == 6)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 3);
                }
                else
                {
                    num = 3;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 4 : 4);
            }
            else
            {
                num = 4;
            }
        }
        else if (nDistCode == 7)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 3);
                }
                else
                {
                    num = 3;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 4 : 4);
            }
            else
            {
                num = 4;
            }
        }
        else if (nDistCode == 8)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 3);
                }
                else
                {
                    num = 3;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 4 : 4);
            }
            else
            {
                num = 4;
            }
        }
        else if (nDistCode == 9)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 1 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 3);
                }
                else
                {
                    num = 3;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 3 : 3);
            }
            else
            {
                num = 3;
            }
        }
        else if (nDistCode == 10)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 1 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 5 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 5 : 1);
            }
            else
            {
                num = 1;
            }
        }
        else if (nDistCode == 11)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 5 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 5 : 5);
                }
                else
                {
                    num = 1;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 5 : 5);
            }
            else
            {
                num = 5;
            }
        }
        else if (nDistCode == 12)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 1 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 2 : 2);
                }
                else
                {
                    num = 2;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 3 : 2);
            }
            else
            {
                num = 2;
            }
        }
        else if (nDistCode == 13)
        {
            if (szSeverity == "L")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 1);
                }
                else
                {
                    num = 1;
                }
            }
            else if (szSeverity == "M")
            {
                if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 3 : 3);
                }
                else
                {
                    num = 3;
                }
            }
            else if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 4 : 4);
            }
            else
            {
                num = 4;
            }
        }
        else if (nDistCode != 14)
        {
            if (nDistCode == 15)
            {
                if (szSeverity == "L")
                {
                    if (nDD >= 10)
                    {
                        num = (nDD < 10 || nDD > 50 ? 1 : 1);
                    }
                    else
                    {
                        num = 1;
                    }
                }
                else if (szSeverity == "M")
                {
                    if (nDD >= 10)
                    {
                        num = (nDD < 10 || nDD > 50 ? 5 : 5);
                    }
                    else
                    {
                        num = 1;
                    }
                }
                else if (nDD >= 10)
                {
                    num = (nDD < 10 || nDD > 50 ? 5 : 5);
                }
                else
                {
                    num = 5;
                }
            }
        }
        else if (szSeverity == "L")
        {
            if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 3 : 1);
            }
            else
            {
                num = 1;
            }
        }
        else if (szSeverity == "M")
        {
            if (nDD >= 10)
            {
                num = (nDD < 10 || nDD > 50 ? 3 : 3);
            }
            else
            {
                num = 3;
            }
        }
        else if (nDD >= 10)
        {
            num = (nDD < 10 || nDD > 50 ? 4 : 4);
        }
        else
        {
            num = 4;
        }
        return num.ToString();
    }
 
    public void GetRegTypeNoAndTypeName(string KeyId, TextBox txt1, TextBox txt2)
    {
        this.szDistNo = KeyId.Substring(0, 3);
        this.szRegNo = KeyId.Substring(3, 2);
        this.szWhere = string.Concat(" Where  DistNo=", this.szDistNo, " And RegNo=", this.szRegNo);
        txt1.Text = this.GetValue(string.Concat("Select RegTypeNo from Region_View", this.szWhere));
        txt2.Text = this.GetValue(string.Concat("Select RegTypeName from Region_View", this.szWhere));
    }
 
    public string getUdiRate(double dUdi)
    {
        string str;
        if (dUdi >= 0 && dUdi <= 39)
        {
            str = "Poor";
        }
        else if (dUdi < 40 || dUdi > 69)
        {
            str = (dUdi < 70 || dUdi > 89 ? "Excelent" : "Good");
        }
        else
        {
            str = "Fair";
        }
        return str;
    }
 
    public string GetValue(string strSQL)
    {
        SqlCommand sqlCommand = new SqlCommand(strSQL, new SqlConnection(ConfigurationManager.ConnectionStrings["TpmmsConString"].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 string GetValueDefZero(string strSQL)
    {
        SqlCommand sqlCommand = new SqlCommand(strSQL, new SqlConnection(ConfigurationManager.ConnectionStrings["TpmmsConString"].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 string GregToHijriInDMY(string szDate)
    {
        string[] str = new string[5];
        int day = DateTime.Parse(szDate).Day;
        str[0] = day.ToString();
        str[1] = "/";
        int month = DateTime.Parse(szDate).Month;
        str[2] = month.ToString();
        str[3] = "/";
        int year = DateTime.Parse(szDate).Year;
        str[4] = year.ToString();
        string str1 = string.Concat(str);
        return this.objDate.GregToHijri(str1, "dd-MM-yyyy");
    }
 
    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.fnOpenConnection(string.Concat(str, ")"));
        this.CloseConnection();
    }
 
    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.fnOpenConnection(string.Concat(str, ")"));
        this.CloseConnection();
        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.fnOpenConnection(string.Concat(str, ")"));
        this.CloseConnection();
        this.fnLblMsgShow(lblCtrl, szMessage, "msgblue", nMsgSize);
    }
 
    public void InsertIntoDataBaseMulti(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.fnOpenConnection1(string.Concat(str, ")"));
        this.CloseConnection1();
    }
 
    public void InsertSurveyDet(string ItemId, int SurNo, string szSurDate)
    {
        object[] itemId = new object[] { " Where ItemNo=`", ItemId, "` And SurveyNo=", SurNo };
        if (!this.IsRecExists("SurveyDetails", "ItemNo", string.Concat(itemId)))
        {
            string str = "ItemNo,SurveyNo,SurveyDate";
            object[] objArray = new object[] { "`", ItemId, "`,", SurNo, ",`", szSurDate, "`" };
            this.InsertIntoDataBase("SurveyDetails", str, string.Concat(objArray));
        }
    }
 
    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.objDataReader(this.szSql);
        if (sqlDataReader.Read())
        {
            this.szRet = sqlDataReader[0].ToString();
            this.CloseConnection();
            flag = (int.Parse(this.szRet) <= 0 ? false : true);
        }
        return flag;
    }
 
    public bool IsSectinEndsTrue(string getNum)
    {
        bool flag = getNum.EndsWith("M");
        if (!flag && !getNum.EndsWith("S"))
        {
            return false;
        }
        return true;
    }
 
    public SqlDataReader objDataReader(string szSql)
    {
        if (this.objConnect.State == ConnectionState.Open)
        {
            this.objConnect.Close();
        }
        this.objConnect.Open();
        this.objCommand.Connection = this.objConnect;
        this.objCommand.CommandText = szSql;
        return this.objCommand.ExecuteReader(CommandBehavior.CloseConnection);
    }
 
    public void OnSampleLenghtOrWidthChange(TextBox txtLengthCls, TextBox txtWidthCls, TextBox txtAreaCls)
    {
        if (txtLengthCls.Text.Length > 0 && txtWidthCls.Text.Length > 0)
        {
            this.fnGetArea(txtLengthCls, txtWidthCls, txtAreaCls);
            return;
        }
        if (txtLengthCls.Text.Length > 0 && txtWidthCls.Text.Length == 0)
        {
            txtAreaCls.Text = "";
            return;
        }
        if (txtLengthCls.Text.Length == 0 && txtWidthCls.Text.Length > 0)
        {
            txtAreaCls.Text = "";
            return;
        }
        txtAreaCls.Text = "";
    }
 
    public void PopDistName(TextBox txt1, TextBox txt2)
    {
        if (txt1.Text.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select DistName  from L_District Where DistNo=", txt1.Text));
    }
 
    public void PopDistNameBy_KeyId_Intersection(string KeyId, TextBox txt1, TextBox txt2)
    {
        this.szStr = KeyId.Substring(0, 4);
        txt1.Text = this.szStr;
        if (KeyId.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select DistName  from L_District Where DistNo=", this.szStr));
    }
 
    public void PopDistNameBy_KeyId_Section(string KeyId, TextBox txt1, TextBox txt2)
    {
        this.szDistNo = KeyId.Substring(0, 3);
        txt1.Text = this.szDistNo;
        if (KeyId.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        string[] strArrays = new string[] { "Select DistName  from L_District Where MuncNo=`", this.szMuncNo, "` And DistNo=`", this.szDistNo, "`" };
        txt2.Text = this.GetValue(string.Concat(strArrays));
    }
 
    public void PopMuncName(TextBox txt1, TextBox txt2)
    {
        if (txt1.Text.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select MuncName  from L_Muncipality Where MuncNo=", txt1.Text));
    }
 
    public void PopMuncNameBy_KeyId_Common(string KeyId, TextBox txt1, TextBox txt2)
    {
        this.szStr = KeyId.Substring(0, 2);
        txt1.Text = this.szStr;
        if (KeyId.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select MuncName  from L_Muncipality Where MuncNo=`", this.szStr, "`"));
    }
 
    public void PopMuncNameBy_VarText(string StreetNo, TextBox txt2)
    {
        if (StreetNo.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select MuncName  from L_Muncipality Where MuncNo=", StreetNo));
    }
 
    public void PopRegionType(TextBox txt1, TextBox txt2)
    {
        if (txt1.Text.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select RegTypeName  from L_RegionType Where RegTypeNo=", txt1.Text));
    }
 
    public void PopStreetName(TextBox txt1, TextBox txt2)
    {
        txt1.Text = txt1.Text.Trim();
        if (txt1.Text.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select StreetName from L_Streets Where StreetNo=`", txt1.Text, "`"));
        txt2.Text = txt2.Text.Trim();
    }
 
    public void PopStreetNameBy_KeyId_Intersection(string KeyId, TextBox txt1, TextBox txt2, TextBox txt3, TextBox txt4)
    {
        this.szStr = KeyId.Substring(2, 3);
        this.szRet = KeyId.Substring(5, 3);
        txt1.Text = this.szStr;
        txt3.Text = this.szRet;
        if (KeyId.Length > 0)
        {
            txt2.Text = this.GetValue(string.Concat("Select StreetName  from L_Streets Where StreetNo=", this.szStr));
            txt4.Text = this.GetValue(string.Concat("Select StreetName  from L_Streets Where StreetNo=", this.szRet));
        }
    }
 
    public void PopStreetNameBy_KeyId_Section(string KeyId, TextBox txt1, TextBox txt2)
    {
        this.szStr = KeyId.Substring(6, 3);
        txt1.Text = this.szStr;
        if (KeyId.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select StreetName  from L_Streets Where StreetNo=", this.szStr));
    }
 
    public void PopStreetNameThroughWhereCond(TextBox txt1, TextBox txt2, string gszWhere)
    {
        txt1.Text = txt1.Text.Trim();
        gszWhere = string.Concat(gszWhere, " And StreetNo=`", txt1.Text, "`");
        if (txt1.Text.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        txt2.Text = this.GetValue(string.Concat("Select StreetName from L_Streets ", gszWhere));
        txt2.Text = txt2.Text.Trim();
    }
 
    public void PopValueBy_KeyId(string KeyId, TextBox txt1, TextBox txt2, int nStart, int nEnd, string ColDesc, string ColNo, string tblName)
    {
        this.szStr = KeyId.Substring(nStart, nEnd);
        txt1.Text = this.szStr;
        if (KeyId.Length <= 0)
        {
            txt2.Text = "";
            return;
        }
        string[] colDesc = new string[] { "Select ", ColDesc, "  from ", tblName, " Where ", ColNo, "=", this.szStr };
        txt2.Text = this.GetValue(string.Concat(colDesc));
    }
 
    public int RecordCount(string szStr)
    {
        int num = 0;
        SqlDataReader sqlDataReader = this.objDataReader(szStr);
        if (sqlDataReader.Read())
        {
            num = int.Parse(sqlDataReader[0].ToString());
            this.CloseConnection();
        }
        return num;
    }
 
    public int Update_Method(string SQLString)
    {
        SqlConnection sqlConnection = new SqlConnection()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings["TpmmsConString"].ConnectionString
        };
        if (sqlConnection.State == ConnectionState.Open)
        {
            sqlConnection.Close();
        }
        SqlCommand sqlCommand = new SqlCommand(SQLString, sqlConnection);
        sqlConnection.Open();
        int num = sqlCommand.ExecuteNonQuery();
        sqlConnection.Close();
        return num;
    }
}