コード例 #1
0
    private void BindNewCollectedInfo()
    {
        string[]  code = ddlSeasonYear.Text.Split(new string[] { "20" }, StringSplitOptions.None);
        DataTable dt   = reportObj.GetNewallcollectionList(ddlProduct.SelectedValue, code[1].ToString());

        if (dt.Rows.Count > 0)
        {
            DataTable dtNewPre = new DataTable();
            dtNewPre.Columns.Add("Blending_BatchID");
            dtNewPre.Columns.Add("CollectionQty", typeof(decimal));
            dtNewPre.Columns.Add("CreatedDate", typeof(DateTime));
            dtNewPre.Columns.Add("ProductID", typeof(int));

            DataTable dtNew = new DataTable();
            dtNew.Columns.Add("FarmerID");
            dtNew.Columns.Add("FarmID");
            dtNew.Columns.Add("FarmerName");
            dtNew.Columns.Add("Farmercode");
            dtNew.Columns.Add("PlotCode");
            dtNew.Columns.Add("ProductName");
            dtNew.Columns.Add("Lotnumber");
            dtNew.Columns.Add("CollectionQty", typeof(decimal));
            dtNew.Columns.Add("CreatedDate", typeof(DateTime));
            dtNew.Columns.Add("ProductID", typeof(int));
            dtNew.Columns.Add("OrderID", typeof(int));
            dtNew.Columns.Add("Whether", typeof(string));
            dtNew.Columns.Add("ReceivedBy", typeof(string));
            dtNew.Columns.Add("Remarks", typeof(string));
            foreach (DataRow item in dt.Rows)
            {
                string[] FarmerID        = item["FarmerID"].ToString().Split('@');
                string[] FarmID          = item["FarmID"].ToString().Split('@');
                string[] Lotnumber       = item["Lotnumber"].ToString().Split('@');
                string[] CollectionQty   = item["CollectionQty"].ToString().Split('@');
                string   blendingBatchId = item["Blending_BatchID"].ToString();
                if (!string.IsNullOrEmpty(blendingBatchId) && blendingBatchId.Contains("@"))
                {
                    string[] BlendingBID = item["Blending_BatchID"].ToString().Split('@');
                    if (BlendingBID[0].ToString().Trim() == string.Empty)
                    {
                        string[] FarmerID1      = FarmerID[0].ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] FarmID1        = FarmID[0].ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] Lotnumber1     = Lotnumber[0].ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        string[] CollectionQty1 = CollectionQty[0].ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                        for (int i = 0; i < FarmerID1.Length; i++)
                        {
                            DataRow drNew = dtNew.NewRow();
                            drNew["FarmerID"]      = FarmerID1[i].ToString();
                            drNew["FarmID"]        = FarmID1[i].ToString();
                            drNew["Lotnumber"]     = Lotnumber1[i].ToString();
                            drNew["CollectionQty"] = CollectionQty1[i].ToString();
                            DataTable dtFarmer = orderObj.GetBlendFarmerDetails(FarmerID1[i].ToString(), FarmID1[i].ToString());
                            if (dtFarmer.Rows.Count > 0)
                            {
                                drNew["FarmerName"]  = dtFarmer.Rows[0]["FirstName"].ToString();
                                drNew["Farmercode"]  = dtFarmer.Rows[0]["FarmerCode"].ToString();
                                drNew["CreatedDate"] = Convert.ToDateTime(item["CreatedDate"]);
                                drNew["ProductID"]   = Convert.ToInt32(item["ProductID"]);
                                if (Convert.ToInt32(item["ProductID"]) == 4)
                                {
                                    drNew["ProductName"] = "Organic Cornmint Oil";
                                }
                                else
                                {
                                    drNew["ProductName"] = item["ProductName"].ToString();
                                }

                                drNew["OrderID"] = Convert.ToInt32(item["OrderID"].ToString());
                            }
                            dtNew.Rows.Add(drNew);
                        }
                    }
                }
            }
            decimal farmerCollTotal = dtNew.AsEnumerable().Sum(row => row.Field <decimal>("CollectionQty"));
            lblColleted.Text = Math.Round(farmerCollTotal, 1).ToString();

            DataView dv = dtNew.DefaultView;
            dv.Sort = "CreatedDate asc";
            DataTable sortedDT = dv.ToTable();

            Session["UnitInfo"] = null;
            Session["UnitInfo"] = dtNew;

            gvNewCollect.DataSource = sortedDT;
            gvNewCollect.DataBind();
        }
    }