Esempio n. 1
0
        public static DataTable GetProduct(string strProductName, string strMemberRight)
        {
            string strsql = "";

            if (string.IsNullOrEmpty(strProductName))
            {
                strsql = "select a.cnvcValue as cnvcProductName,b.cnvcMemberType,b.cnvcMemberValue from "
                         + " (select * from tbNameCode where cnvcType = '服务产品')a "
                         + " left outer join "
                         + " tbMemberCode b on a.cnvcValue = b.cnvcMemberName";
            }
            else
            {
                strsql = "select a.cnvcValue as cnvcProductName,b.cnvcMemberType,b.cnvcMemberValue from "
                         + " (select * from tbNameCode where cnvcType = '服务产品' and cnvcValue like '%" + strProductName + "%' )a "
                         + " left outer join "
                         + " tbMemberCode b on a.cnvcValue = b.cnvcMemberName ";
            }
            if (!string.IsNullOrEmpty(strMemberRight))
            {
                strsql += " where a.cnvcValue in (select cnvcMemberType from tbMemberCode where cnvcMemberName='" + strMemberRight + "')";
            }
            DataTable dtProduct = Query(strsql);
            int       oldCount  = dtProduct.Rows.Count;
            Hashtable htProduct = new Hashtable();

            foreach (DataRow drProduct in dtProduct.Rows)
            {
                if (htProduct.ContainsKey(drProduct["cnvcProductName"].ToString()))
                {
                    ProductCode p = (ProductCode)htProduct[drProduct["cnvcProductName"].ToString()];
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductPrice))
                    {
                        p.cnvcProductPrice = drProduct["cnvcMemberValue"].ToString();
                    }
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductDiscount))
                    {
                        p.cnvcProductDiscount = drProduct["cnvcMemberValue"].ToString();
                    }
                }
                else
                {
                    ProductCode p = new ProductCode();
                    p.cnvcProductName = drProduct["cnvcProductName"].ToString();
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductPrice))
                    {
                        p.cnvcProductPrice = drProduct["cnvcMemberValue"].ToString();
                    }
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductDiscount))
                    {
                        p.cnvcProductDiscount = drProduct["cnvcMemberValue"].ToString();
                    }
                    htProduct.Add(p.cnvcProductName, p);
                }
            }
            DataTable dtProductNew = new DataTable();

            dtProductNew.Columns.Add("cnvcIsSelected");
            dtProductNew.Columns.Add("cnvcProductName");
            dtProductNew.Columns.Add("cnnProductPrice");
            dtProductNew.Columns.Add("cnnProductDiscount");
            dtProductNew.Columns.Add("cnnPrepay");
            dtProductNew.Columns.Add("cnvcFree");
            dtProductNew.Columns.Add("cnnCount");
            IDictionaryEnumerator myEnumerator = htProduct.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                DataRow     drProduct = dtProductNew.NewRow();
                ProductCode p         = (ProductCode)myEnumerator.Value;
                drProduct["cnvcIsSelected"]  = "false";
                drProduct["cnvcFree"]        = "1";
                drProduct["cnvcProductName"] = p.cnvcProductName;
                drProduct["cnnProductPrice"] = p.cnvcProductPrice;
                if (string.IsNullOrEmpty(p.cnvcProductDiscount))
                {
                    drProduct["cnnProductDiscount"] = "100";
                }
                else
                {
                    drProduct["cnnProductDiscount"] = p.cnvcProductDiscount;
                }
                //if (p.cnvcProductPrice == "" || p.cnvcProductDiscount == "")
                //{
                //    drProduct["cnnPrepay"] = p.cnvcProductPrice;
                //}
                //if (p.cnvcProductPrice != "" && p.cnvcProductDiscount != "")
                //{
                //    drProduct["cnnPrepay"] = (int.Parse(p.cnvcProductPrice) * int.Parse(p.cnvcProductDiscount)) / 100;
                //}
                drProduct["cnnCount"] = "1";
                dtProductNew.Rows.Add(drProduct);
            }
            //			DataView dvProduct = dtProductNew.Copy().DefaultView;
            //			dvProduct.Sort = "cnvcProductName";
            //			DataTable dtProductSort = dvProduct.Table.Copy();
            DataRow[] drProducts    = dtProductNew.Select("cnnProductPrice <>'' and cnnProductDiscount <>''", "cnvcProductName asc");
            DataTable dtProductSort = dtProductNew.Clone();

            //dtProductSort.Clear();
            foreach (DataRow drProduct in drProducts)
            {
                dtProductSort.ImportRow(drProduct);
            }
            //int newCount = dtProductSort.Rows.Count;
            return(dtProductSort);
        }
Esempio n. 2
0
        public static DataTable BindProduct()
        {
            DataTable dtProduct = Query("select a.cnvcValue as cnvcProductName,b.cnvcMemberType,b.cnvcMemberValue from "
                                        + " (select * from tbNameCode where cnvcType = '服务产品')a "
                                        + " left outer join "
                                        + " tbMemberCode b on a.cnvcValue = b.cnvcMemberName");
            int       oldCount  = dtProduct.Rows.Count;
            Hashtable htProduct = new Hashtable();

            foreach (DataRow drProduct in dtProduct.Rows)
            {
                if (htProduct.ContainsKey(drProduct["cnvcProductName"].ToString()))
                {
                    ProductCode p = (ProductCode)htProduct[drProduct["cnvcProductName"].ToString()];
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductPrice))
                    {
                        p.cnvcProductPrice = drProduct["cnvcMemberValue"].ToString();
                    }
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductDiscount))
                    {
                        p.cnvcProductDiscount = drProduct["cnvcMemberValue"].ToString();
                    }
                }
                else
                {
                    ProductCode p = new ProductCode();
                    p.cnvcProductName = drProduct["cnvcProductName"].ToString();
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductPrice))
                    {
                        p.cnvcProductPrice = drProduct["cnvcMemberValue"].ToString();
                    }
                    if (drProduct["cnvcMemberType"].ToString().Equals(ConstApp.ProductDiscount))
                    {
                        p.cnvcProductDiscount = drProduct["cnvcMemberValue"].ToString();
                    }
                    htProduct.Add(p.cnvcProductName, p);
                }
            }
            DataTable dtProductNew = new DataTable();

            dtProductNew.Columns.Add("cnvcIsSelected");
            dtProductNew.Columns.Add("cnvcProductName");
            dtProductNew.Columns.Add("cnnProductPrice");
            dtProductNew.Columns.Add("cnnProductDiscount");
            dtProductNew.Columns.Add("cnnPrepay");
            dtProductNew.Columns.Add("cnvcFree");
            IDictionaryEnumerator myEnumerator = htProduct.GetEnumerator();

            while (myEnumerator.MoveNext())
            {
                DataRow     drProduct = dtProductNew.NewRow();
                ProductCode p         = (ProductCode)myEnumerator.Value;
                drProduct["cnvcIsSelected"]     = "false";
                drProduct["cnvcFree"]           = "1";
                drProduct["cnvcProductName"]    = p.cnvcProductName;
                drProduct["cnnProductPrice"]    = p.cnvcProductPrice;
                drProduct["cnnProductDiscount"] = p.cnvcProductDiscount;
                if (p.cnvcProductPrice == "" || p.cnvcProductDiscount == "")
                {
                    drProduct["cnnPrepay"] = p.cnvcProductPrice;
                }
                if (p.cnvcProductPrice != "" && p.cnvcProductDiscount != "")
                {
                    drProduct["cnnPrepay"] = (int.Parse(p.cnvcProductPrice) * int.Parse(p.cnvcProductDiscount)) / 100;
                }

                dtProductNew.Rows.Add(drProduct);
            }
            //			DataView dvProduct = dtProductNew.Copy().DefaultView;
            //			dvProduct.Sort = "cnvcProductName";
            //			DataTable dtProductSort = dvProduct.Table.Copy();
            DataRow[] drProducts    = dtProductNew.Select("cnnProductPrice <>'' and cnnProductDiscount <>''", "cnvcProductName asc");
            DataTable dtProductSort = dtProductNew.Clone();

            //dtProductSort.Clear();
            foreach (DataRow drProduct in drProducts)
            {
                dtProductSort.ImportRow(drProduct);
            }
            int newCount = dtProductSort.Rows.Count;

            //gridProduct.SetDataBinding(dtProductSort,null,true,true);
            if (oldCount != newCount * 2)
            {
                MessageBox.Show("服务产品参数不全", "服务产品参数");
            }
            return(dtProductSort);
        }