Exemple #1
0
    //Method called when the update and confirm button has been pressed
    protected void EmployeeGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Collects info from edited lines in the table
        GridViewRow row = (GridViewRow)EmployeeGridView.Rows[e.RowIndex];

        Label   textid    = EmployeeGridView.Rows[e.RowIndex].FindControl("lbl_ID") as Label;
        TextBox textAdmin = (TextBox)row.Cells[4].Controls[0];
        TextBox textDepID = (TextBox)row.Cells[5].Controls[0];
        TextBox textPhone = (TextBox)row.Cells[7].Controls[0];
        TextBox textEmail = (TextBox)row.Cells[8].Controls[0];

        //Converts the admin text from yes or no into a 1/0 bit
        textAdmin.Text = textAdmin.Text == "YES" ? "1" : "0";

        //Resets the edit index
        EmployeeGridView.EditIndex = -1;

        //A new transactionscope is sent and returns and displays whether it is successful or not
        if (CreateTransactionScope.MakeTransactionScope(String.Format("Exec EmployeeModal @Action = 'Update', @EmployeeID = '{0}', @Admin = '{1}', @DepartmentID = '{2}', @Email = '{3}', @Phone = '{4}'",
                                                                      textid.Text, textAdmin.Text, textDepID.Text, textEmail.Text, textPhone.Text)) > 0)
        {
            //Sets the label text to saying the transaction was successful
            emplbl.Text    = "Employee was successfully edited";
            emplbl.Visible = true;
        }
        else
        {
            //Sets the label text to saying the transaction was not successful
            emplbl.Text    = "One or more fields were invalid changes reverted";
            emplbl.Visible = true;
        }

        //The table is refreshed
        Binding(Base.RefreshTable());
    }
    //Method called when pressing the update button
    protected void DepartmentsGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Collects info from edited lines in the table
        GridViewRow row      = (GridViewRow)DepartmentsGridView.Rows[e.RowIndex];
        Label       textid   = DepartmentsGridView.Rows[e.RowIndex].FindControl("lbl_DID") as Label;
        TextBox     textName = (TextBox)row.Cells[3].Controls[0];


        //Resets the edit index
        DepartmentsGridView.EditIndex = -1;

        //A new transactionscope is sent and returns and displays whether it is successful or not
        if (CreateTransactionScope.MakeTransactionScope(String.Format("Exec DepartmentModal @Action = 'Update', @ID = '{0}', @Name = '{1}'", textid.Text, textName.Text)) > 0)

        {
            //Sets the label text to saying the transaction was successful
            deplbl.Text    = "Department was successfully edited";
            deplbl.Visible = true;
        }
        else
        {
            //Sets the label text to saying the transaction was not successful
            deplbl.Text    = "One or more fields were invalid changes reverted";
            deplbl.Visible = true;
        }
        //The table is refreshed
        Binding(Base.RefreshTable());
    }
Exemple #3
0
    //Enabled once editing has been enabled and a change a has been made.
    protected void SaveChange_Click(object sender, EventArgs e)
    {
        //Add checks and warnings here to make sure info is properly formatted.


        string[] update = new string[5];

        update[0] = Phone.Text == "" ? "NULL" : Phone.Text;
        update[1] = HomeAddr.Text == "" ? "NULL" : HomeAddr.Text;
        update[2] = City.Text == "" ? "NULL" : City.Text;
        update[3] = Zip.Text == "" ? "NULL" : Zip.Text;
        update[4] = DropDownListState.SelectedValue == "-1" ? "NULL" : DropDownListState.SelectedValue;

        string updatequery = "UPDATE Employees SET Phone ='" + update[0] + "', HomeAddress ='" + update[1] + "', City ='" + update[2] + "', Zip ='" + update[3] + "', State ='" + update[4] + "' WHERE Email ='" + Email.Text + "'";

        //send update query here
        CreateTransactionScope.MakeTransactionScope(updatequery);
        SaveChange.Enabled = false;

        //Sets all the bottom section textboxes back to being uneditable and reverts their style.
        Phone.ReadOnly            = true;
        HomeAddr.ReadOnly         = true;
        City.ReadOnly             = true;
        Zip.ReadOnly              = true;
        DropDownListState.Enabled = false;
        Phone.CssClass            = "form-control-plaintext";
        HomeAddr.CssClass         = "form-control-plaintext";
        City.CssClass             = "form-control-plaintext";
        Zip.CssClass              = "form-control-plaintext";
        SaveChange.CssClass       = "btn btn-outline-dark";
    }
    protected void ItemLookUpGridView_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        //Finding the controls from Gridview for the row which is going to update



        GridViewRow row = (GridViewRow)ItemLookUpGridView.Rows[e.RowIndex];

        Label   textid     = ItemLookUpGridView.Rows[e.RowIndex].FindControl("lbl_SKU") as Label;
        TextBox textName   = (TextBox)row.Cells[3].Controls[0];
        TextBox textLocID  = (TextBox)row.Cells[4].Controls[0];
        TextBox textOnH    = (TextBox)row.Cells[5].Controls[0];
        TextBox textToQ    = (TextBox)row.Cells[6].Controls[0];
        TextBox textPrice  = (TextBox)row.Cells[7].Controls[0];
        TextBox textStatus = (TextBox)row.Cells[9].Controls[0];
        TextBox textSupID  = (TextBox)row.Cells[10].Controls[0];
        TextBox textCom    = (TextBox)row.Cells[11].Controls[0];


        ItemLookUpGridView.EditIndex = -1;

        if (CreateTransactionScope.MakeTransactionScope(String.Format("EXEC ItemModal @Action = 'Update', @SKU = '{0}', @Name = '{1}', @Price = '{2}', @Quantity = '{3}', @OnHand = '{4}', @SupplierID = '{5}', @Comments = '{6}', @LocationID = '{7}'",
                                                                      textid.Text, textName.Text, textPrice.Text, textToQ.Text, textOnH.Text, textSupID.Text, textCom.Text, textLocID.Text)) > 0)
        {
            itemlbl.Text    = "Item was successfully edited";
            itemlbl.Visible = true;
        }
        else
        {
            itemlbl.Text    = "One or more fields were invalid changes reverted";
            itemlbl.Visible = true;
        }

        Binding(Base.RefreshTable());
    }
Exemple #5
0
    //Used and called when details button is pressed on the gridview
    protected void GridView1_OnRowCommand(object sender, GridViewCommandEventArgs e)
    {
        //Used to see which command on the row is being called
        if (e.CommandName == "Details")
        {
            //converts retrieved command argument to int for index
            int         index = Convert.ToInt32(e.CommandArgument.ToString());
            GridViewRow row   = PurchaseOrdersGridView.Rows[index];

            //temporary array to store all needed strings for string query
            string[] squery = { row.Cells[0].Text, row.Cells[2].Text, row.Cells[3].Text, row.Cells[4].Text };
            //appends array strings to be sent to response redirect
            string qstring = "/purchaseorderlines.aspx?purchid=" + squery[0] + "&name=" + squery[1] + "&odate=" + squery[2] + "&ddate=" + squery[3];

            //Redirects and attaches purchid of purchase order to query string
            Response.Redirect(qstring);
        }
        else if (e.CommandName == "ConfDeliv")
        {
            int         index = Convert.ToInt32(e.CommandArgument.ToString());
            GridViewRow row   = PurchaseOrdersGridView.Rows[index];

            CreateTransactionScope.MakeTransactionScope(String.Format("Update PurchaseOrder SET DateDelivered = '{0}' WHERE PurchID = '{1}'", DateTime.Now, row.Cells[0].Text));
            this.Binding(Base.RefreshTable());
        }
    }
    protected void createEmployeeButton_Click(object sender, EventArgs e)
    {
        if (efirsttxt.Text != "" && elasttxt.Text != "" && emailtxt.Text != "" && passwordtxt.Text != "" && tempassconftxt.Text != "" && (passwordtxt.Text.Equals(tempassconftxt.Text)))
        {
            string admin = "0";
            string eid   = ""; //default value if no previous items are in the
            try
            {
                SqlConnection con = new SqlConnection(ConnectionString.GetConnectionString("invDBConStr"));
                con.Open();

                SqlCommand     com       = new SqlCommand("SELECT MAX(EmployeeID) FROM Employees", con); // table name
                SqlDataAdapter da        = new SqlDataAdapter(com);
                SqlDataReader  empRecord = com.ExecuteReader();
                if (empRecord.Read())
                {
                    eid = (string)empRecord[0];

                    if (eid != "")
                    {
                        int skunum = Int32.Parse(eid.Substring(eid.LastIndexOf('-') + 1)) + 1;
                        eid = "E-" + string.Format("{0:0000}", skunum);
                    }
                    else
                    {
                        eid = "E-0001";
                    }
                }
                con.Close();
            }
            catch (SqlException exception)
            {
                // errorLabel.Visible = true;
                // errorLabel.Text = "An unknown error occurred, please try again later.";
            }

            if (yesToggle.Checked)
            {
                admin = "1";
            }

            if (CreateTransactionScope.MakeTransactionScope(String.Format("Exec EmployeeModal @Action = 'Insert', @EmployeeID = '{0}', @FirstName ='{1}', @LastName = '{2}', @Admin = '{3}', @DepartmentID = '{4}', @Pass = '******', @LastLogged = '{6}', @Email = '{7}'"
                                                                          , eid, efirsttxt.Text, elasttxt.Text, admin, DropDownListDep.SelectedValue, ComputeSha256Hash(passwordtxt.Text), DateTime.Now, emailtxt.Text)) > 0)
            {
                employeestatuslabel.Text    = "Employee successfully added";
                employeestatuslabel.Visible = true;
            }
            else
            {
                employeestatuslabel.Text    = "Employee could not be added";
                employeestatuslabel.Visible = true;
            }
        }
        else
        {
            employeestatuslabel.Text    = "One or more fields are incomplete or incorrect";
            employeestatuslabel.Visible = true;
        }
    }
Exemple #7
0
 //Method called when attempting to change passwords
 protected void SendPassChange_Click(object sender, EventArgs e)
 {
     if (NewPass.Text.Equals(NewPassConf.Text) && EntCurPassword.Text != "" && EntCurPassword.Text != NewPass.Text)
     {                                                                                                                                                                  //Checks to make sure the new password boxes match and the current password is not null as well as making sure the old and new password do not match.
         if (Checkpassword())                                                                                                                                           //Checks to see if the given password matches the current password
         {
             CreateTransactionScope.MakeTransactionScope("UPDATE Employees SET Password ='******' WHERE Email ='" + Email.Text + "'"); //Generates a new hash for the new password and updates the database with it.
         }
     }
 }
    protected void ItemLookUpGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label textid = ItemLookUpGridView.Rows[e.RowIndex].FindControl("lbl_SKU") as Label;

        if (CreateTransactionScope.MakeTransactionScope("EXEC Deleteitem @SKU ='" + textid.Text + "'") > 0)
        {
            itemlbl.Text    = "Item has been successfully deleted";
            itemlbl.Visible = true;
        }
        else
        {
            itemlbl.Text    = "Item could not be deleted";
            itemlbl.Visible = true;
        }

        Binding(Base.RefreshTable());
    }
    //Method called when delete button is pressed and confirmed
    protected void DepartmentsGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //Fetches the id of the employee in the row
        Label dltID = DepartmentsGridView.Rows[e.RowIndex].FindControl("lbl_DID") as Label;

        //Attempts to delete the selected employee
        if (CreateTransactionScope.MakeTransactionScope(String.Format("DELETE FROM Departments WHERE DepartmentID = '{0}'", dltID.Text)) > 0)
        {
            deplbl.Text    = "Department was successfully deleted";
            deplbl.Visible = true;
        }
        else
        {
            deplbl.Text    = "Department could not be deleted";
            deplbl.Visible = true;
        }
        //Refreshes the table
        Binding(Base.RefreshTable());
    }
Exemple #10
0
    //Method called when delete button is pressed and confirmed
    protected void EmployeeGridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        //Fetches the id of the employee in the row
        Label dltID = EmployeeGridView.Rows[e.RowIndex].FindControl("lbl_ID") as Label;


        //Attempts to delete the selected employee
        if (CreateTransactionScope.MakeTransactionScope(String.Format("Exec DeleteEmployee @ID = '{0}'", dltID.Text)) > 0)
        {
            dltID.Text    = "Employee was successfully deleted";
            dltID.Visible = true;
        }
        else
        {
            dltID.Text    = "Employee could not be deleted";
            dltID.Visible = true;
        }

        //Refreshes the table
        Binding(Base.RefreshTable());
    }
 // Method called when pressing the create department button on the modal
 protected void createDepartmentButton_Click(object sender, EventArgs e)
 {
     if (depIDTxt.Text != "" && depNameTxt.Text != "")
     {
         if (CreateTransactionScope.MakeTransactionScope("EXEC DepartmentModal @Action = 'Insert', @ID ='D-" + depIDTxt.Text + "', @Name = '" + depNameTxt.Text + "'") > 0)
         {
             departmentstatuslabel.Text    = "Department successfully added";
             departmentstatuslabel.Visible = true;
         }
         else
         {
             departmentstatuslabel.Text    = "Department could not be added";
             departmentstatuslabel.Visible = true;
         }
     }
     else
     {
         departmentstatuslabel.Text    = "One or more fields are incomplete or incorrect";
         departmentstatuslabel.Visible = true;
     }
 }
    protected void CreatePOButton_Click(object sender, EventArgs e)
    {
        dt = ViewState["ordertable"] as DataTable;
        //Transaction scope here
        if (dt != null && dt.Rows.Count > 0) //checks to see if the bottom grid has any rows or is empty
        {
            string pid = "P-001";

            try
            {
                SqlConnection con = new SqlConnection(ConnectionString.GetConnectionString("invDBConStr"));
                con.Open();

                SqlCommand     com       = new SqlCommand("SELECT MAX(PurchID) FROM PurchaseOrder", con); // table name
                SqlDataAdapter da        = new SqlDataAdapter(com);
                SqlDataReader  empRecord = com.ExecuteReader();
                if (empRecord.Read())
                {
                    pid = (string)empRecord[0];

                    if (pid != "")
                    {
                        int skunum = Int32.Parse(pid.Substring(pid.LastIndexOf('-') + 1)) + 1;
                        pid = "P-" + string.Format("{0:000}", skunum);
                    }
                    else
                    {
                        pid = "P-001";
                    }
                }
                con.Close();


                //Attempts to create new purchase order with automatic id and if it can't it gives a warning instead
                if (CreateTransactionScope.MakeTransactionScope(string.Format("EXEC PurchaseOrderModal @Action = 'Insert', @PurchaseID = '{0}', @EmployeeID = '{1}'", pid, Request.Cookies["userInfo"]["emplID"])) > 0)
                {
                    using (var bulkCopy = new SqlBulkCopy(ConnectionString.GetConnectionString("invDBConStr"), SqlBulkCopyOptions.KeepIdentity))
                    {
                        DataTable copyDT;
                        copyDT = dt.Copy();
                        copyDT.Columns.Remove("SupplierID");
                        copyDT.Columns.Remove("Price");
                        copyDT.Columns.Remove("ItemName");
                        copyDT.Columns["Quantity"].ColumnName = "OrdQuantity";
                        DataColumn newcol = new DataColumn("PurchID", typeof(System.String))
                        {
                            DefaultValue = pid
                        };
                        copyDT.Columns.Add(newcol);



                        foreach (DataColumn col in copyDT.Columns)
                        {
                            bulkCopy.ColumnMappings.Add(col.ColumnName, col.ColumnName);
                        }
                        bulkCopy.BulkCopyTimeout      = 300;
                        bulkCopy.DestinationTableName = "PurchaseOrderLine";
                        bulkCopy.WriteToServer(copyDT);

                        POstatuslbl.Text    = "Purchase order successfully added";
                        POstatuslbl.Visible = true;
                    }
                }
                else
                {
                    POstatuslbl.Text    = "Purchase order could not be made";
                    POstatuslbl.Visible = true;
                }
            }

            catch (SqlException exception)
            {
                POstatuslbl.Text    = "Purchase order could not be made";
                POstatuslbl.Visible = true;
            }
        }
        else
        {
            POstatuslbl.Text    = "Purchase order could not be made";
            POstatuslbl.Visible = true;
        }
    }
    protected void createItemButton_Click(object sender, EventArgs e)
    {
        if (itemSKUTxt.Text != "" && itemNameTxt.Text != "" && itemQTYTxt.Text != "" && itemQOHTxt.Text != "" && itemPriceTxt.Text != "")
        {
            string sid = DropDownListsupplier.SelectedValue;
            if (sid == "--New Supplier--")
            {
                string[] suppinfo = new string[4];
                sid = "S-001";

                try
                {
                    SqlConnection con = new SqlConnection(ConnectionString.GetConnectionString("invDBConStr"));
                    con.Open();

                    SqlCommand     com       = new SqlCommand("SELECT MAX(SupplierID) FROM Suppliers", con); // table name
                    SqlDataAdapter da        = new SqlDataAdapter(com);
                    SqlDataReader  empRecord = com.ExecuteReader();
                    if (empRecord.Read())
                    {
                        sid = (string)empRecord[0];

                        if (sid != "")
                        {
                            int skunum = Int32.Parse(sid.Substring(sid.LastIndexOf('-') + 1)) + 1;
                            sid = "S-" + string.Format("{0:000}", skunum);
                        }
                        else
                        {
                            sid = "S-001";
                        }
                    }
                    con.Close();
                }
                catch (SqlException ex)
                {
                    itemstatuslabel.Text    = "Supplier could not be added";
                    itemstatuslabel.Visible = true;
                }
                //Block used to set up string array for inserting new supplier into database and allows for empty phone and name texts
                if ((supEmailTxt.Text == "" || EmailRegexValid.IsValid) && (supPhoneTxt.Text == "" || PhoneRegexValid.IsValid))
                {
                    suppinfo[0] = sid;
                    suppinfo[1] = supNameTxt.Text;
                    suppinfo[2] = supPhoneTxt.Text != "" ? "'" + supPhoneTxt.Text + "'" : "NULL";
                    suppinfo[3] = supEmailTxt.Text != "" ? "'" + supEmailTxt.Text + "'" : "NULL";
                    if (!(supNameTxt.Text != "" && CreateTransactionScope.MakeTransactionScope(String.Format("Insert Into Suppliers VALUES ('{0}', '{1}', {2}, {3})", suppinfo[0], suppinfo[1], suppinfo[2], suppinfo[3])) > 0))
                    {
                        itemstatuslabel.Text    = "Supplier could not be added";
                        itemstatuslabel.Visible = true;
                        return;
                    }
                }
                else
                {
                    itemstatuslabel.Text    = "Supplier could not be added";
                    itemstatuslabel.Visible = true;
                    return;
                }
            }

            if (CreateTransactionScope.MakeTransactionScope(String.Format("Exec ItemModal @Action = 'Insert', @SKU = 'I-{0}', @Name = '{1}', @Quantity = '{2}', @OnHand = '{3}', @Price = '{4}', @SupplierID = '{5}', @EmployeeID = '{6}', @Comments = '{7}'"
                                                                          , itemSKUTxt.Text, itemNameTxt.Text, itemQTYTxt.Text, itemQOHTxt.Text, itemPriceTxt.Text, sid, Request.Cookies["userInfo"]["emplID"], itemCommentsTxt.Text)) > 0) //Sends isnert statement to add new item and also checks to see if it was successfully added or not
            {
                itemstatuslabel.Text    = "Item successfully added";
                itemstatuslabel.Visible = true;
            }
            else
            {
                itemstatuslabel.Text    = "Item could not be added";
                itemstatuslabel.Visible = true;
            }
        }
        else
        {
            itemstatuslabel.Text    = "One or more fields are incomplete or incorrect";
            itemstatuslabel.Visible = true;
        }
    }