//Delete tools from project protected void btnSubToolProduction_Click(object sender, EventArgs e) { try { //Create instance of tool with ID of textbox value var t = new PROD_TOOL { ID = Convert.ToInt32(txtSubToolProduction.Text) }; //Attach records db.PROD_TOOL.Attach(t); //Remove record db.PROD_TOOL.Remove(t); db.SaveChanges(); //Refresh gridview gvToolRequirementProduction.DataBind(); } catch { this.lblErrormsgToolProdcution.Text = "Please select a valid row to delete!"; } //Set textbox back to default this.txtSubToolProduction.Text = ""; }
//Add tools to the production plan protected void btnAddToolProduction_Click(object sender, EventArgs e) { try { //Create a tool instance PROD_TOOL t = new PROD_TOOL(); //Gather information needed to make a tool t.projectID = Convert.ToInt32(this.ddlProjectID.SelectedValue); t.ptQty = Convert.ToByte(this.txtToolQtyEstProduction.Text); t.ptDeliverFrom = Convert.ToDateTime(this.txtToolDeliverFromProduction.Text); t.ptDeliverTo = Convert.ToDateTime(this.txtToolDeliverToProduction.Text); t.toolID = this.ddlToolDescProduction.SelectedIndex + 1; //Sace tool to database db.PROD_TOOL.Add(t); db.SaveChanges(); //Refresh gridview gvToolRequirementProduction.DataBind(); } catch { lblErrormsgToolProdcution.Text = "Something went wrong!"; } //Set textboxes the dropdowns back to defaults this.txtToolQtyEstProduction.Text = ""; this.txtToolDeliverFromProduction.Text = ""; this.txtToolDeliverToProduction.Text = ""; this.ddlToolDescProduction.SelectedIndex = 0; }