public string SaveOrder(Order anOrder)
        {
            try
            {


                if (anOrder.Quantity <= 0)
                {
                    MessageBox.Show("Enter the book quantity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (anOrder.Advance < 0)
                {
                    MessageBox.Show("Enter the advance ammount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //int quantity =;
                     double total = anOrder.Quantity*anOrder.UnitPrice;
                    double due = total - anOrder.Advance;
                    DBManager manager = new DBManager();
                    SqlConnection connection = manager.Connection();
                    string insertQuery = "INSERT INTO Orders values(@name,@phone,@bname,@bwriter,@bEdition,@type,@bPrint,@buyUnitprice,@bQuantity,@unitprice,@total,@advance,@due,@odrderDate,@supplyDate)";

                    //string insertQuery = "INSERT INTO Orders values('" + anOrder.CustomerName + "','" +
                    //                     anOrder.CustomerPhone + "','" + anOrder.BookName + "','" + anOrder.WriterName +
                    //                     "','" + anOrder.Edition + "','" + anOrder.BookPrint + "','" + anOrder.BuyUnitPrice + "','" + anOrder.Quantity + "','" + anOrder.UnitPrice +
                    //                     "','" + total + "','" + anOrder.Advance + "','" + due + "','" +
                    //                     DateTime.Now.ToShortDateString() + "','" + anOrder.SupplyDate + "')";
                    SqlCommand insertCommand = new SqlCommand(insertQuery, connection);
                    connection.Open();
                    insertCommand.Parameters.Clear();
                    insertCommand.Parameters.AddWithValue("@name", anOrder.CustomerName);
                    insertCommand.Parameters.AddWithValue("@phone", anOrder.CustomerPhone);
                    insertCommand.Parameters.AddWithValue("@bname", anOrder.BookName);
                    insertCommand.Parameters.AddWithValue("@bwriter", anOrder.WriterName);
                    insertCommand.Parameters.AddWithValue("@bEdition", anOrder.Edition);
                    insertCommand.Parameters.AddWithValue("@type", anOrder.TypeOfBook);
                    insertCommand.Parameters.AddWithValue("@bPrint", anOrder.BookPrint);
                    insertCommand.Parameters.AddWithValue("@buyUnitprice", anOrder.BuyUnitPrice);
                    insertCommand.Parameters.AddWithValue("@bQuantity", anOrder.Quantity);
                    insertCommand.Parameters.AddWithValue("@unitprice", anOrder.UnitPrice);
                    insertCommand.Parameters.AddWithValue("@total", total);
                    insertCommand.Parameters.AddWithValue("@advance", anOrder.Advance);
                    insertCommand.Parameters.AddWithValue("@due", due);
                    insertCommand.Parameters.AddWithValue("@odrderDate", DateTime.Now.ToShortDateString());
                    insertCommand.Parameters.AddWithValue("@supplyDate", anOrder.SupplyDate);
                   
                    int i = insertCommand.ExecuteNonQuery();
                    
                }
                

            }
            catch (Exception exception)
            {

                MessageBox.Show(exception.Message);
            }
            return " Order Saved";
        }
        public string SaveOrder(Order anOrder)
        {
            try
            {


                if (anOrder.Quantity <= 0)
                {
                    MessageBox.Show("Enter the book quantity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (anOrder.Advance < 0)
                {
                    MessageBox.Show("Enter the advance ammount", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //int quantity =;
                     double total = anOrder.Quantity*anOrder.UnitPrice;
                    double due = total - anOrder.Advance;
                    DBManager manager = new DBManager();
                    SqlConnection connection = manager.Connection();
                    string insertQuery = "INSERT INTO Orders values('" + anOrder.CustomerName + "','" +
                                         anOrder.CustomerPhone + "','" + anOrder.BookName + "','" + anOrder.WriterName +
                                         "','" + anOrder.Edition + "','"+anOrder.BuyUnitPrice+"','" + anOrder.Quantity + "','" + anOrder.UnitPrice +
                                         "','" + total + "','" + anOrder.Advance + "','" + due + "','" +
                                         DateTime.Now.ToShortDateString() + "','" + anOrder.SupplyDate + "')";
                    SqlCommand insertCommand = new SqlCommand(insertQuery, connection);
                    connection.Open();
                    int i = insertCommand.ExecuteNonQuery();
                    
                }
                

            }
            catch (Exception exception)
            {

                MessageBox.Show(exception.Message);
            }
            return " Order Saved";
        }
        public void AllOrder()
        {

            try
            {

                DBManager manager = new DBManager();
                SqlConnection connection = manager.Connection();

                string selectQuery = "SELECT Book_Name,Writer,Edition,Quantity from Orders";
                SqlCommand cmd = new SqlCommand(selectQuery, connection);
                connection.Open();
                order2 = new List<Order>();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    string bookName = reader[0].ToString();
                    string writerName = reader[1].ToString();
                    string edition = reader[2].ToString();
                    string qu = reader[3].ToString();
                    int quantity = Convert.ToInt16(qu);

                    Order anOrder = new Order();
                    anOrder.BookName = bookName;
                    anOrder.WriterName = writerName;
                    anOrder.Edition = edition;
                    anOrder.Quantity = quantity;
                    order2.Add(anOrder);

                }


            }
            catch (SqlException exception)
            {
                MessageBox.Show(exception.Message);
            }


        }
        //save an Order 
        private void orderAcceptButton_Click(object sender, EventArgs e)
        {

            try
            {
                OrderGateway gateway = new OrderGateway();
                Order anOrder = new Order();
                anOrder.CustomerName = customerNameTextBox.Text;
                anOrder.CustomerPhone = customerMobileTextBox.Text;
                anOrder.BookName = bookNameTextBox.Text;
                anOrder.WriterName = writerNameTextBox.Text;
                anOrder.Edition = bookEditionTextBox.Text;
                anOrder.BuyUnitPrice = Convert.ToDouble(buyingUnitPriceTextBox.Text);
                string quantiy = bookQuantityTextBOx.Text;
                anOrder.Quantity = Convert.ToInt16(quantiy);
                anOrder.UnitPrice = Convert.ToDouble(bookUnitPriceTextBOx.Text);
                anOrder.Advance = Convert.ToDouble(advanceTextBox.Text);
                
                anOrder.SupplyDate = dateTimePicker1.Text;
                string st = gateway.SaveOrder(anOrder);
                MessageBox.Show(st,"Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
                ClearALLtextBox();
                LoadAllBook();

                serialTextBox.Text = LastAddedInvestlNo().ToString();
            }
            catch (Exception)
            {
               
                MessageBox.Show("Please fill every fields properly.", "Error", MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
            }


        }
        private void button6_Click_1(object sender, EventArgs e)
        {
            try
            {

                DBManager manager = new DBManager();
                SqlConnection connection = manager.Connection();

                string selectQuery = "SELECT Book_Name,Writer,Edition,Quantity from Orders";
                SqlCommand cmd = new SqlCommand(selectQuery, connection);
                connection.Open();
                List<Order> orders = new List<Order>();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    string bookName = reader[0].ToString();
                    string writerName = reader[1].ToString();
                    string edition = reader[2].ToString();
                    string qu = reader[3].ToString();
                    int quantity = Convert.ToInt16(qu);

                    Order anOrder = new Order();
                    anOrder.BookName = bookName;
                    anOrder.WriterName = writerName;
                    anOrder.Edition = edition;
                    anOrder.Quantity = quantity;
                    orders.Add(anOrder);


                }

                QuantitySelect aQuantitySelect = new QuantitySelect(orders);
                aQuantitySelect.ShowDialog();
            }
            catch (SqlException exception)
            {
                MessageBox.Show(exception.Message);
            }

        }
        //save an Order 
        private void orderAcceptButton_Click(object sender, EventArgs e)
        {
            
            try
            {
                OrderGateway gateway = new OrderGateway();
                Order anOrder = new Order();
                anOrder.CustomerName = customerNameTextBox.Text;
                anOrder.CustomerPhone = customerMobileTextBox.Text;
                anOrder.BookName = bookNameTextBox.Text;
                anOrder.WriterName = writerNameTextBox.Text;
                anOrder.Edition = bookEditionTextBox.Text;
                anOrder.TypeOfBook = typeOfBookTextBox.Text;
                anOrder.BookPrint = bookPrintTextbox.Text;
                anOrder.BuyUnitPrice = Convert.ToDouble(buyingUnitPriceTextBox.Text);
                string quantiy = bookQuantityTextBOx.Text;
                anOrder.Quantity = Convert.ToInt16(quantiy);
                anOrder.UnitPrice = Convert.ToDouble(bookUnitPriceTextBOx.Text);
                anOrder.Advance = Convert.ToDouble(advanceTextBox.Text);
                
                anOrder.SupplyDate = dateTimePicker1.Text;
                
                
                string st = gateway.SaveOrder(anOrder);

                ////InvoiceUI invoice=new InvoiceUI(serialTextBox.Text,customerNameTextBox.Text,customerMobileTextBox.Text,bookNameTextBox.Text,writerNameTextBox.Text,bookEditionTextBox.Text,typeOfBookTextBox.Text,bookPrintTextbox.Text,bookQuantityTextBOx.Text,bookUnitPriceTextBOx.Text,advanceTextBox.Text,dueTextBox.Text,dateTimePicker1.Text);

                //invoice.ShowDialog();
                TempOrder aOrder=new TempOrder();
                aOrder.SerialNo = serialTextBox.Text;
                aOrder.CustomerName = customerNameTextBox.Text;
                aOrder.MobileNo = customerMobileTextBox.Text;
                aOrder.BookName = bookNameTextBox.Text;
                aOrder.WriterName = writerNameTextBox.Text;
                aOrder.Edition = bookEditionTextBox.Text;
                aOrder.Type = typeOfBookTextBox.Text;
                aOrder.Print = bookPrintTextbox.Text;
                aOrder.Quantity = Convert.ToInt16(bookQuantityTextBOx.Text);
                aOrder.Unitprice = Convert.ToDouble(bookUnitPriceTextBOx.Text);
                aOrder.Total =
                    (Convert.ToInt16(bookQuantityTextBOx.Text)*Convert.ToDouble(bookUnitPriceTextBOx.Text));
                aOrder.Advance = Convert.ToDouble(advanceTextBox.Text);
                aOrder.Due = Convert.ToDouble(dueTextBox.Text);

                aOrder.SupplyDate = dateTimePicker1.Text;
                aOrder.MemoNumber = memoNumver;
                TempOrderGateway gateway1=new TempOrderGateway();
                gateway1.SaveTempOrer(aOrder);

                MessageBox.Show(st,"Information",MessageBoxButtons.OK,MessageBoxIcon.Information);

               

                ClearALLtextBox();
                LoadAllBook();

                serialTextBox.Text = LastAddedInvestlNo().ToString();
                CustomerNamteSuggestion();
                AtocompleteTextBox();
                

            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);

                //MessageBox.Show("Please fill every fields properly.", "Error", MessageBoxButtons.OK,
                //        MessageBoxIcon.Error);
            }


        }