public JsonResult PrintSKU(int Id)
 {
     PlanDaoType obj = NSession.Get<PlanDaoType>(Id);
     if (obj != null)
     {
         NSession.Flush();
         IList<PurchasePlanType> plans = NSession.CreateQuery("from PurchasePlanType where PlanNo=:p and SKU=:p2").SetString("p", obj.PlanNo).SetString("p2", obj.SKU).SetMaxResults(1).List<PurchasePlanType>();
         PurchasePlanType plan = plans[0];
         IList<SKUCodeType> list =
              NSession.CreateQuery("from SKUCodeType where SKU=:p1 and PlanNo=:p2 and Code >=:p3 order by Id").SetString("p1", obj.SKU).
                  SetString("p2", obj.PlanNo).SetInt32("p3", obj.SKUCode).SetMaxResults(obj.RealQty).List<SKUCodeType>();
         DataTable dt = new DataTable();
         dt.Columns.Add("sku");
         dt.Columns.Add("name");
         dt.Columns.Add("num");
         dt.Columns.Add("date");
         dt.Columns.Add("people");
         dt.Columns.Add("desc");
         dt.Columns.Add("code");
         int i = 1;
         foreach (SKUCodeType skuCodeType in list)
         {
             DataRow dr = dt.NewRow();
             dr[0] = plan.SKU;
             dr[1] = plan.ProductName;
             dr[2] = i + "/" + obj.RealQty;
             dr[3] = plan.BuyOn;
             dr[4] = plan.BuyBy;
             dr[5] = plan.PlanNo;
             dr[6] = skuCodeType.Code;
             dt.Rows.Add(dr);  
             i++;
         }
         DataSet ds = new DataSet();
         ds.Tables.Add(dt);
         if(plan.ExpectReceiveOn <(new DateTime(2000, 1, 1)))
         {
             plan.ExpectReceiveOn = new DateTime(2000, 1, 1);
         }
         PrintDataType data = new PrintDataType();
         data.Content = ds.GetXml();
         data.CreateOn = DateTime.Now;
         NSession.Save(data);
         NSession.Flush();
         return Json(new { IsSuccess = true, Result = data.Id });
     }
     return Json(new { IsSuccess = false });
 }
        public ActionResult SetPrintData(string m, string r, string d, string t)
        {
            d = d.Replace("\r", "").Replace("\n", ",");
            IList<OrderType> objectses = NSession.CreateQuery("from OrderType where IsAudit=0 and OrderNo IN('" +
                                   d.Replace(",", "','") + "')").List<OrderType>();
            string NotPrint = "";
            foreach (OrderType c in objectses)
            {
                NotPrint += c.OrderNo + " ;";
            }
            string sql = "";
            sql = @"select (select COUNT(1) from OrderProducts where OrderProducts.OId=O.id) as 'GCount',O.IsPrint as 'PCount' ,O.Id,O.OrderNo,o.OrderExNo,O.Account,O.Platform,O.Amount,O.CurrencyCode,O.BuyerEmail,O.BuyerName,O.LogisticMode,O.IsSplit,O.IsRepeat,O.IsAudit,
O.BuyerMemo,O.SellerMemo,O.CreateOn,O.Freight,O.Weight,O.TrackCode,O.Country,OA.Addressee,OA.Street,OA.County,OA.City,OA.Province,
OA.Phone,OA.Tel,OA.PostCode,OA.CountryCode,OP.SKU,OP.Standard,OP.Remark,OP.Title,OP.Qty,OP.ExSKU,P.OldSKU,P.Category,P.SPicUrl,P.OldSKU,P.Location,P.ProductName,
R.RetuanName ,R.City as 'RCity',R.Street as 'RStreet',R.Phone as 'RPhone',R.Tel as 'RTel',R.County as 'RCounty',(select top 1 CCountry from Country where ECountry=O.Country) as CCountry,O.GenerateOn,
R.Country as 'RCountry',R.PostCode as 'RPostCode',R.Province as 'RProvince' from Orders O 
left join OrderProducts OP on o.Id=op.OId
left join OrderAddress OA on o.AddressId=oa.Id
Left Join Products P ON OP.SKU=P.SKU
left join ReturnAddress R On r.Id=" + r;


            //2013.9.22 添加 sal不打印,直接硬编码.--> 看后期是否可以变成过滤模块吧,
            sql += " where O.IsAudit=1 and  O.OrderNo IN('" + d.Replace(",", "','") + "') and O.LogisticMode not like '%sal%' and O.Account not in ('wunderschoen_dream')";
            DataSet ds = new DataSet();
            IDbCommand command = NSession.Connection.CreateCommand();
            command.CommandText = sql;
            SqlDataAdapter da = new SqlDataAdapter(command as SqlCommand);
            da.Fill(ds);
            ds.Tables[0].DefaultView.Sort = " OrderNo Asc";
            if (t == "多物品订单")
                ds.Tables[0].DefaultView.RowFilter = " GCount >1";
            else
            {
                List<string> list = new List<string>();
                DataTable dt1 = ds.Tables[0];
                foreach (DataRow dr in dt1.Rows)
                {
                    if (list.Contains(dr["OrderNo"].ToString()))
                    {
                        dr.Delete();
                    }
                    else
                    {
                        list.Add(dr["OrderNo"].ToString());
                    }
                }
                ds.Tables[0].DefaultView.Sort = " OrderNo Asc";

            }
            DataTable dt = ds.Tables[0].DefaultView.ToTable();
            dt.Columns.Add("PrintName");
            dt.Columns.Add("AreaName");

            List<string> list2 = new List<string>();
          
            foreach (DataRow dr in dt.Rows)
            {
                dr["PrintName"] = CurrentUser.Realname;
                if (dr["LogisticMode"].ToString() == "BLS")
                {
                    dr["TrackCode"] = "1372100" + dr["OrderNo"].ToString();
                }

                object obj = NSession.CreateSQLQuery("select top 1 AreaName from [LogisticsArea] where LId = (select top 1 ParentID from LogisticsMode where LogisticsCode='" + dr["LogisticMode"] + "')  and Id =(select top 1 AreaCode from LogisticsAreaCountry where [LogisticsArea].Id=AreaCode  and CountryCode in (select ID from Country where ECountry='" + dr["Country"] + "') )").UniqueResult();
                dr["AreaName"] = obj;
                if (list2.Contains(dr["OrderNo"].ToString()))
                {
                }
                else
                {
                    LoggerUtil.GetOrderRecord(Convert.ToInt32(dr["Id"]), dr["OrderNo"].ToString(), "订单打印", CurrentUser.Realname + "订单打印!", CurrentUser, NSession);
                    list2.Add(dr["OrderNo"].ToString());
               
                }
            }
            //标记打印
            NSession.CreateQuery("update OrderType set IsPrint=IsPrint+1 where  IsAudit=1 and  OrderNo IN('" + d.Replace(",", "','") + "') and LogisticMode not like '%sal%'").ExecuteUpdate();
            ds.Tables.Clear();
            ds.Tables.Add(dt);
            if (NotPrint != "")
            {
                NotPrint = "有" + objectses.Count + "条订单没有审核,无法发打印,订单号:" + NotPrint;
            }
            PrintDataType data = new PrintDataType();
            data.Content = ds.GetXml();
            data.CreateOn = DateTime.Now;
            NSession.Save(data);
            NSession.Flush();
            return Json(new { IsSuccess = true, Result = data.Id });
        }
        public ActionResult PrintSKU(int Id)
        {
            StockInType obj = NSession.Get<StockInType>(Id);
            if (obj != null)
            {
                NSession.Flush();
                IList<SKUCodeType> list =
                     NSession.CreateQuery("from SKUCodeType where PlanNo='" + obj.Id + "'").
                       List<SKUCodeType>();
                DataTable dt = new DataTable();
                dt.Columns.Add("sku");
                dt.Columns.Add("name");
                dt.Columns.Add("num");
                dt.Columns.Add("date");
                dt.Columns.Add("people");
                dt.Columns.Add("desc");
                dt.Columns.Add("code");
                int i = 1;
                foreach (SKUCodeType skuCodeType in list)
                {
                    DataRow dr = dt.NewRow();
                    dr[0] = obj.SKU;
                    dr[1] = obj.SKU;
                    dr[2] = i + "/" + obj.Qty;
                    dr[3] = obj.CreateOn;
                    dr[4] = obj.CreateBy;
                    dr[5] = "手动入库";
                    dr[6] = skuCodeType.Code;
                    dt.Rows.Add(dr);
                    i++;
                }
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);

                PrintDataType data = new PrintDataType();
                data.Content = ds.GetXml();
                data.CreateOn = DateTime.Now;
                NSession.Save(data);
                NSession.Flush();
                return Json(new { IsSuccess = true, Result = data.Id });
            }
            return Json(new { IsSuccess = false });
        }