private void button2_Click(object sender, EventArgs e) { try { DBManager manager = new DBManager(); SqlConnection connection = manager.Connection(); String query = "select * from Temp_Sell_Counter"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); List <TempSell> tempSells = new List <TempSell>(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt16(reader[0]); string bookname = reader[1].ToString(); string writer = reader[2].ToString(); string edition = reader[3].ToString(); string type = reader[4].ToString(); string print = reader[5].ToString(); int quantity = Convert.ToInt16(reader[6]); double unitpirce = Convert.ToDouble(reader[7]); double total = Convert.ToDouble(reader[8]); double pay = Convert.ToDouble(reader[9]); double due = Convert.ToDouble(reader[10]); int memoNumber = Convert.ToInt16(reader[11]); TempSell aSell = new TempSell(); aSell.Id = id; aSell.BookName = bookname; aSell.WriterName = writer; aSell.Edition = edition; aSell.Type = type; aSell.Print = print; aSell.Quantity = quantity; aSell.Unitprice = unitpirce; aSell.Total = total; aSell.Pay = pay; aSell.Due = due; aSell.Memonumber = memoNumber; tempSells.Add(aSell); } connection.Close(); SellReprotUI sellReprot = new SellReprotUI(tempSells); sellReprot.ShowDialog(); System.Windows.Forms.DialogResult dialog = MessageBox.Show("Did you print the document?", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); SqlCommand command1; String deletequery = "delete from Temp_Sell_Counter"; if (dialog == DialogResult.Yes) { command1 = new SqlCommand(deletequery, connection); connection.Open(); command1.ExecuteNonQuery(); string que = "DBCC CHECKIDENT (Temp_Sell_Counter,Reseed,0)"; command1 = new SqlCommand(que, connection); command1.ExecuteNonQuery(); string que1 = "set identity_insert Temp_Sell_Counter on"; command1 = new SqlCommand(que1, connection); command1.ExecuteNonQuery(); string insQuery = "insert into Memo_Counter values(@date)"; command1 = new SqlCommand(insQuery, connection); command1.Parameters.Clear(); command1.Parameters.AddWithValue("@date", DateTime.Now.Date); command1.ExecuteNonQuery(); memoNumver = GetLastMemoNumber(); } else if (dialog == DialogResult.No) { System.Windows.Forms.DialogResult dialog1 = MessageBox.Show("Are you want to print now?", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialog1 == DialogResult.Yes) { sellReprot = new SellReprotUI(tempSells); sellReprot.ShowDialog(); connection.Open(); command1 = new SqlCommand(deletequery, connection); command1.ExecuteNonQuery(); string que = "DBCC CHECKIDENT (Temp_Sell_Counter,Reseed,0)"; command1 = new SqlCommand(que, connection); command1.ExecuteNonQuery(); string que1 = "set identity_insert Temp_Sell_Counter on"; command1 = new SqlCommand(que1, connection); command1.ExecuteNonQuery(); string insQuery = "insert into Memo_Counter values(@date)"; command1 = new SqlCommand(insQuery, connection); command1.Parameters.Clear(); command1.Parameters.AddWithValue("@date", DateTime.Now.Date); command1.ExecuteNonQuery(); memoNumver = GetLastMemoNumber(); DialogResult d2 = MessageBox.Show(" Print Sucessful! Are you want ot exit? ", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (d2 == DialogResult.Yes) { this.Close(); } else if (d2 == DialogResult.No) { } } else if (dialog1 == DialogResult.No) { this.Close(); } } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button2_Click(object sender, EventArgs e) { try { DBManager manager = new DBManager(); SqlConnection connection = manager.Connection(); String query = "select * from Temp_Sell_Counter"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); List<TempSell> tempSells = new List<TempSell>(); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { int id = Convert.ToInt16(reader[0]); string bookname = reader[1].ToString(); string writer = reader[2].ToString(); string edition = reader[3].ToString(); string type = reader[4].ToString(); string print = reader[5].ToString(); int quantity = Convert.ToInt16(reader[6]); double unitpirce = Convert.ToDouble(reader[7]); double total = Convert.ToDouble(reader[8]); double pay = Convert.ToDouble(reader[9]); double due = Convert.ToDouble(reader[10]); int memoNumber = Convert.ToInt16(reader[11]); TempSell aSell = new TempSell(); aSell.Id = id; aSell.BookName = bookname; aSell.WriterName = writer; aSell.Edition = edition; aSell.Type = type; aSell.Print = print; aSell.Quantity = quantity; aSell.Unitprice = unitpirce; aSell.Total = total; aSell.Pay = pay; aSell.Due = due; aSell.Memonumber = memoNumber; tempSells.Add(aSell); } connection.Close(); SellReprotUI sellReprot = new SellReprotUI(tempSells); sellReprot.ShowDialog(); System.Windows.Forms.DialogResult dialog = MessageBox.Show("Did you print the document?", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); SqlCommand command1; String deletequery = "delete from Temp_Sell_Counter"; if (dialog == DialogResult.Yes) { command1 = new SqlCommand(deletequery, connection); connection.Open(); command1.ExecuteNonQuery(); string que = "DBCC CHECKIDENT (Temp_Sell_Counter,Reseed,0)"; command1 = new SqlCommand(que, connection); command1.ExecuteNonQuery(); string que1 = "set identity_insert Temp_Sell_Counter on"; command1 = new SqlCommand(que1, connection); command1.ExecuteNonQuery(); string insQuery = "insert into Memo_Counter values(@date)"; command1 = new SqlCommand(insQuery, connection); command1.Parameters.Clear(); command1.Parameters.AddWithValue("@date", DateTime.Now.Date); command1.ExecuteNonQuery(); memoNumver = GetLastMemoNumber(); } else if (dialog == DialogResult.No) { System.Windows.Forms.DialogResult dialog1 = MessageBox.Show("Are you want to print now?", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dialog1 == DialogResult.Yes) { sellReprot = new SellReprotUI(tempSells); sellReprot.ShowDialog(); connection.Open(); command1 = new SqlCommand(deletequery, connection); command1.ExecuteNonQuery(); string que = "DBCC CHECKIDENT (Temp_Sell_Counter,Reseed,0)"; command1 = new SqlCommand(que, connection); command1.ExecuteNonQuery(); string que1 = "set identity_insert Temp_Sell_Counter on"; command1 = new SqlCommand(que1, connection); command1.ExecuteNonQuery(); string insQuery = "insert into Memo_Counter values(@date)"; command1 = new SqlCommand(insQuery, connection); command1.Parameters.Clear(); command1.Parameters.AddWithValue("@date", DateTime.Now.Date); command1.ExecuteNonQuery(); memoNumver = GetLastMemoNumber(); DialogResult d2 = MessageBox.Show(" Print Sucessful! Are you want ot exit? ", "Print Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (d2 == DialogResult.Yes) { this.Close(); } else if (d2 == DialogResult.No) { } } else if (dialog1 == DialogResult.No) { this.Close(); } } } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }