//To keep track of delete buttons protected void Page_Load(object sender, EventArgs e) { con = new OdbcConnection(connectionstring); con.Open(); db = new TestEntities(); //Gets next identity number by seeing how many orders are in the system using (OdbcCommand command = new OdbcCommand("SELECT COUNT(*) FROM dbo.InfraOrders", con)) { using (OdbcDataReader reader = command.ExecuteReader()) { reader.Read(); string temp = reader.GetString(0); //If there are 0 rows in the table, the first number is 1 lblOrderNum.Text = (Int32.Parse(temp) + 1).ToString(); } } //Creates temp table to store order lines before order is placed if (!IsPostBack) { try { using (OdbcCommand command = new OdbcCommand("CREATE TABLE ##temp([Line #] int IDENTITY(1,1)," + "[F Code] varchar(10), Description varchar(MAX), [Quantity Per] int, [# of Cont.] int, [Cont. Type] varchar(50)," + "UOM varchar(10), Priority int, [Total RQ] int)", con)) { command.ExecuteNonQuery(); } } catch { using (OdbcCommand command = new OdbcCommand("DELETE dbo.##temp; DBCC CHECKIDENT('##temp', RESEED, 0)", con)) { command.ExecuteNonQuery(); } } } //Must recreate buttons if it is a post back else { PlaceHolder1.Controls.Clear(); double btnHeight = gv1.RowStyle.Height.Value + 27; Unit height = new Unit(btnHeight); for (int i = 0; i < gv1.Rows.Count; ++i) { Button btn = new Button(); btn.Text = "Delete"; btn.Height = gv1.RowStyle.Height; btn.ID = i.ToString(); btn.Click += new EventHandler(btnDelete); PlaceHolder1.Controls.Add(btn); btn.Visible = true; Literal lit = new Literal(); lit.Text = "<br/>"; PlaceHolder1.Controls.Add(lit); } } }
protected void Page_Load(object sender, EventArgs e) { db = new TestEntities(); con = new OdbcConnection(connectionstring); con.Open(); //Creates temp table to store order lines before order is placed if (!IsPostBack) { mainPage = (Page)Context.Handler; gvOrder = (GridView)mainPage.FindControl("gvOrders"); orderNum = Int32.Parse(gvOrder.SelectedRow.Cells[1].Text); lblOrderNum.Text = orderNum.ToString(); custID = Int32.Parse(gvOrder.SelectedRow.Cells[2].Text); //Gets Customer Name for Operator Label var customers = db.Customers.ToList(); var nameList = from customer in customers where customer.ID == custID select customer.Name; List <string> temp = nameList.ToList(); lbOp.Text = temp[0]; try { using (OdbcCommand command = new OdbcCommand("CREATE TABLE ##editTemp([Line #] int IDENTITY(1,1)," + "[F Code] varchar(10), Description varchar(MAX), [Quantity Per] int, [# of Cont.] int, [Cont. Type] varchar(50)," + "UOM varchar(10), Priority int, [Total RQ] int)", con)) { command.ExecuteNonQuery(); } } catch { using (OdbcCommand command = new OdbcCommand("DELETE dbo.##editTemp; DBCC CHECKIDENT('##editTemp', RESEED, 0)", con)) { command.ExecuteNonQuery(); } } //Fills ##editTemp with the selected order's order lines using (OdbcCommand command = new OdbcCommand($"INSERT INTO dbo.##editTemp([F Code], Description, [Quantity Per]," + $"[# of Cont.], [Cont. Type], UOM, Priority, [Total RQ]) SELECT [F Code], Description, [Quantity Per], [# of Cont.]," + $"[Cont. Type], UOM, Priority, [Total RQ] FROM dbo.InfraOrderLines WHERE [Order #] = {orderNum}", con)) { command.ExecuteNonQuery(); } } /*else * { * using (OdbcCommand command = new OdbcCommand("DELETE dbo.##editTemp; DBCC CHECKIDENT('##editTemp', RESEED, 0)", con)) * { * * command.ExecuteNonQuery(); * } * } */ ShowData(); //Recreates buttons from original order PlaceHolder1.Controls.Clear(); double btnHeight = gv1.RowStyle.Height.Value + 27; Unit height = new Unit(btnHeight); for (int i = 0; i < gv1.Rows.Count; ++i) { Button btn = new Button(); btn.Text = "Delete"; btn.Height = gv1.RowStyle.Height; btn.ID = i.ToString(); btn.Click += new EventHandler(btnDelete); PlaceHolder1.Controls.Add(btn); btn.Visible = true; Literal lit = new Literal(); lit.Text = "<br/>"; PlaceHolder1.Controls.Add(lit); } }