protected void DataCHView_RowCommand(object sender, GridViewCommandEventArgs e) { //Removes Charge Hours Row from button DataTable CHTable = Session["CHtab"] as DataTable; if (e.CommandName == "RemoveRow") { int index = Convert.ToInt32(e.CommandArgument); float Tothours = Global.TimeToFloat(TotalHoursAppLabel.Text); float Removedhours = Global.TimeToFloat(CHTable.Rows[index]["Hours:Mins"].ToString().Replace(':', ' ')); TotalHoursAppLabel.Text = Global.TimeToString(Tothours - Removedhours); //Deletes a row from table CHTable.Rows[index].Delete(); DataCHView.DataSource = CHTable; DataCHView.DataBind(); Session["CHtab"] = CHTable; } }
protected void Page_Load(object sender, EventArgs e) { //will only run when the first instance of a page is loaded if (!IsPostBack) { string userName = Session["UsrName"].ToString(); //Provides Inital data for Infolist beside forms string Name = Global.ReadDataString($"SELECT EMPNAME FROM EMPLOYEES WHERE RESOURCENAME='{Session["UsrName"].ToString()}';"); Ordernumbers = Global.ReadDataList("SELECT DISTINCT ORDERNUMBER FROM ORDERS;"); NameViewLabel.Text = Name; DateViewLabel.Text = Global.DictUsrData[userName].Date; TotalHoursLabel.Text = Global.TimeToString(Global.DictUsrData[userName].TotalHours); TotalHoursAppLabel.Text = "0h 0m"; NCCodeData.Items.Add("Please Select an Order Number"); List <string> NCCodes = Global.ReadDataList("SELECT CODE FROM NONCHARGE;"); foreach (string str in NCCodes) { NCCodeData.Items.Add(str); } StepTaskData.Items.Add("Please Select a Step or Task"); for (int i = 0; i <= 10; i++) { if (i >= 0 && i <= 9) { CHHoursHSelection.Items.Add("0" + Convert.ToString(i)); NCHoursHSelection.Items.Add("0" + Convert.ToString(i)); } else { CHHoursHSelection.Items.Add(Convert.ToString(i)); NCHoursHSelection.Items.Add(Convert.ToString(i)); } } for (int i = 0; i <= 3; i++) { if (i == 0) { CHHoursMSelection.Items.Add("00"); NCHoursMSelection.Items.Add("00"); } else { CHHoursMSelection.Items.Add(Convert.ToString(i * 15)); NCHoursMSelection.Items.Add(Convert.ToString(i * 15)); } } //Creates DataTables for data to be inputed into. This is for both Jobs and Assemblies and for Non-Charge Activities aswell. DataTable CHTable = new DataTable(); CHTable.Columns.Add("Job/Assy"); CHTable.Columns.Add("Number"); CHTable.Columns.Add("Step/Task"); CHTable.Columns.Add("Hours:Mins"); CHTable.Columns.Add("WyEU REF"); CHTable.Columns.Add("EU Step/Task"); CHTable.Columns.Add("EU Cust"); CHTable.Columns.Add("Customer"); DataCHView.DataSource = CHTable; DataCHView.DataBind(); Session["CHtab"] = CHTable; DataTable NCTable = new DataTable(); NCTable.Columns.Add("NC Code"); NCTable.Columns.Add("Hours:Mins"); NCTable.Columns.Add("Non-Charge Comment"); DataNCView.DataSource = NCTable; DataNCView.DataBind(); Session["NCtab"] = NCTable; } }
protected void BtnCHTableADDClick(object sender, EventArgs e) { bool containsValue = false; DataTable CHTable = Session["CHtab"] as DataTable; //checks weather a step or task has already been inputed into the data table. foreach (DataRow dr in CHTable.Rows) { if (dr["Step/Task"].ToString() == StepTaskData.SelectedValue && dr["Number"].ToString() == OrderNumberInput.Text) { containsValue = true; } } //Checks weather forms are filled in before allowing user to input data. string inputData = OrderNumberInput.Text; inputData = inputData.Replace(" ", string.Empty); inputData = inputData.Replace("'", string.Empty); inputData = inputData.Replace(";", string.Empty); inputData = inputData.ToUpper(); string result = Global.ReadDataString("SELECT FIRST 1 ORDERNUMBER FROM ORDERS WHERE ORDERNUMBER='" + inputData + "';"); if (result == "") { Response.Write("<script>alert('Entered Order number is invalid. Please review what you have entered and try again.');</script>"); StepTaskData.Items.Clear(); StepTaskData.Enabled = false; return; } if (StepTaskData.SelectedValue == "Please Select a Step or Task" || CHHoursHSelection.SelectedValue == "00" && CHHoursMSelection.SelectedValue == "00") { Response.Write("<script>alert('Some fields do not have data please make sure that all fields are filled before adding a row.');</script>"); } else if (containsValue == true) { Response.Write("<script>alert('You have already inputed this Step or Task for this Order Number please remove and try again.');</script>"); } else { //Adds data to tables and allows it to be viewed. DataRow dr = CHTable.NewRow(); dr["Job/Assy"] = JobAssyData.Text; dr["Number"] = OrderNumberInput.Text; dr["Step/Task"] = StepTaskData.SelectedValue; dr["Hours:Mins"] = CHHoursHSelection.SelectedValue + ":" + CHHoursMSelection.SelectedValue; dr["WyEU REF"] = WyEUrefData.Text; dr["EU Step/Task"] = EUStepData.Text; dr["EU Cust"] = EUCustData.Text; dr["Customer"] = CustData.Text; CHTable.Rows.Add(dr); DataCHView.DataSource = CHTable; DataCHView.DataBind(); Session["CHtab"] = CHTable; //Updates the amount of hours applied(Addition) float Tothours = Global.TimeToFloat(TotalHoursAppLabel.Text); float Addedhours = Global.TimeToFloat(CHHoursHSelection.Text + " " + CHHoursMSelection.Text); TotalHoursAppLabel.Text = Global.TimeToString(Tothours + Addedhours); } }