public List <Key_ValueModel> SubCat_Value(string SCOKID)
        {
            List <Key_ValueModel> result = new List <Key_ValueModel>();
            PDBC          db             = new PDBC();
            ExcParameters par            = new ExcParameters()
            {
                _KEY   = "@SCOKID",
                _VALUE = SCOKID
            };
            List <ExcParameters> pAs = new List <ExcParameters>();

            pAs.Add(par);
            db.Connect();
            using (DataTable dt = db.Select("SELECT [id_SCOV] as id,[SCOVValueName] as [name] FROM [tbl_Product_SubCategoryOptionValue] WHERE[id_SCOK] = @SCOKID", pAs))
            {
                db.DC();
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    var maodel = new Key_ValueModel()
                    {
                        Id    = Convert.ToInt32(dt.Rows[i]["id"]),
                        Value = dt.Rows[i]["name"].ToString()
                    };
                    result.Add(maodel);
                }
            }
            return(result);
        }
        public ActionResult ProductInStockpile(int PSID)
        {
            ProductInStockpileModelView model = new ProductInStockpileModelView();
            PDBC          db  = new PDBC();
            ExcParameters par = new ExcParameters()
            {
                _KEY   = "@id_MPC",
                _VALUE = PSID
            };
            List <ExcParameters> pars = new List <ExcParameters>();

            pars.Add(par);
            string id_MProductReal = "";

            db.Connect();
            using (DataTable dtproduct = db.Select("SELECT [MoneyTypeName],[PQT_Demansion], [id_MProduct],[MultyPriceStartFromQ],[code_Stockpile],[Description],[MultyPrice],[Title],[PricePerquantity] FROM [v_Connector_MainProductConnectorToProduct] WHERE [id_MPC] = @id_MPC", pars))
            {
                db.DC();
                if (dtproduct.Rows.Count > 0)
                {
                    id_MProductReal = dtproduct.Rows[0]["id_MProduct"].ToString();

                    model.ShowPSIDs = new ShowPSID()
                    {
                        id_MPC = PSID.ToString(),
                        MultyPriceStartFromQ = dtproduct.Rows[0]["MultyPriceStartFromQ"].ToString(),
                        PicList                   = new List <string>(),
                        ProductCode               = dtproduct.Rows[0]["code_Stockpile"].ToString(),
                        ProductDescription        = dtproduct.Rows[0]["Description"].ToString(),
                        ProductMultyPrice         = dtproduct.Rows[0]["MultyPrice"].ToString(),
                        ProductName               = dtproduct.Rows[0]["Title"].ToString(),
                        ProductPurePrice          = dtproduct.Rows[0]["PricePerquantity"].ToString(),
                        ShopAvailable4Transaction = new List <Key_ValueModel>(),
                        ShopList                  = new List <Shops>(),
                        socKandSockvlList         = new List <ProductViewDetails_ProductSOCKandSOCKVLList>(),
                        STHList                   = new List <StockpileTransactionHistoryModel>(),
                        MoneyType                 = dtproduct.Rows[0]["MoneyTypeName"].ToString(),
                        demansion                 = dtproduct.Rows[0]["PQT_Demansion"].ToString(),
                    };
                }
                else
                {
                    return(RedirectToAction("Index"));
                }
            }
            //===========================pics
            db.Connect();
            using (DataTable dt = db.Select("SELECT [orgUploadAddress] FROM [v_tblProduct_Image] WHERE [id_MProduct]=" + id_MProductReal))
            {
                db.DC();
                int dtrows = dt.Rows.Count;
                for (int i = 0; i < dtrows; i++)
                {
                    model.ShowPSIDs.PicList.Add(dt.Rows[i]["orgUploadAddress"].ToString());
                }
            }
            if (model.ShowPSIDs.PicList.Count == 0)
            {
                model.ShowPSIDs.PicList.Add("/AdminDesignResource/app/media/img/users/user4.jpg");
            }
            //==============================Shops
            db.Connect();
            using (DataTable dtstock = db.Select("SELECT  [id_Stockpile]  ,[id_Stockpile_AllowType] ,[shop_id] ,[shop_name] ,[shop_IsAvailable] ,[shop_IsDelete]  FROM [v_Stockpile_MainView] WHERE [id_MPC] = " + PSID))
            {
                db.DC();
                AmountOfProductsLeft AOPL = new AmountOfProductsLeft();
                for (int i = 0; i < dtstock.Rows.Count; i++)
                {
                    bool CalCulatingFromShops = false;
                    if (dtstock.Rows[i]["id_Stockpile_AllowType"].ToString() == "1")
                    {
                        CalCulatingFromShops = true;
                    }
                    bool ISActivate = false;
                    if (dtstock.Rows[i]["shop_IsDelete"].ToString() == "0" && dtstock.Rows[i]["shop_IsAvailable"].ToString() == "1")
                    {
                        ISActivate = true;
                    }
                    //ProductCALCULATOR
                    Int64  ProductAvailableCount = AOPL.CanBuyThisProductFromThisShop(PSID.ToString(), dtstock.Rows[i]["shop_id"].ToString(), -1);
                    string BootstrapColor        = "";
                    if (ProductAvailableCount > 200)
                    {
                        BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.success);
                    }
                    else if (ProductAvailableCount > 100)
                    {
                        BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.warning);
                    }
                    else
                    {
                        BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.danger);
                    }
                    model.ShowPSIDs.ShopList.Add(new Shops()
                    {
                        ShopName              = dtstock.Rows[i]["shop_name"].ToString(),
                        CalCulatingFromShop   = CalCulatingFromShops,
                        ISActivate            = ISActivate,
                        ProductAvailableCount = String.Format("{0:n0}", ProductAvailableCount),
                        BootstrapColor        = BootstrapColor
                    });
                }
            }

            //===================================socKandSockvlList
            db.Connect();
            using (DataTable dtproduct = db.Select("SELECT [PTname], [MCName],[SCName]  FROM [v_Connector_MainProductConnectorToProduct] WHERE [id_MPC] = " + PSID))
            {
                using (DataTable dt = db.Select("SELECT [id_MPC] ,[SCOKName] ,[SCOVValueName] FROM [v_ConnectorTheProductConnectorViewToSCOVandSCOKV_s] WHERE [id_MProduct] = " + id_MProductReal + " ORDER BY [id_MPC] DESC"))
                {
                    db.DC();
                    if (dt.Rows.Count > 0)
                    {
                        int dtrows = dt.Rows.Count;
                        ProductViewDetails_ProductSOCKandSOCKVLList products = new ProductViewDetails_ProductSOCKandSOCKVLList();
                        products.ProductSOCKSOCKVList = new List <ProductViewDetails_ProductSOCKandSOCKVL>();
                        string id_MPC = "";
                        products.ProductSOCKSOCKVList.Add(new ProductViewDetails_ProductSOCKandSOCKVL()
                        {
                            BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.primary),
                            SOCKName       = "سردسته بندی اصلی",
                            SOCKVName      = dtproduct.Rows[0]["PTname"].ToString()
                        });
                        products.ProductSOCKSOCKVList.Add(new ProductViewDetails_ProductSOCKandSOCKVL()
                        {
                            BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.primary),
                            SOCKName       = "گروه اصلی",
                            SOCKVName      = dtproduct.Rows[0]["MCName"].ToString()
                        });
                        products.ProductSOCKSOCKVList.Add(new ProductViewDetails_ProductSOCKandSOCKVL()
                        {
                            BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.primary),
                            SOCKName       = "گروه محصول",
                            SOCKVName      = dtproduct.Rows[0]["SCName"].ToString()
                        });
                        for (int i = 0; i < dtrows; i++)
                        {
                            if (id_MPC != dt.Rows[i]["id_MPC"].ToString())
                            {
                                if (!string.IsNullOrEmpty(id_MPC))
                                {
                                    products.id_MPC = id_MPC;
                                    model.ShowPSIDs.socKandSockvlList.Add(products);
                                    products = new ProductViewDetails_ProductSOCKandSOCKVLList();
                                    products.ProductSOCKSOCKVList = new List <ProductViewDetails_ProductSOCKandSOCKVL>();
                                    products.id_MPC = dt.Rows[i]["id_MPC"].ToString();
                                    products.ProductSOCKSOCKVList.Add(new ProductViewDetails_ProductSOCKandSOCKVL()
                                    {
                                        BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.primary),
                                        SOCKName       = "سردسته بندی اصلی",
                                        SOCKVName      = dtproduct.Rows[0]["PTname"].ToString()
                                    });
                                    products.ProductSOCKSOCKVList.Add(new ProductViewDetails_ProductSOCKandSOCKVL()
                                    {
                                        BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.primary),
                                        SOCKName       = "گروه اصلی",
                                        SOCKVName      = dtproduct.Rows[0]["MCName"].ToString()
                                    });
                                    products.ProductSOCKSOCKVList.Add(new ProductViewDetails_ProductSOCKandSOCKVL()
                                    {
                                        BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.primary),
                                        SOCKName       = "گروه محصول",
                                        SOCKVName      = dtproduct.Rows[0]["SCName"].ToString()
                                    });
                                }
                            }
                            products.ProductSOCKSOCKVList.Add(new ProductViewDetails_ProductSOCKandSOCKVL()
                            {
                                BootstrapColor = BootstrapColorPicker.GetbootstrapColorRandomByCounter(i),
                                SOCKName       = dt.Rows[i]["SCOKName"].ToString(),
                                SOCKVName      = dt.Rows[i]["SCOVValueName"].ToString()
                            });
                            id_MPC = dt.Rows[i]["id_MPC"].ToString();
                            if (i == dtrows - 1)
                            {
                                products.id_MPC = id_MPC;
                                model.ShowPSIDs.socKandSockvlList.Add(products);
                            }
                        }
                    }
                    else
                    {
                        return(RedirectToAction("index"));
                    }
                }
            }

            //=-=======================================StockpileTransactionHistoryModel

            db.Connect();
            using (DataTable dt = db.Select("SELECT [shop_id], [id_TransactionType], [PQT_Demansion],[PQTValueOf_Transaction],[PriceOf_Transaction],[shop_name],[StockpileDate_Transaction],[StockpileTime_Transaction],[MoneyTypeName] FROM  [v_Stockpile_Transactions] WHERE [id_MPC] = " + PSID + " ORDER BY [id_Transaction] DESC"))
            {
                db.DC();
                int dtcount = dt.Rows.Count;
                if (dtcount > 0)
                {
                    for (int i = 0; i < dtcount; i++)
                    {
                        StockpileTransactionHistoryModel historyModel = new StockpileTransactionHistoryModel();
                        // {
                        //     BootstrapColor = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.danger),
                        //     Dimension = "موردی یافت نشد",
                        //     HajmSadere = "موردی یافت نشد",x
                        //     HajmVarede = "موردی یافت نشد",x
                        //     MiyanginGheymateSadere = "موردی یافت نشد"x
                        //,
                        //     MiyanginGheymateVarede = "موردی یافت نشد",x
                        //     Mojoodi = "موردی یافت نشد",x
                        //     ShopID = "موردی یافت نشد",x
                        //     ShopName = "موردی یافت نشد",x
                        //     TotalPriceOfsadere = "موردی یافت نشد",x
                        //     TotalPriceOfVarede = "موردی یافت نشد",x
                        //     TransActionDate = "موردی یافت نشد",x
                        // };
                        historyModel.ShopID   = dt.Rows[i]["shop_id"].ToString();
                        historyModel.ShopName = dt.Rows[i]["shop_name"].ToString();
                        historyModel.Mojoodi  = "0";
                        PersianDateTime pdt = new PersianDateTime(DateTime.Parse(dt.Rows[i]["StockpileDate_Transaction"].ToString()));
                        historyModel.TransActionDate = pdt.ToLongDateString() + " " + dt.Rows[i]["StockpileTime_Transaction"].ToString();
                        historyModel.Dimension       = dt.Rows[i]["PQT_Demansion"].ToString();

                        if (dt.Rows[i]["id_TransactionType"].ToString() == "1")
                        {
                            historyModel.BootstrapColor         = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.success);
                            historyModel.HajmSadere             = "0";
                            historyModel.MiyanginGheymateSadere = "0";
                            historyModel.TotalPriceOfsadere     = "0";
                            historyModel.HajmVarede             = String.Format("{0:n0}", dt.Rows[i]["PQTValueOf_Transaction"].ToString());
                            historyModel.MiyanginGheymateVarede = "0";
                            historyModel.TotalPriceOfVarede     = String.Format("{0:n0}", dt.Rows[i]["PriceOf_Transaction"].ToString()) + " " + dt.Rows[i]["PQT_Demansion"].ToString();
                        }
                        else
                        {
                            historyModel.BootstrapColor         = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.danger);
                            historyModel.HajmVarede             = "0";
                            historyModel.MiyanginGheymateVarede = "0";
                            historyModel.TotalPriceOfVarede     = "0";
                            historyModel.HajmSadere             = String.Format("{0:n0}", dt.Rows[i]["PQTValueOf_Transaction"].ToString());
                            historyModel.MiyanginGheymateSadere = "0";
                            historyModel.TotalPriceOfsadere     = String.Format("{0:n0}", dt.Rows[i]["PriceOf_Transaction"].ToString()) + " " + dt.Rows[i]["PQT_Demansion"].ToString();
                        }



                        model.ShowPSIDs.STHList.Add(historyModel);
                    }
                }
                else
                {
                    StockpileTransactionHistoryModel historyModel = new StockpileTransactionHistoryModel()
                    {
                        BootstrapColor         = BootstrapColorPicker.GetbootstrapColorByTag(BootstrapColorEnums.danger),
                        Dimension              = "موردی یافت نشد",
                        HajmSadere             = "موردی یافت نشد",
                        HajmVarede             = "موردی یافت نشد",
                        MiyanginGheymateSadere = "موردی یافت نشد"
                        ,
                        MiyanginGheymateVarede = "موردی یافت نشد",
                        Mojoodi            = "موردی یافت نشد",
                        ShopID             = "موردی یافت نشد",
                        ShopName           = "موردی یافت نشد",
                        TotalPriceOfsadere = "موردی یافت نشد",
                        TotalPriceOfVarede = "موردی یافت نشد",
                        TransActionDate    = "موردی یافت نشد",
                    };
                    model.ShowPSIDs.STHList.Add(historyModel);
                }
            }
            //================================================ ShopAvailable4Transaction
            //=================>MRMNeedsEdit
            db.Connect();
            using (DataTable shops = db.Select("SELECT   [shop_id] ,[shop_name]  FROM [tbl_Modules_StockpileShopsMainTable]"))
            {
                db.DC();
                Key_ValueModel kvm;
                for (int i = 0; i < shops.Rows.Count; i++)
                {
                    kvm = new Key_ValueModel()
                    {
                        Id    = Convert.ToInt32(shops.Rows[i]["shop_id"].ToString()),
                        Value = shops.Rows[i]["shop_name"].ToString()
                    };
                    model.ShowPSIDs.ShopAvailable4Transaction.Add(kvm);
                }
            }

            return(View(model));
        }