protected void btInsert_Click(object sender, EventArgs e) { int orderID; SqlCommand command = new SqlCommand("", DBConnection.connection); if (DBConnection.userID == 0) { Response.Redirect("AuthorizationPage.aspx"); } else { decimal Cost; command.CommandType = System.Data.CommandType.Text; command.CommandText = "SELECT (Price) FROM [Product] where [ID_Product] = " + Convert.ToInt32(ddlProduct.SelectedValue) + ""; DBConnection.connection.Open(); Cost = Convert.ToDecimal(command.ExecuteScalar().ToString()); command.ExecuteNonQuery(); DBConnection.connection.Close(); int Sum = Convert.ToInt32(tbQuantity.Text) * Convert.ToInt32(Cost); string time = DateTime.Now.ToString("h:mm"); DateTime theDate = DateTime.ParseExact(tbSaledDate.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); string date = theDate.ToString("dd.MM.yyyy"); DBProcedures dBProcedures = new DBProcedures(); dBProcedures.Order_Insert(Convert.ToInt32(ddlProduct.SelectedValue), Convert.ToInt32(tbQuantity.Text), Convert.ToInt32(ddlClient.SelectedValue), Convert.ToDecimal(Sum)); command.CommandType = System.Data.CommandType.Text; command.CommandText = "SELECT MAX(ID_Order) FROM [Order]"; DBConnection.connection.Open(); orderID = Convert.ToInt32(command.ExecuteScalar().ToString()); command.ExecuteNonQuery(); DBConnection.connection.Close(); dBProcedures.Check_Insert(time, date, DBConnection.userID, orderID); DeleteData(); gvFill(QR); } }
protected void btUpdate_Click(object sender, EventArgs e) { int checkID; DBProcedures dBProcedures = new DBProcedures(); SqlCommand command = new SqlCommand("", DBConnection.connection); if (DBConnection.userID == 0) { Response.Redirect("AuthorizationPage.aspx"); } else { string time = DateTime.Now.ToString("h:mm"); DateTime theDate = DateTime.ParseExact(tbSaledDate.Text, "yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture); string date = theDate.ToString("dd.MM.yyyy"); dBProcedures.Order_Update(DBConnection.selectedRow, Convert.ToInt32(ddlProduct.SelectedValue), Convert.ToInt32(tbQuantity.Text), Convert.ToInt32(ddlClient.SelectedValue)); command.CommandType = System.Data.CommandType.Text; command.CommandText = "SELECT [ID_Check] from [Check] where [Order_ID] = " + Convert.ToString(DBConnection.selectedRow) + ""; DBConnection.connection.Open(); try { checkID = Convert.ToInt32(command.ExecuteScalar().ToString()); } catch { checkID = 0; } command.ExecuteNonQuery(); DBConnection.connection.Close(); if (checkID == 0) { dBProcedures.Check_Insert(time, date, DBConnection.userID, DBConnection.selectedRow); } else { dBProcedures.Check_Update(checkID, time, date, DBConnection.selectedRow, DBConnection.userID); } gvFill(QR); DeleteData(); } }