public ActionResult OrderDetail()
        {
            string _ordercode = QueryString.SafeQ("code");

            VWConfirmOrderEntity confirmorder = ConfirmOrderBLL.Instance.GetVWConfirmOrderByCode(_ordercode);

            if (confirmorder != null && confirmorder.ConfirmOrderId > 0)
            {
                Dictionary <int, VWMemberEntity>  memberdic   = new Dictionary <int, VWMemberEntity>();
                IList <ConfirmOrderProductEntity> productlist = ConfirmOrderProductBLL.Instance.GetConfirmProductAllByCode(_ordercode, -1, false);
                confirmorder.OrderProducts = productlist;
                confirmorder.OrderPics     = InquiryOrderPicsBLL.Instance.GetInquiryOrderPicsAllByCode(confirmorder.InquiryOrderCode);
                foreach (ConfirmOrderProductEntity pro in productlist)
                {
                    if (pro.CGMemId > 0 && !memberdic.ContainsKey(pro.CGMemId))
                    {
                        memberdic[pro.CGMemId] = MemberBLL.Instance.GetVWMember(pro.CGMemId);
                    }
                }
                //CGMemQuotedEntity quote = CGMemQuotedBLL.Instance.GetCGMemHasCheckedByCode(confirmorder.InquiryOrderCode);
                //ViewBag.CGMemQuote = quote;
                ViewBag.CGMemberDic = memberdic;
            }
            ViewBag.VWOrder = confirmorder;
            return(View());
        }
        public VWConfirmOrderEntity GetVWConfirmOrderByCode(string code)
        {
            string sql = @"SELECT  a.Id,a.[Code],a.InquiryOrderCode,a.[VinNo],a.VinPic,a.[EngineModelNo],a.EngineModelPic,a.CarBrandId,a.CarBrandName,a.CarSeriesId,a.CarSeriesName,[CarTypeModelId],[CarTypeModelName],
[Remark],[WLMemId],[WLRemark],NeedDay,CGTotalPrice,TotalPrice,[CreateManId],[CreateTime], a.[Status],a.StatusForMem,a.ScopeType, b.MemId, b.[MemName]
      ,b.[MemPhone]
      ,b.[CompanyAddress]
      ,b.[CompanyName] from dbo.[ConfirmOrder] a WITH(NOLOCK) INNER JOIN ConfirmOrderMember b WITH(NOLOCK) 
ON a.[InquiryOrderCode]=b.[InquiryOrderCode] 	
							WHERE a.[Code]=@Code";
            DbCommand cmd = db.GetSqlStringCommand(sql); 
            db.AddInParameter(cmd, "@Code", DbType.String, code);
            VWConfirmOrderEntity entity = new VWConfirmOrderEntity();
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                { 
                    entity.ConfirmOrderId = StringUtils.GetDbInt(reader["Id"]);
                    entity.ConfirmOrderCode = StringUtils.GetDbString(reader["Code"]);
                    entity.InquiryOrderCode = StringUtils.GetDbString(reader["InquiryOrderCode"]);
                    entity.VinNo = StringUtils.GetDbString(reader["VinNo"]);
                    entity.VinPic = StringUtils.GetDbString(reader["VinPic"]);
                    entity.EngineModelNo = StringUtils.GetDbString(reader["EngineModelNo"]);
                    entity.EngineModelPic = StringUtils.GetDbString(reader["EngineModelPic"]);
                    entity.CarBrandId = StringUtils.GetDbInt(reader["CarBrandId"]);
                    entity.CarBrandName = StringUtils.GetDbString(reader["CarBrandName"]);
                    entity.CarSeriesId = StringUtils.GetDbInt(reader["CarSeriesId"]);
                    entity.CarSeriesName = StringUtils.GetDbString(reader["CarSeriesName"]);
                    entity.CarTypeModelId = StringUtils.GetDbInt(reader["CarTypeModelId"]);
                    entity.CarTypeModelName = StringUtils.GetDbString(reader["CarTypeModelName"]);
                    entity.Remark = StringUtils.GetDbString(reader["Remark"]);
                    entity.NeedDay = StringUtils.GetDbInt(reader["NeedDay"]);
                    entity.WLMemId = StringUtils.GetDbInt(reader["WLMemId"]);
                    entity.WLRemark = StringUtils.GetDbString(reader["WLRemark"]);
                    entity.CGTotalPrice = StringUtils.GetDbDecimal(reader["CGTotalPrice"]);
                    entity.TotalPrice = StringUtils.GetDbDecimal(reader["TotalPrice"]);
                    entity.MemId = StringUtils.GetDbInt(reader["MemId"]); 
                    entity.MemName = StringUtils.GetDbString(reader["MemName"]);
                    entity.MemPhone = StringUtils.GetDbString(reader["MemPhone"]);
                    entity.CompanyAddress = StringUtils.GetDbString(reader["CompanyAddress"]);
                    entity.CompanyName = StringUtils.GetDbString(reader["CompanyName"]);
                    entity.CreateManId = StringUtils.GetDbInt(reader["CreateManId"]);
                    entity.CreateTime = StringUtils.GetDbDateTime(reader["CreateTime"]);
                    entity.Status = StringUtils.GetDbInt(reader["Status"]);
                    entity.StatusForMem = StringUtils.GetDbInt(reader["StatusForMem"]);
                    entity.ScopeType = StringUtils.GetDbInt(reader["ScopeType"]);
                    //entity.CancelReasonId = StringUtils.GetDbInt(reader["CancelReasonId"]);
                    //entity.CancelRemark = StringUtils.GetDbString(reader["CancelRemark"]);
                }
            }
            return entity;
        }
        /// <summary>
        /// 选择供应商页面
        /// </summary>
        /// <returns></returns>
        public ActionResult CGMemSelect()
        {
            string code = QueryString.SafeQ("code");
            VWConfirmOrderEntity conor = ConfirmOrderBLL.Instance.GetVWConfirmOrderByCode(code);

            if (conor.Status == (int)OrderConfirmStatusEnum.WaitSelectCGMem)
            {
                conor.OrderProducts = ConfirmOrderProductBLL.Instance.GetConfirmProductAllByCode(code, -1, false);
                //VWInquiryOrderEntity vworder = InquiryOrderBLL.Instance.GetInquiryOrderDataByCode(conor.InquiryOrderCode);
                IList <VWCGMemQuotedEntity> quotelist             = CGMemQuotedBLL.Instance.GetVWCGMemQuotedAllByCode(conor.InquiryOrderCode);
                IList <CGQuotedPriceEntity> pricelist             = CGQuotedPriceBLL.Instance.GetCGQuotedPriceAll(conor.InquiryOrderCode, -1, true);
                Dictionary <string, CGQuotedPriceEntity> pricedic = new Dictionary <string, CGQuotedPriceEntity>();
                foreach (CGQuotedPriceEntity price in pricelist)
                {
                    if (!pricedic.ContainsKey(price.InquiryProductSubId + "_" + price.CGMemId))
                    {
                        pricedic.Add(price.InquiryProductId + "_" + price.InquiryProductType + "_" + price.CGMemId, price);
                    }
                }
                //IList<InquiryProductSubEntity> productsubs = vworder.OrderProductSubs;
                //Dictionary<int, IList<InquiryProductSubEntity>> productsubdic = new Dictionary<int, IList<InquiryProductSubEntity>>();
                //if (productsubs != null && productsubs.Count > 0)
                //{
                //    foreach (InquiryProductSubEntity prod in productsubs)
                //    {
                //        if (!productsubdic.ContainsKey(prod.InquiryProductId))
                //        {
                //            productsubdic.Add(prod.InquiryProductId, new List<InquiryProductSubEntity>());
                //        }
                //        productsubdic[prod.InquiryProductId].Add(prod);
                //    }
                //}
                ViewBag.VWOrder         = conor;
                ViewBag.QuotedCGMemList = quotelist;
                //ViewBag.ProductSubDIc = productsubdic;
                ViewBag.PriceDic = pricedic;
                ViewBag.Code     = code;
            }
            else
            {
                return(RedirectToAction("OrderDetail", new { code = code }));
            }
            return(View());
        }
        public ActionResult OrderConfirmPrint()
        {
            string _code = QueryString.SafeQ("code");
            VWConfirmOrderEntity confirmorder = ConfirmOrderBLL.Instance.GetVWConfirmOrderByCode(_code);

            if (confirmorder != null && confirmorder.ConfirmOrderId > 0)
            {
                IList <ConfirmOrderProductEntity> productlist = ConfirmOrderProductBLL.Instance.GetConfirmProductAllByCode(_code, -1, false);
                confirmorder.OrderProducts = productlist;
                confirmorder.OrderPics     = InquiryOrderPicsBLL.Instance.GetInquiryOrderPicsAllByCode(confirmorder.InquiryOrderCode);

                ViewBag.VWOrder = confirmorder;
            }
            else
            {
                RedirectToAction("OrderConfirmList");
            }
            return(View());
        }
        /// <summary>
        /// 读取记录列表。
        /// </summary>
        /// <param name="db">数据库操作对象</param>
        /// <param name="columns">需要返回的列,不提供任何列名时默认将返回所有列</param>
        public   IList<VWConfirmOrderEntity> GetConfirmOrderList(int pagesize, int pageindex, ref  int recordCount, int memid, int cgmemid, int status, string key,string  inquirycode)
        {
            string where = " where 1=1 ";
            string innercgmemsql = "";
            if (memid != -1)
            {
                where += " and b.MemId=@MemId";
            }
            if (cgmemid != -1)
            {
                where += " and cgm.CGMemId=@CGMemId";
                innercgmemsql = " inner join ConfirmOrderCGMem cgm WITH(NOLOCK)  on a.[Code]=cgm.ConfirmOrderCode ";
            }
            if (status != -1)
            {
                where += " and a.Status=@Status";
            } 
            if (!string.IsNullOrEmpty(key))
            {
                where += " and a.Code like @Code";
            }
            if (!string.IsNullOrEmpty(inquirycode))
            {
                where += " and a.InquiryOrderCode like @InquiryOrderCode";
            }
            string sql= @"SELECT   [Code],InquiryOrderCode,[VinNo],VinPic,[EngineModelNo], EngineModelPic,CarBrandId,CarBrandName,CarSeriesId,CarSeriesName,[CarTypeModelId],[CarTypeModelName],[Remark],[WLRemark],NeedDay,CGTotalPrice,TotalPrice,[CreateManId],[CreateTime], [Status], StatusForMem,MemId,[MemName]
      ,[MemPhone]
      ,[CompanyAddress]
      ,[CompanyName] FROM 
						(SELECT ROW_NUMBER() OVER (ORDER BY a.Id desc) AS ROWNUMBER,
a.[Code],a.InquiryOrderCode,a.[VinNo],a.VinPic,a.[EngineModelNo],a.EngineModelPic,a.CarBrandId,a.CarBrandName,a.CarSeriesId,a.CarSeriesName,[CarTypeModelId],[CarTypeModelName],[Remark],[WLRemark],NeedDay,a.CGTotalPrice,a.TotalPrice,[CreateManId],[CreateTime], a.[Status],a.StatusForMem, a.MemId, b.[MemName]
      ,b.[MemPhone]
      ,b.[CompanyAddress]
      ,b.[CompanyName] from dbo.[ConfirmOrder] a WITH(NOLOCK) INNER JOIN ConfirmOrderMember b WITH(NOLOCK) 
ON a.[Code]=b.[ConfirmOrderCode] " + innercgmemsql + where + @") as temp 
						where rownumber BETWEEN ((@PageIndex - 1) * @PageSize + 1) AND @PageIndex * @PageSize";
			
			string sql2= @"Select count(1) from dbo.[ConfirmOrder]  a WITH(NOLOCK) INNER JOIN ConfirmOrderMember b WITH(NOLOCK) 
ON a.[Code]=b.[ConfirmOrderCode] " + innercgmemsql + where;
            IList<VWConfirmOrderEntity> entityList = new List<VWConfirmOrderEntity>();
            DbCommand cmd = db.GetSqlStringCommand(sql);
		    db.AddInParameter(cmd, "@PageIndex", DbType.Int32, pageindex);
		    db.AddInParameter(cmd, "@PageSize", DbType.Int32, pagesize);
            if (memid != -1)
            {
		      db.AddInParameter(cmd, "@MemId", DbType.Int32, memid);  
            }
            if (cgmemid != -1)
            { 
                db.AddInParameter(cmd, "@CGMemId", DbType.Int32, cgmemid);
            }
            if (status != -1)
            { 
                db.AddInParameter(cmd, "@Status", DbType.Int32, status);
            }
            if (!string.IsNullOrEmpty(key))
            { 
                db.AddInParameter(cmd, "@Code", DbType.String,"%"+ key+"%");
            }
            if (!string.IsNullOrEmpty(inquirycode))
            { 
                db.AddInParameter(cmd, "@InquiryOrderCode", DbType.String, "%" + inquirycode + "%");
            }
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                while (reader.Read())
                {
                    VWConfirmOrderEntity entity =new VWConfirmOrderEntity(); 
					entity.ConfirmOrderCode=StringUtils.GetDbString(reader["Code"]);
					entity.InquiryOrderCode = StringUtils.GetDbString(reader["InquiryOrderCode"]);
					entity.VinNo=StringUtils.GetDbString(reader["VinNo"]);
					entity.VinPic=StringUtils.GetDbString(reader["VinPic"]);
                    entity.EngineModelNo = StringUtils.GetDbString(reader["EngineModelNo"]);
                    entity.EngineModelPic = StringUtils.GetDbString(reader["EngineModelPic"]);
                    entity.CarBrandId=StringUtils.GetDbInt(reader["CarBrandId"]);
					entity.CarBrandName=StringUtils.GetDbString(reader["CarBrandName"]);
					entity.CarSeriesId=StringUtils.GetDbInt(reader["CarSeriesId"]);
					entity.CarSeriesName=StringUtils.GetDbString(reader["CarSeriesName"]);
					entity.CarTypeModelId=StringUtils.GetDbInt(reader["CarTypeModelId"]);
					entity.CarTypeModelName=StringUtils.GetDbString(reader["CarTypeModelName"]);
					entity.Remark=StringUtils.GetDbString(reader["Remark"]);
					entity.NeedDay=StringUtils.GetDbInt(reader["NeedDay"]);
					entity.WLRemark=StringUtils.GetDbString(reader["WLRemark"]);
					entity.CGTotalPrice=StringUtils.GetDbDecimal(reader["CGTotalPrice"]);
					entity.TotalPrice=StringUtils.GetDbDecimal(reader["TotalPrice"]);
					entity.MemId=StringUtils.GetDbInt(reader["MemId"]); 
                    entity.MemName = StringUtils.GetDbString(reader["MemName"]);
					entity.MemPhone = StringUtils.GetDbString(reader["MemPhone"]);
					entity.CompanyAddress = StringUtils.GetDbString(reader["CompanyAddress"]);
					entity.CompanyName = StringUtils.GetDbString(reader["CompanyName"]);
					entity.CreateManId=StringUtils.GetDbInt(reader["CreateManId"]);
					entity.CreateTime=StringUtils.GetDbDateTime(reader["CreateTime"]);
					entity.Status=StringUtils.GetDbInt(reader["Status"]); 
					entity.StatusForMem=StringUtils.GetDbInt(reader["StatusForMem"]);
                    entityList.Add(entity);
			    }
			 }
			cmd = db.GetSqlStringCommand(sql2);
            if (memid != -1)
            {
                db.AddInParameter(cmd, "@MemId", DbType.Int32, memid);

            }
            if (cgmemid != -1)
            {
                db.AddInParameter(cmd, "@CGMemId", DbType.Int32, cgmemid);
            }
            if (status != -1)
            {
                db.AddInParameter(cmd, "@Status", DbType.Int32, status);
            }
            if (!string.IsNullOrEmpty(key))
            {
                db.AddInParameter(cmd, "@Code", DbType.String, "%" + key + "%");
            }
            if (!string.IsNullOrEmpty(inquirycode))
            {
                db.AddInParameter(cmd, "@InquiryOrderCode", DbType.String, "%" + inquirycode + "%");
            }
            using (IDataReader reader = db.ExecuteReader(cmd))
            {
                if (reader.Read())
                {
                    recordCount = StringUtils.GetDbInt(reader[0]);
                }
                else
                {
                    recordCount = 0;
                }
            }
            return entityList;
     	}