public void SaveTempDueRecord(TempDueRecord aTempDueRecord)
      {
          try
          {
              connection = manager.Connection();
              string insertQuery =
                  "insert into TempDueRecord values(@name,@mobile,@forBook,@forCopy,@forOthers,@previousDue,@total,@memoNo)";
              command = new SqlCommand(insertQuery, connection);
              command.Parameters.Clear();
              command.Parameters.AddWithValue("@name", aTempDueRecord.CoustemerName);
              command.Parameters.AddWithValue("@mobile", aTempDueRecord.Mobile);
              command.Parameters.AddWithValue("@forBook", aTempDueRecord.ForBook);
              command.Parameters.AddWithValue("@forCopy", aTempDueRecord.ForCopy);
              command.Parameters.AddWithValue("@forOthers", aTempDueRecord.ForOthers);
              command.Parameters.AddWithValue("@previousDue", aTempDueRecord.PreviousDue);
              command.Parameters.AddWithValue("@total", aTempDueRecord.Total);
              command.Parameters.AddWithValue("@memoNo", aTempDueRecord.MemoNumber);
              connection.Open();
              command.ExecuteNonQuery();
              MessageBox.Show("Saved", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
          }
          catch (Exception exception)
          {
              MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          finally
          {
              connection.Close();
          }

      }
      public List<TempDueRecord> GeTempDueRecords()
      {


          List<TempDueRecord> tempDueRecords = new List<TempDueRecord>();

          try
          {
              connection = manager.Connection();

              string selectQuery = "select * from TempDueRecord";
              command = new SqlCommand(selectQuery, connection);
              connection.Open();
              SqlDataReader reader = command.ExecuteReader();
             
              
              while (reader.Read())
              {

                  if (reader[0].ToString().Equals(""))
                  {
                      MessageBox.Show("There are no avilable Due", "Message", MessageBoxButtons.OK,
                          MessageBoxIcon.Information);
                  }
                  else
                  {
                      TempDueRecord aRecord = new TempDueRecord();
                      aRecord.SerialNo = Convert.ToInt16(reader[0]);
                      aRecord.CoustemerName = reader[1].ToString();
                      aRecord.Mobile = reader[2].ToString();
                      aRecord.ForBook = Convert.ToDouble(reader[3]);
                      aRecord.ForCopy = Convert.ToDouble(reader[4]);
                      aRecord.ForOthers = Convert.ToDouble(reader[5]);
                      aRecord.PreviousDue = Convert.ToDouble(reader[6]);
                      aRecord.Total = Convert.ToDouble(reader[7]);
                      aRecord.MemoNumber = Convert.ToInt16(reader[8]);
                      tempDueRecords.Add(aRecord);
                  }

              }
              
          }
          catch (Exception exception)
          {
              MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          finally
          {
              connection.Close();
          }
          return tempDueRecords;
      } 
        private void saveButton_Click(object sender, EventArgs e)
        {
            try
            {
            DBManager manager6 = new DBManager();
            SqlConnection connection6 = manager6.Connection();
            string selectQuery6 = "insert into  Due_Collection values(@pay,@empty,@payCollection,@date)";
            SqlCommand cmd6 = new SqlCommand(selectQuery6, connection6);
            connection6.Open()
                ;
            cmd6.Parameters.Clear();
            cmd6.Parameters.Add("@pay", "0");
            cmd6.Parameters.Add("@empty", totalDuetextBox.Text);
            cmd6.Parameters.AddWithValue("@payCollection", "0");
            cmd6.Parameters.Add("@date", DateTime.Now.ToShortDateString());


            cmd6.ExecuteNonQuery();

            connection6.Close();

            
                RecordDue aRecordDue = new RecordDue();
                aRecordDue.Name = cnameTextBox.Text;
                aRecordDue.Mobile = cMobileTextBox.Text;
                aRecordDue.Fbook = Convert.ToDouble(forBooktextBox.Text);
                aRecordDue.Fcopy = Convert.ToDouble(forphotocopytextBox.Text);
                aRecordDue.Fothers = Convert.ToDouble(forOThersTextBox.Text);
                aRecordDue.PreviousDue = Convert.ToDouble(previousDueTextBox.Text);
                RecordDueGateway gateway = new RecordDueGateway();
                gateway.SaveDueRecord(aRecordDue);

                listView1.Items.Clear();
                LoadAllBook();

               
                GetAllDueRecord();
                TempDueRecord aRecord=new TempDueRecord();
                aRecord.CoustemerName = cnameTextBox.Text;
                aRecord.Mobile = cMobileTextBox.Text;
                aRecord.ForBook = Convert.ToDouble(forBooktextBox.Text);
                aRecord.ForCopy = Convert.ToDouble(forphotocopytextBox.Text);
                aRecord.ForOthers = Convert.ToDouble(forOThersTextBox.Text);
                aRecord.Total = Convert.ToDouble(totalDuetextBox.Text);
                if (previousDueTextBox.Text.Equals("")||previousDueTextBox.Text.Equals("0"))
                {
                    aRecord.PreviousDue = 0;
                }
                else
                {
                    aRecord.PreviousDue = Convert.ToDouble(previousDueTextBox.Text
                       );    
                }
                aRecord.MemoNumber = memoNumver;
                TempDueRecordGateway DueRecordGateway=new TempDueRecordGateway();
                DueRecordGateway.SaveTempDueRecord(aRecord);


                //DueReportUI dueReportUi=new DueReportUI(cnameTextBox.Text,cMobileTextBox.Text,forBooktextBox.Text,forphotocopytextBox.Text,forOThersTextBox.Text,totalDuetextBox.Text);
                //dueReportUi.ShowDialog();

                //listView1.Items.Clear();
                //LoadAllBook();
                //ClearALLTextbox();
            }
            catch (NullReferenceException exception)
            {
                MessageBox.Show("Please fill every fields properly. ", "Error", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

            }
            catch (Exception exception)
            {
              MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, 
                  MessageBoxIcon.Error);
               
                
            }
        }