Exemplo n.º 1
0
 StringBuilder strbuilder;//string builder for query
 #region  Data in Gridview
 /// <summary>
 /// Event Name:Page Load Event
 /// Description:Fetch the data from Database table and bind in the Gridview
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         //insert SQLquery in String builder
         strbuilder = new StringBuilder("SELECT * ");
         strbuilder.Append(" FROM");
         strbuilder.Append(" Territories;");
         //connection generation and read the data fro reader
         objcmnfunction = new CommonFunctions();
         //store data in grid view
         gvTerritories.DataSource = objcmnfunction.ConnectionGenerate(strbuilder.ToString());
         gvTerritories.DataBind();
     }
     catch (Exception)
     {
         objconstmsg = new ConstantMessages();
         Response.Redirect(objconstmsg.strerrorpage);
     }
     finally
     {
         objcmnfunction = null;
         strbuilder     = null;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Method Name: Page_Load
 /// Description:Concept of session dataset & Binding with GridView
 /// Author:bhumi
 /// created On:2/6/2015
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         //Typed Dataset & its TableAdapter
         dataset = new Employees_TypedDataSet();
         adapter = new Employees_TypedDataSetTableAdapters.EmployeesTableAdapter();
         //fill the daset with specific table
         adapter.Fill(dataset.Employees);
         //display data in gridview
         Session["Dataset_session"] = dataset.Employees;
         gvEmployees.DataSource     = Session["Dataset_session"];
         gvEmployees.DataBind();
     }
     catch (Exception)
     {
         objconstmsg = new ConstantMessages();
         Response.Redirect(objconstmsg.strerrorpage);
     }
     finally
     {
         adapter = null;
         dataset = null;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// method name:Grid_Fill
        /// Description: Fill and bind the Gridview
        /// Author:bhumi
        /// Created On:1/6/2015
        /// </summary>
        public void Grid_Fill()
        {
            StringBuilder strbuilder;//string builder for query

            try
            {
                objconstmsg = new ConstantMessages();
                //insert SQLquery in String builder
                strbuilder = new StringBuilder("SELECT EmployeeID,FirstName,LastName,TitleOfCourtesy,CONVERT(nvarchar,BirthDate,110) AS BirthDate,Address,City,Country,HomePhone");
                strbuilder.Append(" FROM");
                strbuilder.Append(" Employees;");
                //connection generation and read the data fro reader
                objcmnfunction = new CommonFunctions();
                //datatable
                dtEmployees = new DataTable();
                //dataset
                dataset     = new Employees_TypedDataSet();
                dtEmployees = objcmnfunction.ConnectionGenerate(strbuilder.ToString());
                //fill the dataset
                dataset.Tables.Add(dtEmployees);
                //store data in grid view
                gvEmployees.DataSource = dtEmployees;
                gvEmployees.DataBind();
            }
            catch (Exception)
            {
                Response.Redirect(objconstmsg.strerrorpage);
            }
            finally
            {
                //objcmnfunction = null;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Event Name:Page Load Event
        /// Description:databinding with gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder strbuilder;//string builder for query

            try
            {
                //insert SQLquery in String builder
                strbuilder = new StringBuilder("SELECT * ");
                strbuilder.Append(" FROM");
                strbuilder.Append(" EmployeeTerritories;");
                //connection generation and read the data fro reader
                objcmnfunction = new CommonFunctions();
                //datatable
                datatable = new DataTable();
                //dataset
                dataset   = new Employees_TypedDataSet();
                datatable = objcmnfunction.ConnectionGenerate(strbuilder.ToString());
                //fill the dataset
                dataset.Tables.Add(datatable);
                //store data in grid view
                gvEmployeeTerritory.DataSource = datatable;
                gvEmployeeTerritory.DataBind();
            }
            catch (Exception)
            {
                objconstmsg = new ConstantMessages();
                Response.Redirect(objconstmsg.strerrorpage);
            }
            finally
            {
                objcmnfunction = null;
                dataset        = null;
                datatable      = null;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Method Name:DropDownList1_SelectedIndexChanged
        /// Description: According to selection of Dropdownlist Textboxes text set
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //SQL objects
            SqlConnection  sqlconn;
            SqlCommand     sqlcmd;
            SqlDataAdapter sqladapter;
            SqlDataReader  sqlreader;

            sqlconn = new SqlConnection();
            StringBuilder    strbuider;
            ConstantMessages objconstmsg;

            try
            {
                if (ddlId.SelectedValue != "0")
                {
                    sqlconn.ConnectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
                    if (sqlconn.State == ConnectionState.Closed)
                    {
                        sqlconn.Open();//open the connection
                    }
                    //insert SQLquery in String builder
                    strbuider = new StringBuilder("SELECT EmployeeID,FirstName,LastName,City,Country ");
                    strbuider.Append(" FROM");
                    strbuider.Append(" Employees");
                    strbuider.Append(" Where EmployeeID='" + ddlId.SelectedItem.Value.ToString() + "'");
                    sqlcmd     = new SqlCommand(strbuider.ToString(), sqlconn);
                    sqladapter = new SqlDataAdapter(sqlcmd);
                    sqlreader  = sqlcmd.ExecuteReader();//Reading data
                    while (sqlreader.Read())
                    {
                        //store the dat in textbox from sql reader
                        txtName.Text     = sqlreader[1].ToString();
                        txtLastname.Text = sqlreader[2].ToString();
                        txtCity.Text     = sqlreader[3].ToString();
                        txtCountry.Text  = sqlreader[4].ToString();
                    }
                    sqlreader = null;
                }
            }

            catch (Exception)
            {
                objconstmsg = new ConstantMessages();
                Server.Transfer(objconstmsg.strerrorpage);
            }
            finally
            {
                if (sqlconn.State == ConnectionState.Open)
                {
                    sqlconn.Close();
                }
                sqlconn    = null;
                sqlcmd     = null;
                sqladapter = null;
                sqlreader  = null;
                strbuider  = null;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Method Name:BtnHAdd_Click
        /// Description: Click on ADD Button Method will be performed
        /// Author: bhumi
        /// Created at:2/6/2015
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnHAdd_Click(object sender, EventArgs e)
        {
            //SQL CONNECTION
            SqlConnection    sqlconn;
            ConstantMessages objconstmsg;

            objconstmsg = new ConstantMessages();
            SqlCommand sqlcmd;

            sqlconn = new SqlConnection();
            StringBuilder strbuilder;

            //DateTime date;
            try
            {
                if (Page.IsPostBack)
                {
                    //date = Convert.ToDateTime(TextBox8_CalendarExtender.SelectedDate);
                    //connectionstring
                    sqlconn.ConnectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
                    //SQLQuery
                    if (sqlconn != null && sqlconn.State == ConnectionState.Closed)
                    {
                        sqlconn.Open();//open the connection
                    }
                    strbuilder = new StringBuilder("insert");
                    strbuilder.Append(" into Employees ");
                    strbuilder.Append(" (LastName,FirstName,TitleOfCourtesy,BirthDate,Address,City,Country,HomePhone)");
                    strbuilder.Append(" values");
                    strbuilder.Append(" ('" + txtLastname.Text + "','" + txtFirstname.Text + "','" + ddlSalutation.SelectedItem.Value.ToString() + "','" + txtbirthday.Text + "','" + txtaddress.Text + "','" + txtCity.Text + "','" + txtCountry.Text + "','" + txtphoneno.Text + "')");
                    sqlcmd = new SqlCommand(strbuilder.ToString(), sqlconn);
                    sqlcmd.ExecuteNonQuery();
                }
            }
            catch (Exception)
            {
                Response.Redirect(objconstmsg.strerrorpage);
            }
            finally
            {
                if (sqlconn.State == ConnectionState.Open)
                {
                    sqlconn.Close();
                    sqlcmd     = null;
                    strbuilder = null;
                    Server.Transfer(objconstmsg.stremp_detailspage);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Event Name:Page Load
        /// Description:databinding with the gridview
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            StringBuilder strbuilder;//string builder for query
            int           EmployeeID;

            try
            {
                EmployeeID = Convert.ToInt32(Request.QueryString[0]);
                //insert SQLquery in String builder
                strbuilder = new StringBuilder("SELECT * ");
                strbuilder.Append(" FROM");
                strbuilder.Append(" EmployeeTerritories");
                strbuilder.Append(" where EmployeeID=" + EmployeeID);
                objcmnfunction = new CommonFunctions();
                objconstmsg    = new ConstantMessages();
                //dataset
                dataset = new Employees_TypedDataSet();
                table   = new DataTable();
                //fill the dataset
                table = objcmnfunction.ConnectionGenerate(strbuilder.ToString());
                if (table.Rows.Count > 0)
                {
                    dataset.Tables.Add(table);
                    //store data in grid view
                    gvEmployeeTerritory.DataSource = table;
                    gvEmployeeTerritory.DataBind();
                }
                else
                {
                    objconstmsg = new ConstantMessages();
                    Response.Write(objconstmsg.strdata_notavailable);
                }
            }
            catch (Exception)
            {
                objconstmsg = new ConstantMessages();
                Response.Redirect(objconstmsg.strdefault1page);
            }
            finally
            {
                objcmnfunction = null;
                dataset        = null;
                table          = null;
                strbuilder     = null;
            }
        }
Exemplo n.º 8
0
 // datatable;
 #region Class Properties,Arraylist & Gridview
 /// <summary>
 /// Event Name:Page Load
 /// Description:databinding using class Properties
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         objsupplierservices = new SupplierServices();
         //give the return value(Arraylist) of Getsupplier Method to Datasource of Gridview
         arraylist = objsupplierservices.GetSuppliers();
         gnSuppliers.DataSource = arraylist;
         gnSuppliers.DataBind();//Bind data
     }
     catch (Exception)
     {
         objconstmsg = new ConstantMessages();
         Server.Transfer(objconstmsg.strerrorpage);
     }
     finally
     {
         objsupplierservices = null;
     }
 }
Exemplo n.º 9
0
        /// <summary>
        /// Method Name:Button1_Click()
        /// Description: Update operation while clicking update button
        /// Author:bhumi
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            ConstantMessages objconst;
            //Sql Objects
            SqlConnection  sqlconn;
            SqlCommand     sqlcmd;
            SqlDataAdapter sqladapter;
            SqlTransaction sqltransact;

            sqlconn = new SqlConnection();
            StringBuilder strbuider;

            if (ddlId.SelectedValue != "0")
            {
                sqlconn.ConnectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;
                if (sqlconn.State == ConnectionState.Closed)
                {
                    sqlconn.Open();                                    //open the connection
                }
                sqltransact = sqlconn.BeginTransaction("Transaction"); //Begin Transaction
                try
                {
                    //insert SQLquery in String builder
                    strbuider = new StringBuilder("UPDATE Employees");
                    strbuider.Append(" SET ");
                    strbuider.Append(" FirstName='" + txtName.Text + "',LastName='" + txtLastname.Text + "' ,City='" + txtCity.Text + "' ,Country='" + txtCountry.Text + "'");
                    strbuider.Append(" Where EmployeeID='" + ddlId.SelectedItem.Value.ToString() + "'");
                    sqlcmd     = new SqlCommand(strbuider.ToString(), sqlconn, sqltransact);
                    sqladapter = new SqlDataAdapter(sqlcmd);
                    sqlcmd.ExecuteNonQuery();
                    sqltransact.Commit();//Commit
                    //Alert Message after data updation
                    objconst = new ConstantMessages();
                    ClientScript.RegisterStartupScript(this.GetType(), "msgbox", objconst.stralertmessage, true);
                    ddlId.SelectedValue = "0";
                    txtName.Text        = "";
                    txtLastname.Text    = "";
                    txtCity.Text        = "";
                    txtCountry.Text     = "";
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    sqltransact.Rollback();//Roll back transaction
                }
                finally
                {
                    if (sqlconn.State == ConnectionState.Open)
                    {
                        sqlconn.Close();
                    }
                    sqlcmd      = null;
                    sqladapter  = null;
                    sqltransact = null;
                    strbuider   = null;
                }
            }
            else
            {
                objconst = new ConstantMessages();
                Response.Write(objconst.strselectEmpId);
            }
        }
Exemplo n.º 10
0
 protected void Page_Load(object sender, EventArgs e)
 {
     objconstmsg = new ConstantMessages();
     Response.Write(objconstmsg.strerrormessage);//error message
 }