예제 #1
0
 public static void CreditSalesItem(DataGridView view, string search)
 {
     try
     {
         if (string.IsNullOrEmpty(search))
         {
             var            query = "SELECT *FROM View_Credit_Sales ORDER BY Sold_Date,Firstname,Item";
             SqlConnection  con   = new DBConnection().getConnection();
             SqlDataAdapter da    = new SqlDataAdapter(query, con);
             DataTable      dt    = new DataTable();
             da.Fill(dt);
             TodayCredit = 0;
             view.Rows.Clear();
             foreach (DataRow dr in dt.Rows)
             {
                 int n = view.Rows.Add();
                 view.Rows[n].Cells[0].Value = dr[0].ToString();
                 view.Rows[n].Cells[1].Value = dr[1].ToString();
                 view.Rows[n].Cells[2].Value = dr[2].ToString();
                 view.Rows[n].Cells[3].Value = dr[3].ToString();
                 view.Rows[n].Cells[4].Value = dr[4].ToString();
                 view.Rows[n].Cells[5].Value = string.Format("{0:00.#0}", dr[5]);
                 view.Rows[n].Cells[6].Value = dr[6].ToString();
                 int credit = Convert.ToInt32(dr[7]);
                 TodayCredit = TodayCredit + credit;
                 view.Rows[n].Cells[7].Value = string.Format("{0:00.#0}", dr[7]);
                 view.Rows[n].Cells[8].Value = string.Format("{0:MM/dd/yyyy}", dr[8]);
                 view.Rows[n].Cells[9].Value = dr[9].ToString();
             }
         }
         else
         {
             var            query = "SELECT *FROM View_Credit_Sales WHERE Item =@search  ORDER BY Sold_Date,Firstname,Item";
             SqlConnection  con   = new DBConnection().getConnection();
             SqlDataAdapter da    = new SqlDataAdapter(query, con);
             da.SelectCommand.Parameters.AddWithValue("@search", SqlDbType.VarChar).Value = search;
             DataTable dt = new DataTable();
             da.Fill(dt);
             TodayCredit = 0;
             view.Rows.Clear();
             foreach (DataRow dr in dt.Rows)
             {
                 int n = view.Rows.Add();
                 view.Rows[n].Cells[0].Value = dr[0].ToString();
                 view.Rows[n].Cells[1].Value = dr[1].ToString();
                 view.Rows[n].Cells[2].Value = dr[2].ToString();
                 view.Rows[n].Cells[3].Value = dr[3].ToString();
                 view.Rows[n].Cells[4].Value = dr[4].ToString();
                 view.Rows[n].Cells[5].Value = string.Format("{0:00.#0}", dr[5]);
                 view.Rows[n].Cells[6].Value = dr[6].ToString();
                 int credit = Convert.ToInt32(dr[7]);
                 TodayCredit = TodayCredit + credit;
                 view.Rows[n].Cells[7].Value = string.Format("{0:00.#0}", dr[7]);
                 view.Rows[n].Cells[8].Value = string.Format("{0:MM/dd/yyyy}", dr[8]);
                 view.Rows[n].Cells[9].Value = dr[9].ToString();
             }
         }
     }
     catch (Exception ex)
     {
         throw new ExceptionHandling("there was error in the search", ex);
     }
 }