Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
DataTable ProTable = new DataTable();
          ProTable.Columns.Add("Product Code", typeof(string));
          ProTable.Columns.Add("ProdDesc", typeof(string));
          ProTable.Columns.Add("UOM", typeof(string));
          ProTable.Columns.Add("OnHand", typeof(string));
          ProTable.Columns.Add("Price", typeof(string));
          ProTable.Columns.Add("Amount", typeof(string));

           //int coutn = 0;
           //Pr_Bar.Visible = true;
           //Pr_Bar.Minimum = 0;
           ////sqlstr = sdbll.Count(ppbel);
           ////Pr_Bar.Maximum =Convert.ToInt32(sdbll.get_data(sqlstr));
           //ProTable.Rows.Clear();
           probel.prod_cate = Ddl_Brand.Text;
          Dgv_Summary.DataSource = srbll.CategoryData(probel, stock , dblAmount);
          prodmax = srbll.prodmax(probel, prod_max);
          for (int i = 0; i < Dgv_Summary.RowCount; i++)
          {
              //for (int j = 2; j < Dgv_Summary.ColumnCount; j++)
              //{
              //    if (Dgv_Summary[j, i].Value != null)
              //    {
                      try
                      {
                          double ProdPrice =IsNumber(prodmax.ToString());
                          stock = int.Parse(srbll.getonhand(sqldateconverion(Dtp_ToDate.Value), Dgv_Summary[0, i].Value.ToString(), probel.comp_id.ToString()));
                          dblAmount = Convert.ToDouble(((stock * ProdPrice).ToString()));
                          ProTable.Rows.Add(Dgv_Summary[0, i].Value.ToString(), Dgv_Summary[1, i].Value.ToString(), Dgv_Summary[2, i].Value.ToString(),
                               stock, ProdPrice, dblAmount);
                      }
                      catch { }
              //    }
              //}
          }


          //coutn++;
          //try
          //{
          //    Pr_Bar.Value = coutn;
          //}
          //catch { }
          //Pr_Bar.Visible = false;
          Dgv_Summary.DataSource = ProTable;
          Dgv_Summary.Columns["Product Code"].Width = 100;
          Dgv_Summary.Columns["ProdDesc"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
          Dgv_Summary.Columns["UOM"].Width = 100;
          Dgv_Summary.Columns["OnHand"].Width = 100;
          Dgv_Summary.Columns["Price"].Width = 100;
          Dgv_Summary.Columns["Amount"].Width = 100;
          Dgv_Summary.Columns["OnHand"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
          Dgv_Summary.Columns["Price"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
          Dgv_Summary.Columns["Amount"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
          //lbl_TotalAmount.Text = ProTable.Compute(Convert.ToString("Sum(Amount)"), "").ToString();
          //DataRow[] dr = ProTable.Select("SUM(Amount)");
          //lbl_TotalAmount.Text = Convert.ToString(dr[0]);
         decimal sum = 0;
          foreach (DataRow dr in ProTable.Rows)
          {
              sum +=Convert.ToDecimal(dr["Amount"].ToString());
          }
          lbl_TotalAmount.Text = sum.ToString();
       }
       public double IsNumber(string strData)
       {
           double Num;
           double fnum = 0;
           Boolean isNum = double.TryParse(strData, out Num);
           if (isNum == true)
               fnum = Convert.ToDouble(strData);
           return fnum;

       }



STORED PROCEDURE
SQL
ALTER procedure [dbo].[SP_StockReport_Category]
@prod_cate nvarchar(30)

as begin
select prod_code as[Product Code], prod_desc as[Description], prod_uom as UOM ,prod_max from products
where prod_cate=@prod_cate  and comp_id=1 and prod_deleted=0 and prod_stock=1 and prod_suspend = 0 order by prod_code

end


DAL
C#
public DataTable CategoryData(ProductBEL probel, int stock, double dblAmount)
    {
        if (cn.State != ConnectionState.Open)
            cn.Open();
        cmd.Connection = cn;
        cmd = new SqlCommand("SP_StockReport_Category", cn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@prod_cate", probel.prod_cate);
        //cmd.Parameters.AddWithValue("@prodcode", prod_code);
        sda = new SqlDataAdapter(cmd);
        ds = new DataSet();
        sda.Fill(ds, "products");

        return ds.Tables["products"];

    }
    public double prodmax(ProductBEL probel, double prodmax)
    {
        if (cn.State != ConnectionState.Open)
            cn.Open();
        cmd.Connection = cn;
        cmd = new SqlCommand("SP_StockReport_Category", cn);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@prod_cate", probel.prod_cate);
        //cmd.Parameters.AddWithValue("@prodcode",prod_code);
        tdr = cmd.ExecuteReader();
        while (tdr.Read())
        {
            prodmax =Convert.ToDouble( tdr["prod_max"].ToString());
        }
        tdr.Close();
        return prodmax;


    }
Posted
Updated 12-Sep-14 20:47pm
v2

1 solution

You can't return more than one value in a single double: that's like trying to fit a dozen apples in one hand!
A double holds one single value: if you want to return more than than, then you would need a collection
of some form:
C#
public List<double> prodmax(ProductBEL probel)
{
    if (cn.State != ConnectionState.Open)
        cn.Open();
    cmd.Connection = cn;
    cmd = new SqlCommand("SP_StockReport_Category", cn);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@prod_cate", probel.prod_cate);
    //cmd.Parameters.AddWithValue("@prodcode",prod_code);
    tdr = cmd.ExecuteReader();
    List<double>>prodmax = new List>double<();
    while (tdr.Read())
    {
        prodmax.Add(Convert.ToDouble( tdr["prod_max"].ToString()));
    }
    tdr.Close();
    return prodmax;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900