コード例 #1
0
ファイル: ZC.cs プロジェクト: 552847957/mjapi
        /// <summary>
        /// 得到主材明细
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public string GetZcMx2(string did, string desingerid = "")
        {
            #region sql语句
            string         sql = @"select * from (
select sum(cast(num as float))  as Num ,sum(cast(Price as float)) as price,ShowroomId,Bname,Pmodel,unit,
netPrice,view_sp.extension,view_sp.gg ,Marketprice,pname,cName,ProductId,projectTypeId,pc.SmallPic,
tp from view_sp left join Pic as pc on pc.TypeId=ProductId and pc.PicId=(select MAX(PicId) 
from pic where Pic.TypeId=view_sp.ProductId) where showRoomid=@did and  
view_sp.Extension1='房间' group by ShowroomId,Bname,Pmodel,unit
,netPrice,view_sp.extension,view_sp.gg,Marketprice,pname,cName,ProductId,projectTypeId,SmallPic,tp) as b";
            SqlParameter[] arr = new SqlParameter[] {
                new SqlParameter("@did", did)
            };

            DataTable dt = SqlHelper.ExecuteDataTable(sql, arr);

            #endregion


            //     Num	price	ShowroomId	Bname	Pmodel	unit	netPrice	extension	Marketprice	pname	cName	ProductId	projectTypeId	SmallPic	tp
            #region 取字典
            Dictionary <string, string> dicp = new Dictionary <string, string>();
            object o = Commen.DataCache.GetCache(desingerid + did);
            if (o != null)
            {
                dicp = o as Dictionary <string, string>;
            }
            #endregion



            #region  组序列化
            Dictionary <string, List <object> > dic = new Dictionary <string, List <object> >();

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];


                var zxobj = new { originalid = row["productid"].ToSafeString(), productid = row["productid"].ToSafeString(), num = row["num"].ToSafeString(), price = row["price"].ToSafeString(), unit = row["unit"].ToSafeString(), tp = ExChange(row["tp"].ToSafeString()), type = ExChange2(row["tp"].ToSafeString()), netprice = row["netprice"].ToSafeString(), pname = row["pname"].ToSafeString(), bnmae = row["bname"].ToSafeString(), pmodel = row["pmodel"].ToSafeString(), gg = row["gg"].ToSafeString(), smallpic = "http://www.mj100.com/admin/UploadFile/550/" + GetPic(row["extension"].ToSafeString()).Replace("\\", "/") };


                if (dicp.ContainsKey(zxobj.originalid))//字典包含这个id  说明已经替换了
                {
                    #region 从缓存中替换
                    string newpid = dicp[zxobj.originalid];
                    //新id

                    #region 新id
                    var row1 = SqlHelper.ExecuteDataTable(@"select top 10 Netprice,Pname, Brand.Bname , Pmodel,Products.extension1 as gg,Products.extension    from Products left join Brand  
on Products.BID=Brand.BID
where  Products.PID='" + newpid + "'  ").Rows[0];
                    #endregion

                    zxobj = new { originalid = row["productid"].ToSafeString(), productid = newpid, num = row["num"].ToSafeString(), price = "236", unit = row["unit"].ToSafeString(), tp = ExChange(row["tp"].ToSafeString()), type = ExChange2(row["tp"].ToSafeString()), netprice = row1["netprice"].ToSafeString(), pname = row1["pname"].ToSafeString(), bnmae = row1["bname"].ToSafeString(), pmodel = row1["pmodel"].ToSafeString(), gg = row1["gg"].ToSafeString(), smallpic = "http://www.mj100.com/admin/UploadFile/550/" + GetPic(row1["extension"].ToSafeString()).Replace("\\", "/") };
                    #endregion
                }


                if (dic.ContainsKey(zxobj.tp))
                {
                    List <object> listemp = dic[zxobj.tp];
                    listemp.Add(zxobj);
                    dic[zxobj.tp] = listemp;
                }
                else
                {
                    List <object> listemp = new List <object>();
                    listemp.Add(zxobj);
                    dic.Add(zxobj.tp, listemp);
                }
            }
            #endregion


            return(JsonConvert.SerializeObject(dic));
        }