protected void btnnext_Click(object sender, EventArgs e)
        {
            DataSet              ds1 = new DataSet();
            DataTable            dt1 = new DataTable();
            iProductMasterClient productClient = new iProductMasterClient();
            iPartRequestClient   objService = new iPartRequestClient();
            CustomProfile        profile = CustomProfile.GetProfile();
            decimal              TotalProdQty = 0m, totalPrice = 0m;
            string   Title = "Direct Order Import";
            string   OrderNumber = "";
            DateTime orderdate = DateTime.Now;

            try
            {
                ds = productClient.GetDistinctPLCodes(profile.DBConnection._constr);
                //ds = productClient.GetDirectOrderData(profile.DBConnection._constr);
                dt = ds.Tables[0];
                for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                {
                    DataSet   ds2         = new DataSet();
                    DataTable dt2         = new DataTable();
                    long      disDeptid   = long.Parse(ds.Tables[0].Rows[i]["deptId"].ToString());
                    long      DisLocId    = long.Parse(ds.Tables[0].Rows[i]["LocID"].ToString());
                    long      CompanyID   = long.Parse(ds.Tables[0].Rows[i]["ParentID"].ToString());
                    long      Orderheadid = 0;
                    ds2 = productClient.GetTotalForOrderHead(disDeptid, DisLocId, profile.DBConnection._constr);
                    dt2 = ds2.Tables[0];
                    if (dt2.Rows.Count > 0)
                    {
                        TotalProdQty = decimal.Parse(dt2.Rows[0]["TotalOrderQty"].ToString());
                        totalPrice   = decimal.Parse(dt2.Rows[0]["GrandTotalPrice"].ToString());
                    }
                    OrderNumber = productClient.getOrderFormatNumber(disDeptid, profile.DBConnection._constr);
                    ds1         = productClient.GetImportDatabyDisDeptLocId(disDeptid, DisLocId, profile.DBConnection._constr);
                    dt1         = ds1.Tables[0];
                    long sequence = 0;
                    for (int j = 0; j <= ds1.Tables[0].Rows.Count - 1; j++)
                    {
                        long UOMID = 16;

                        string  skucode          = ds1.Tables[0].Rows[j]["SKUCode"].ToString();
                        string  SkuName          = ds1.Tables[0].Rows[j]["Name"].ToString();
                        string  Description      = ds1.Tables[0].Rows[j]["Description"].ToString();
                        decimal AvailableBalance = decimal.Parse(ds1.Tables[0].Rows[j]["AvailableBalance"].ToString());
                        decimal RequestQty       = decimal.Parse(ds1.Tables[0].Rows[j]["asRequestQty"].ToString());
                        decimal OrderQty         = decimal.Parse(ds1.Tables[0].Rows[j]["OrderQty"].ToString());
                        decimal Price            = decimal.Parse(ds1.Tables[0].Rows[j]["Price"].ToString());
                        decimal Total            = decimal.Parse(ds1.Tables[0].Rows[j]["Total"].ToString());
                        long    locationid       = long.Parse(ds1.Tables[0].Rows[j]["locationid"].ToString());
                        long    prodID           = long.Parse(ds1.Tables[0].Rows[j]["prodID"].ToString());
                        long    storeID          = long.Parse(ds1.Tables[0].Rows[j]["ID"].ToString());
                        decimal Dispatch         = decimal.Parse(ds1.Tables[0].Rows[j]["TotalDispatchQty"].ToString());
                        //TotalProdQty = TotalProdQty + OrderQty;
                        //totalPrice = totalPrice + Total;
                        long     maxdeldays          = productClient.GetmaxDeliverydays(storeID, profile.DBConnection._constr);
                        DateTime Deliveryday         = DateTime.Now.AddDays(maxdeldays);
                        decimal  CurrentAvailBalance = AvailableBalance - OrderQty;
                        decimal  CurrentDispatchQty  = Dispatch + OrderQty;

                        sequence = sequence + 1;
                        if (j == 0)
                        {
                            Orderheadid = productClient.SaveOrderHeaderImport(storeID, orderdate, Deliveryday, 0, 3, profile.Personal.UserID, DateTime.Now, Title, DateTime.Now, TotalProdQty, totalPrice, OrderNumber, locationid, profile.DBConnection._constr);
                        }
                        productClient.SaveOrderDetailImport(Orderheadid, prodID, OrderQty, UOMID, sequence, SkuName, Description, skucode, Price, Total, profile.DBConnection._constr);
                        productClient.updateproductstockdetailimport(storeID, prodID, CurrentAvailBalance, CurrentDispatchQty, profile.DBConnection._constr);
                    }
                    productClient.ImportMsgTransHeader(Orderheadid, profile.DBConnection._constr);
                    int x = objService.EmailSendWhenRequestSubmit(Orderheadid, profile.DBConnection._constr);

                    DataSet dss = new DataSet();
                    dss = objService.GetApproverDepartmentWise(disDeptid, profile.DBConnection._constr);
                    for (int t = 0; t <= dss.Tables[0].Rows.Count - 1; t++)
                    {
                        long approverid = Convert.ToInt64(dss.Tables[0].Rows[t]["UserId"].ToString());

                        objService.EmailSendofApproved(approverid, Orderheadid, profile.DBConnection._constr);
                    }
                }

                productClient.DeleteOrderImport(profile.DBConnection._constr);
                Response.Redirect("ImportOrderF.aspx");
            }
            catch
            {
                productClient.DeleteSKUPricetemp(profile.DBConnection._constr);
            }
            finally
            {
                productClient.Close();
            }
        }