protected void Page_Load(object sender, EventArgs e)
 {
     try
     {
         Aim.Portal.Web.WebPortalService.CheckLogon();
     }
     catch
     {
         Response.Write("<script> window.location.href = '/Login.aspx';</script>");
         Response.End();
     }
     string action = Request["action"];
     string where = "";
     DataTable dt = null;
     string id = Request["id"];
     InWarehouse iwEnt = null;
     IList<InWarehouseDetail> iwdEnts = null;
     switch (action)
     {
         case "load":
             if (!string.IsNullOrEmpty(Request["InWarehouseNo"]))
             {
                 where += " and InWarehouseNo like '%" + Request["InWarehouseNo"].Trim() + "%'";
             }
             if (!string.IsNullOrEmpty(Request["SupplierName"]))
             {
                 where += " and SupplierName like '%" + Request["SupplierName"].Trim() + "%'";
             }
             if (!string.IsNullOrEmpty(Request["State"]))
             {
                 where += " and State = '" + Request["State"] + "'";
             }
             if (!string.IsNullOrEmpty(Request["ProductCode"]))
             {
                 where += " and Id in (select distinct InWarehouseId from SHHG_AimExamine..InWarehouseDetail where  ProductCode like '%" + Request["ProductCode"] + "%')";
             }
             sql = "select * from SHHG_AimExamine..InWarehouse where InWarehouseType ='采购入库' " + where;
             dt = DataHelper.QueryDataTable(GetPageSql(sql));
             Response.Write("{total:" + totalProperty + ",rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
             Response.End();
             break;  
         case "delete":
             if (!string.IsNullOrEmpty(id))
             {
                 iwEnt = InWarehouse.Find(id);
                 iwdEnts = InWarehouseDetail.FindAllByProperty("InWarehouseId", id);
                 foreach (InWarehouseDetail tempEnt in iwdEnts)
                 {
                     sql = "select sum(isnull(IQuantity,0)) from SHHG_AimExamine..InWarehouseDetail where PurchaseOrderDetailId='" + tempEnt.PurchaseOrderDetailId + "'";
                     tempEnt.DoDelete();
                    //删除完入库单明细后更新采购单明细的生成入库单数量
                     PurchaseOrderDetail podEnt = PurchaseOrderDetail.Find(tempEnt.PurchaseOrderDetailId);
                     podEnt.RuKuDanQuan = DataHelper.QueryValue<Int32>(sql);
                     podEnt.DoUpdate();
                 }
                 iwEnt.DoDelete();
             }
             break;
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            switch (RequestActionString)
            {
            case "Judge":
                string id = RequestData.Get <string>("id");
                if (!string.IsNullOrEmpty(id))
                {
                    InWarehouse       iwEnt = InWarehouse.Find(id);
                    WarehouseExchange weEnt = WarehouseExchange.Find(iwEnt.PublicInterface);
                    if (weEnt.OutWarehouseState == "已出库")
                    {
                        PageState.Add("Allow", true);
                    }
                    else
                    {
                        PageState.Add("Allow", false);
                    }
                }
                break;

            default:
                DoSelect();
                break;
            }
        }
 private void DoSelect()
 {
     if (!string.IsNullOrEmpty(id))
     {
         InWarehouse            ent             = InWarehouse.Find(id);
         string                 tempsql         = @"select A.* ,B.Name from SHHG_AimExamine..InWarehouse as A 
         left join SHHG_AimExamine..Warehouse as B on A.WarehouseId=B.Id where A.Id='" + id + "'";
         IList <EasyDictionary> dicsInWarehouse = DataHelper.QueryDictList(tempsql);
         if (dicsInWarehouse.Count > 0)
         {
             this.SetFormData(dicsInWarehouse[0]);
         }
         string sql = string.Empty;
         if (ent.InWarehouseType == "采购入库")
         {
             sql = @"select A.Id,A.ProductId, A.IQuantity as Quantity,A.InWarehouseId,A.InWarehouseState,
             A.Remark,A.SkinArray,A.SeriesArray,A.PurchaseOrderDetailId,
             UPPER(rtrim(ltrim(B.Isbn))) as ISBN,B.Name,UPPER(B.Code) as Code,B.ProductType,
             SHHG_AimExamine.dbo.fun_ActuallyHaveInQuantity(A.Id,'{0}') as HaveIn,                   
             (A.IQuantity-SHHG_AimExamine.dbo.fun_ActuallyHaveInQuantity(A.Id,'{1}')) as NoIn
             from SHHG_AimExamine..InWarehouseDetail as A 
             left join SHHG_AimExamine..Products as B on A.ProductId=B.Id
             where A.InWarehouseId='{2}'";
             sql = string.Format(sql, ent.InWarehouseType, ent.InWarehouseType, ent.Id);
         }
         else
         {
             sql = @"select A.Id,A.ProductId,A.Quantity,A.InWarehouseId,A.InWarehouseState,A.Remark,A.SkinArray,A.SeriesArray,
             UPPER(B.Code) as Code , B.Name,UPPER(rtrim(ltrim(B.Isbn))) as ISBN,B.ProductType,
             SHHG_AimExamine.dbo.fun_ActuallyHaveInQuantity(A.Id,'{0}') as HaveIn,
             (A.Quantity-SHHG_AimExamine.dbo.fun_ActuallyHaveInQuantity(A.Id,'{1}')) as NoIn
             from SHHG_AimExamine..OtherInWarehouseDetail as A 
             left join SHHG_AimExamine..Products as B on A.ProductId=B.Id  where A.InWarehouseId='{2}'";
             sql = string.Format(sql, ent.InWarehouseType, ent.InWarehouseType, ent.Id);
         }
         IList <EasyDictionary> dics = DataHelper.QueryDictList(sql);
         PageState.Add("DetailList", dics);
     }
 }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Aim.Portal.Web.WebPortalService.CheckLogon();
            }
            catch
            {
                Response.Write("<script> window.location.href = '/Login.aspx';</script>");
                Response.End();
            }
            string      action = Request["action"];
            string      sql    = "";
            DataTable   dt     = null;
            InWarehouse iwEnt  = null;
            IList <InWarehouseDetail> iwdEnts = null;
            PurchaseOrderDetail       podEnt  = null;
            string PurchaseOrderIds           = Request["PurchaseOrderIds"];
            string id = Request["id"];

            if (!string.IsNullOrEmpty(id))
            {
                iwEnt = InWarehouse.Find(id);
            }
            switch (action)
            {
            case "loaddetail":
                if (!string.IsNullOrEmpty(PurchaseOrderIds))
                {
                    sql = @"select a.Id as PurchaseOrderDetailId, a.ProductId,a.Code as ProductCode,                                            
                        (a.Quantity-isnull(a.RuKuDanQuan,0)) as IQuantity, (a.Quantity-isnull(a.RuKuDanQuan,0)) as MaxQuan,b.PurchaseOrderNo
                        from SHHG_AimExamine..PurchaseOrderDetail a left join SHHG_AimExamine..PurchaseOrder b on a.PurchaseOrderId=b.Id 
                        where '" + PurchaseOrderIds + "' like '%'+PurchaseOrderId+'%' and  (a.Quantity-isnull(a.RuKuDanQuan,0))>0 order by a.Code asc";
                }
                if (!string.IsNullOrEmpty(id))
                {
                    sql = @"select a.Id,a.PurchaseOrderDetailId, a.ProductId,a.ProductCode,a.IQuantity, a.YiRuQuan, 
                        c.PurchaseOrderNo,a.InWarehouseState, a.Remark,(b.Quantity-isnull(b.RuKuDanQuan,0)+a.IQuantity) as MaxQuan   
                        from SHHG_AimExamine..InWarehouseDetail a left join SHHG_AimExamine..PurchaseOrderDetail b
                        on a.PurchaseOrderDetailId=b.Id left join SHHG_AimExamine..PurchaseOrder c on c.Id=b.PurchaseOrderId  
                        where a.InWarehouseId='" + id + "' order by a.ProductCode asc";
                }
                dt = DataHelper.QueryDataTable(sql);
                Response.Write("{rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "loadform":
                if (!string.IsNullOrEmpty(PurchaseOrderIds))
                {
                    iwEnt = new InWarehouse();
                    iwEnt.InWarehouseNo   = DataHelper.QueryValue("select SHHG_AimExamine.dbo.fun_getInWarehouseNo()").ToString();
                    iwEnt.InWarehouseType = "采购入库";
                    string[]      idarray = PurchaseOrderIds.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    PurchaseOrder poEnt   = PurchaseOrder.Find(idarray[0]);
                    iwEnt.SupplierId   = poEnt.SupplierId;
                    iwEnt.SupplierName = poEnt.SupplierName;
                    Response.Write("{success:true,data:" + JsonHelper.GetJsonString(iwEnt) + "}");
                }
                if (!string.IsNullOrEmpty(id))
                {
                    Response.Write("{success:true,data:" + JsonHelper.GetJsonString(iwEnt) + "}");
                }
                Response.End();
                break;

            case "create":
                string formdata   = Request["formdata"];
                string detaildata = Request["detaildata"];
                iwEnt            = JsonHelper.GetObject <InWarehouse>(Request["formdata"]);
                iwEnt.CreateId   = Aim.Portal.Web.WebPortalService.CurrentUserInfo.UserID;
                iwEnt.CreateName = Aim.Portal.Web.WebPortalService.CurrentUserInfo.Name;
                iwEnt.CreateTime = DateTime.Now;
                iwEnt.State      = "未入库";
                iwEnt.DoCreate();
                iwdEnts = JsonHelper.GetObject <IList <InWarehouseDetail> >(Request["detaildata"]);
                foreach (InWarehouseDetail iwdEnt in iwdEnts)
                {
                    iwdEnt.InWarehouseId    = iwEnt.Id;
                    iwdEnt.InWarehouseState = "未入库";
                    iwdEnt.DoCreate();
                    //创建完入库单明细后更新采购单明细的生成入库单数量
                    sql                = "select sum(isnull(IQuantity,0)) from SHHG_AimExamine..InWarehouseDetail where PurchaseOrderDetailId='" + iwdEnt.PurchaseOrderDetailId + "'";
                    podEnt             = PurchaseOrderDetail.Find(iwdEnt.PurchaseOrderDetailId);
                    podEnt.RuKuDanQuan = DataHelper.QueryValue <Int32>(sql);
                    podEnt.DoUpdate();
                }
                Response.Write("{success:true}");
                Response.End();
                break;

            case "update":
                InWarehouse    tempEnt = JsonHelper.GetObject <InWarehouse>(Request["formdata"]);
                EasyDictionary dic     = JsonHelper.GetObject <EasyDictionary>(Request["formdata"]);
                iwEnt = DataHelper.MergeData <InWarehouse>(iwEnt, tempEnt, dic.Keys);
                iwEnt.DoUpdate();
                sql = "delete SHHG_AimExamine..InWarehouseDetail where InWarehouseId='" + iwEnt.Id + "'";
                DataHelper.ExecSql(sql);
                iwdEnts = JsonHelper.GetObject <IList <InWarehouseDetail> >(Request["detaildata"]);
                foreach (InWarehouseDetail iwdEnt in iwdEnts)
                {
                    iwdEnt.InWarehouseId    = iwEnt.Id;
                    iwdEnt.InWarehouseState = "未入库";
                    iwdEnt.DoCreate();
                    //创建完入库单明细后更新采购单明细的生成入库单数量
                    sql                = "select sum(isnull(IQuantity,0)) from SHHG_AimExamine..InWarehouseDetail where PurchaseOrderDetailId='" + iwdEnt.PurchaseOrderDetailId + "'";
                    podEnt             = PurchaseOrderDetail.Find(iwdEnt.PurchaseOrderDetailId);
                    podEnt.RuKuDanQuan = DataHelper.QueryValue <Int32>(sql);
                    podEnt.DoUpdate();
                }
                break;
            }
        }
Example #5
0
        private void CreateLog()
        {
            IList <InWarehouseDetailDetail> iwddEnts = InWarehouseDetailDetail.FindAll();//入库

            foreach (InWarehouseDetailDetail iwddEnt in iwddEnts)
            {
                StockLog    slEnt = new StockLog();
                InWarehouse iwEnt = null;
                if (!string.IsNullOrEmpty(iwddEnt.InWarehouseDetailId))
                {
                    slEnt.InOrOutDetailId = iwddEnt.InWarehouseDetailId;
                    InWarehouseDetail iwdEnt = InWarehouseDetail.Find(iwddEnt.InWarehouseDetailId);
                    iwEnt = InWarehouse.Find(iwdEnt.InWarehouseId);
                }
                else
                {
                    slEnt.InOrOutDetailId = iwddEnt.OtherInWarehouseDetailId;
                    OtherInWarehouseDetail oiwdEnt = OtherInWarehouseDetail.Find(iwddEnt.OtherInWarehouseDetailId);
                    iwEnt = InWarehouse.Find(oiwdEnt.InWarehouseId);
                }
                slEnt.InOrOutBillNo = iwEnt.InWarehouseNo;
                slEnt.OperateType   = "产品入库";
                slEnt.WarehouseId   = iwEnt.WarehouseId;
                slEnt.WarehouseName = iwEnt.WarehouseName;
                //IList<StockInfo> siEnts = StockInfo.FindAllByProperties(StockInfo.Prop_ProductId, iwddEnt.ProductId, StockInfo.Prop_WarehouseId, iwEnt.WarehouseId);
                //if (siEnts.Count > 0)
                //{
                //    slEnt.StockQuantity = siEnts[0].StockQuantity;
                //}
                slEnt.Quantity  = iwddEnt.Quantity;
                slEnt.ProductId = iwddEnt.ProductId;
                Product pEnt = Product.TryFind(iwddEnt.ProductId);
                if (pEnt != null)
                {
                    slEnt.ProductName = pEnt.Name;
                    slEnt.ProductCode = pEnt.Code;
                    slEnt.ProductIsbn = pEnt.Isbn;
                    slEnt.ProductPcn  = pEnt.Pcn;
                    slEnt.CreateId    = iwddEnt.CreateId;
                    slEnt.CreateName  = iwddEnt.CreateName;
                    slEnt.CreateTime  = iwddEnt.CreateTime;
                    slEnt.DoCreate();
                }
            }
            //生成出库日志
            IList <DelieryOrderPart> dopEnts = DelieryOrderPart.FindAllByProperty(DelieryOrderPart.Prop_State, "已出库");

            foreach (DelieryOrderPart dopEnt in dopEnts)
            {
                StockLog slEnt = new StockLog();
                slEnt.InOrOutDetailId = dopEnt.Id;
                DeliveryOrder doEnt = DeliveryOrder.Find(dopEnt.DId);
                slEnt.InOrOutBillNo = doEnt.Number;
                slEnt.OperateType   = "产品出库";
                slEnt.WarehouseId   = doEnt.WarehouseId;
                slEnt.WarehouseName = doEnt.WarehouseName;
                //IList<StockInfo> siEnts = StockInfo.FindAllByProperties(StockInfo.Prop_ProductId, iwddEnt.ProductId, StockInfo.Prop_WarehouseId, iwEnt.WarehouseId);
                //if (siEnts.Count > 0)
                //{
                //    slEnt.StockQuantity = siEnts[0].StockQuantity;
                //}
                slEnt.Quantity = dopEnt.OutCount;
                if (!string.IsNullOrEmpty(dopEnt.ProductId))
                {
                    slEnt.ProductId = dopEnt.ProductId;
                    Product pEnt = Product.TryFind(dopEnt.ProductId);
                    if (pEnt != null)
                    {
                        slEnt.ProductName = pEnt.Name;
                        slEnt.ProductCode = pEnt.Code;
                        slEnt.ProductIsbn = pEnt.Isbn;
                        slEnt.ProductPcn  = pEnt.Pcn;
                        slEnt.CreateId    = dopEnt.CreateId;
                        slEnt.CreateName  = dopEnt.CreateName;
                        slEnt.CreateTime  = dopEnt.CreateTime;
                        slEnt.DoCreate();
                    }
                }
            }
            //盘点操作库存日志
            string sql = "select * from SHHG_AimExamine..StockCheckDetail where StockCheckResult!='正常' and StockCheckState='盘点结束'";
            IList <EasyDictionary> scdDics = DataHelper.QueryDictList(sql);

            foreach (EasyDictionary scdDic in scdDics)
            {
                StockLog slEnt = new StockLog();
                slEnt.InOrOutDetailId = scdDic.Get <string>("Id");
                StockCheck scEnt = StockCheck.Find(scdDic.Get <string>("StockCheckId"));
                slEnt.InOrOutBillNo = scEnt.StockCheckNo;
                slEnt.OperateType   = "库存盘点";
                slEnt.WarehouseId   = scEnt.WarehouseId;
                slEnt.WarehouseName = scEnt.WarehouseName;
                slEnt.StockQuantity = scdDic.Get <Int32>("StockQuantity");
                slEnt.Quantity      = scdDic.Get <Int32>("StockCheckQuantity") - scdDic.Get <Int32>("StockQuantity");
                slEnt.ProductId     = scdDic.Get <string>("ProductId");
                Product pEnt = Product.TryFind(slEnt.ProductId);
                if (pEnt != null)
                {
                    slEnt.ProductName = pEnt.Name;
                    slEnt.ProductCode = pEnt.Code;
                    slEnt.ProductIsbn = pEnt.Isbn;
                    slEnt.ProductPcn  = pEnt.Pcn;
                    slEnt.CreateId    = scEnt.CreateId;
                    slEnt.CreateName  = scEnt.CreateName;
                    slEnt.CreateTime  = scEnt.CreateTime;
                    slEnt.DoCreate();
                }
            }
        }
Example #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Aim.Portal.Web.WebPortalService.CheckLogon();
            }
            catch
            {
                Response.Write("<script> window.location.href = '/Login.aspx';</script>");
                Response.End();
            }
            string                action         = Request["action"];
            string                sql            = "";
            DataTable             dt             = null;
            PayBill               pbEnt          = null;
            IList <PayBillDetail> pbdEnts        = null;
            InWarehouseDetail     iwdEnt         = null;
            string                id             = Request["id"];
            string                inwarehouseids = Request["inwarehouseids"];

            if (!string.IsNullOrEmpty(id))
            {
                pbEnt = PayBill.Find(id);
            }
            switch (action)
            {
            case "loaddetail":
                if (!string.IsNullOrEmpty(id))
                {
                    sql = @"select a.Id,a.PurchaseOrderDetailId, a.ProductId,a.ProductCode,a.PayQuantity,a.BuyPrice,a.Amount,a.ProductName,
                        c.PurchaseOrderNo,(d.IQuantity-isnull(d.FuKuanDanQuan,0)+a.PayQuantity) as MaxQuan,a.InWarehouseDetailId  
                        from SHHG_AimExamine..PayBillDetail a 
                        left join SHHG_AimExamine..InWarehouseDetail d on d.Id=a.InWarehouseDetailId               
                        left join SHHG_AimExamine..PurchaseOrderDetail b on a.PurchaseOrderDetailId=b.Id                      
                        left join SHHG_AimExamine..PurchaseOrder c on c.Id=b.PurchaseOrderId  
                        where a.PayBillId='" + id + "' order by a.ProductCode asc";
                }
                if (!string.IsNullOrEmpty(inwarehouseids))
                {
                    sql = @"select a.Id InWarehouseDetailId, a.ProductId,a.PurchaseOrderDetailId, a.ProductCode,b.Name as ProductName, b.BuyPrice,c.PurchaseOrderNo,                                        
                        (a.IQuantity-isnull(a.FuKuanDanQuan,0)) as PayQuantity, (a.IQuantity-isnull(a.FuKuanDanQuan,0)) as MaxQuan,(a.IQuantity-isnull(a.FuKuanDanQuan,0))*(b.BuyPrice) as Amount
                        from SHHG_AimExamine..InWarehouseDetail a 
                        left join SHHG_AimExamine..PurchaseOrderDetail b on a.PurchaseOrderDetailId=b.Id 
                        left join SHHG_AimExamine..PurchaseOrder c on c.Id=b.PurchaseOrderId
                        where (a.IQuantity-isnull(a.FuKuanDanQuan,0))>0 and ('" + inwarehouseids + "' like '%'+a.InWarehouseId+'%') order by a.ProductCode asc";
                }
                dt = DataHelper.QueryDataTable(sql);
                Response.Write("{rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "loadform":
                if (!string.IsNullOrEmpty(inwarehouseids))
                {
                    pbEnt           = new PayBill();
                    pbEnt.PayBillNo = DataHelper.QueryValue("select SHHG_AimExamine.dbo.fun_getPayBillNo()").ToString();
                    string[]    idarray = inwarehouseids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    InWarehouse iwEnt   = InWarehouse.Find(idarray[0]);
                    pbEnt.SupplierId   = iwEnt.SupplierId;
                    pbEnt.SupplierName = iwEnt.SupplierName;
                    Supplier sEnt = Supplier.Find(iwEnt.SupplierId);
                    pbEnt.Symbo = sEnt.Symbo;
                    Response.Write("{success:true,data:" + JsonHelper.GetJsonString(pbEnt) + "}");
                }
                if (!string.IsNullOrEmpty(id))
                {
                    Response.Write("{success:true,data:" + JsonHelper.GetJsonString(pbEnt) + "}");
                }
                Response.End();
                break;

            case "create":
                pbEnt            = JsonHelper.GetObject <PayBill>(Request["formdata"]);
                pbEnt.CreateId   = Aim.Portal.Web.WebPortalService.CurrentUserInfo.UserID;
                pbEnt.CreateName = Aim.Portal.Web.WebPortalService.CurrentUserInfo.Name;
                pbEnt.CreateTime = DateTime.Now;
                pbEnt.State      = "未付款";
                pbEnt.DoCreate();
                pbdEnts = JsonHelper.GetObject <IList <PayBillDetail> >(Request["detaildata"]);
                foreach (PayBillDetail pbdEnt in pbdEnts)
                {
                    pbdEnt.PayBillId = pbEnt.Id;
                    pbdEnt.DoCreate();
                    //创建完付款单明细后更新入库单明细的生成付款单数量
                    sql    = "select sum(isnull(PayQuantity,0)) from SHHG_AimExamine..PayBillDetail where InWarehouseDetailId='" + pbdEnt.InWarehouseDetailId + "'";
                    iwdEnt = InWarehouseDetail.Find(pbdEnt.InWarehouseDetailId);
                    iwdEnt.FuKuanDanQuan = DataHelper.QueryValue <Int32>(sql);
                    iwdEnt.DoUpdate();
                }
                Response.Write("{success:true}");
                Response.End();
                break;

            case "update":
                PayBill        tempEnt = JsonHelper.GetObject <PayBill>(Request["formdata"]);
                EasyDictionary dic     = JsonHelper.GetObject <EasyDictionary>(Request["formdata"]);
                pbEnt = DataHelper.MergeData <PayBill>(pbEnt, tempEnt, dic.Keys);
                pbEnt.DoUpdate();
                sql = "delete SHHG_AimExamine..PayBillDetail where PayBillId='" + pbEnt.Id + "'";
                DataHelper.ExecSql(sql);
                pbdEnts = JsonHelper.GetObject <IList <PayBillDetail> >(Request["detaildata"]);
                foreach (PayBillDetail pbdEnt in pbdEnts)
                {
                    pbdEnt.PayBillId = pbEnt.Id;
                    pbdEnt.DoCreate();
                    //创建完付款单明细后更新入库单明细的生成付款单数量
                    sql    = "select sum(isnull(PayQuantity,0)) from SHHG_AimExamine..PayBillDetail where InWarehouseDetailId='" + pbdEnt.InWarehouseDetailId + "'";
                    iwdEnt = InWarehouseDetail.Find(pbdEnt.InWarehouseDetailId);
                    iwdEnt.FuKuanDanQuan = DataHelper.QueryValue <Int32>(sql);
                    iwdEnt.DoUpdate();
                }
                Response.Write("{success:true}");
                Response.End();
                break;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string          action = Request["action"];
            DataTable       dt;
            string          sql   = "";
            PurchaseInvoice Pient = null;
            //   PurchaseInvoiceDetail Pident = null;
            InWarehouseDetail             IwdEnt  = null;
            IList <PurchaseInvoiceDetail> Pidents = null;
            string inwarehouseids = Request["inwarehouseids"];
            string id             = Request["id"];

            switch (action)
            {
            case "loadform":
                if (!string.IsNullOrEmpty(inwarehouseids))
                {
                    Pient = new PurchaseInvoice();
                    string[]    idarray = inwarehouseids.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                    InWarehouse iwEnt   = InWarehouse.Find(idarray[0]);
                    Pient.SupplierId   = iwEnt.SupplierId;
                    Pient.SupplierName = iwEnt.SupplierName;
                    Supplier sEnt = Supplier.Find(iwEnt.SupplierId);
                    Pient.Symbo = sEnt.Symbo;
                    Response.Write("{success:true,data:" + JsonHelper.GetJsonString(Pient) + "}");
                }
                if (!string.IsNullOrEmpty(id))
                {
                    Response.Write("{success:true,data:" + JsonHelper.GetJsonString(PurchaseInvoice.Find(id)) + "}");
                }
                Response.End();
                break;

            case "loaddetail":
                if (!string.IsNullOrEmpty(id))
                {
                    sql = @"select a.Id,a.PurchaseOrderDetailId, a.ProductId,a.ProductCode,a.InvoiceQuantity,a.InvoiceAmount,a.ProductName,a.BuyPrice,a.Remark,
                        (d.IQuantity-isnull(d.KaiPiaoQuan,0)+a.InvoiceQuantity) as MaxQuan,a.InWarehouseDetailId  
                        from SHHG_AimExamine..PurchaseInvoiceDetail   a 
                        left join SHHG_AimExamine..InWarehouseDetail d on d.Id=a.InWarehouseDetailId               
                        left join SHHG_AimExamine..PurchaseOrderDetail b on a.PurchaseOrderDetailId=b.Id                      
                        left join SHHG_AimExamine..PurchaseOrder c on c.Id=b.PurchaseOrderId  
                        where a.PurchaseInvoiceId='" + id + "' order by a.ProductCode asc";
                }
                if (!string.IsNullOrEmpty(inwarehouseids))
                {
                    sql = @"select a.Id InWarehouseDetailId, a.ProductId,a.PurchaseOrderDetailId, a.ProductCode,b.Name as ProductName, b.BuyPrice, c.PurchaseOrderNo,                                       
                        (a.IQuantity-isnull(a.KaiPiaoQuan,0)) as InvoiceQuantity, (a.IQuantity-isnull(a.KaiPiaoQuan,0)) as MaxQuan,(a.IQuantity-isnull(a.KaiPiaoQuan,0))*(b.BuyPrice) as InvoiceAmount
                        from SHHG_AimExamine..InWarehouseDetail a 
                        left join SHHG_AimExamine..PurchaseOrderDetail b on a.PurchaseOrderDetailId=b.Id 
                        left join SHHG_AimExamine..PurchaseOrder c on c.Id=b.PurchaseOrderId
                        where (a.IQuantity-isnull(a.KaiPiaoQuan,0))>0 and ('" + inwarehouseids + "' like '%'+a.InWarehouseId+'%') order by a.ProductCode asc";
                }
                dt = DataHelper.QueryDataTable(sql);
                Response.Write("{rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "create":
                Pient = JsonHelper.GetObject <PurchaseInvoice>(Request["formdata"]);
                //Pient.CreateId = Aim.Portal.Web.WebPortalService.CurrentUserInfo.UserID;
                //Pient.CreateName = Aim.Portal.Web.WebPortalService.CurrentUserInfo.Name;
                //Pient.CreateTime = DateTime.Now;
                //Pient.InvoiceNo
                Pient.DoCreate();
                Pidents = JsonHelper.GetObject <IList <PurchaseInvoiceDetail> >(Request["detaildata"]);
                foreach (PurchaseInvoiceDetail Pident in Pidents)
                {
                    Pident.PurchaseInvoiceId = Pient.Id;
                    Pident.DoCreate();
                    //创建完付款单明细后更新入库单明细的生成付款单数量
                    sql                = "select sum(isnull(InvoiceQuantity,0)) from SHHG_AimExamine..PurchaseInvoiceDetail where InWarehouseDetailId='" + Pident.InWarehouseDetailId + "'";
                    IwdEnt             = InWarehouseDetail.Find(Pident.InWarehouseDetailId);
                    IwdEnt.KaiPiaoQuan = DataHelper.QueryValue <Int32>(sql);
                    IwdEnt.DoUpdate();
                }
                Response.Write("{success:true}");
                Response.End();
                break;

            case "update":
                Pient = JsonHelper.GetObject <PurchaseInvoice>(Request["formdata"]);
                PurchaseInvoice oEnt = PurchaseInvoice.Find(Pient.Id);
                EasyDictionary  dic  = JsonHelper.GetObject <EasyDictionary>(Request["formdata"]);
                Pient = DataHelper.MergeData <PurchaseInvoice>(oEnt, Pient, dic.Keys);

                Pient.DoUpdate();
                sql = "delete SHHG_AimExamine..PurchaseInvoiceDetail where PurchaseInvoiceId='" + Pient.Id + "'";
                DataHelper.ExecSql(sql);
                Pidents = JsonHelper.GetObject <IList <PurchaseInvoiceDetail> >(Request["detaildata"]);
                foreach (PurchaseInvoiceDetail Pident in Pidents)
                {
                    Pident.PurchaseInvoiceId = Pient.Id;
                    Pident.DoCreate();
                    //创建完付款单明细后更新入库单明细的生成付款单数量
                    sql                = "select sum(isnull(InvoiceQuantity,0)) from SHHG_AimExamine..PurchaseInvoiceDetail where InWarehouseDetailId='" + Pident.InWarehouseDetailId + "'";
                    IwdEnt             = InWarehouseDetail.Find(Pident.InWarehouseDetailId);
                    IwdEnt.KaiPiaoQuan = DataHelper.QueryValue <Int32>(sql);
                    IwdEnt.DoUpdate();
                }
                Response.Write("{success:true}");
                Response.End();
                break;
            }
        }
        private void DoSelect()
        {
            string sql = string.Empty;

            string where = "";
            foreach (CommonSearchCriterionItem item in SearchCriterion.Searches.Searches)
            {
                where += " and " + item.PropertyName + " like '%" + item.Value + "%' ";
            }
            string inWarehouseId = RequestData.Get <string>("InWarehouseId");//入库单id有可能为空 比如

            if (!string.IsNullOrEmpty(inWarehouseId))
            {
                InWarehouse iwEnt = InWarehouse.Find(inWarehouseId);
                if (iwEnt.InWarehouseType == "采购入库")
                {
                    sql = @"select A.ProductId,A.IQuantity as Quantity,B.Name,A.InWarehouseState,B.Code
                    from SHHG_AimExamine..InWarehouseDetail as A
                    left join SHHG_AimExamine..Products as B on A.ProductId=B.Id  
                    where InWarehouseId='" + inWarehouseId + "'" + where;
                }
                else
                {
                    sql = @"select A.ProductId,A.Quantity,A.InWarehouseState,B.Name,B.Code
                    from SHHG_AimExamine..OtherInWarehouseDetail as A
                    left join SHHG_AimExamine..Products as B on A.ProductId=B.Id  
                    where InWarehouseId='" + inWarehouseId + "'" + where;
                }
                PageState.Add("InWarehouseDetail", GetPageData(sql, SearchCriterion));
                PageState.Add("InWarehouseNo", iwEnt.InWarehouseNo);
            }
//            else
//            {
//                DataTable tbl = new DataTable();
//                DataColumn col = new DataColumn("ProductId", typeof(string)); tbl.Columns.Add(col);
//                col = new DataColumn("Quantity", typeof(int)); tbl.Columns.Add(col);
//                col = new DataColumn("Name", typeof(string)); tbl.Columns.Add(col);
//                col = new DataColumn("Code", typeof(string)); tbl.Columns.Add(col);
//                col = new DataColumn("Isbn", typeof(string)); tbl.Columns.Add(col);
//                col = new DataColumn("InWarehouseNo", typeof(string)); tbl.Columns.Add(col);
//                col = new DataColumn("InWarehouseState", typeof(string)); tbl.Columns.Add(col);
//                sql = @"select A.ProductId,A.IQuantity as Quantity,A.InWarehouseState,B.Name,B.Code,B.Isbn,C.InWarehouseNo
//                from SHHG_AimExamine..InWarehouseDetail as A
//                left join SHHG_AimExamine..Products as B on A.ProductId=B.Id
//                left join SHHG_AimExamine..InWarehouse as C on A.InWarehouseId=C.Id where 1=1 " + where;
//                IList<EasyDictionary> dics1 = DataHelper.QueryDictList(sql);
//                foreach (EasyDictionary ea in dics1)
//                {
//                    DataRow dr = tbl.NewRow();
//                    dr["ProductId"] = ea.Get<string>("ProductId");
//                    dr["Quantity"] = ea.Get<int>("Quantity");
//                    dr["Name"] = ea.Get<string>("Name");
//                    dr["Code"] = ea.Get<string>("Code");
//                    dr["Isbn"] = ea.Get<string>("Isbn");
//                    dr["InWarehouseNo"] = ea.Get<string>("InWarehouseNo");
//                    dr["InWarehouseState"] = ea.Get<string>("InWarehouseState");
//                    tbl.Rows.Add(dr);
//                }
//                sql = @"select A.ProductId,A.Quantity,A.InWarehouseState,B.Name,B.Code,B.Isbn,C.InWarehouseNo
//                from SHHG_AimExamine..OtherInWarehouseDetail as A
//                left join SHHG_AimExamine..Products as B on A.ProductId=B.Id
//                left join SHHG_AimExamine..InWarehouse as C on A.InWarehouseId=C.Id where 1=1 " + where;
//                IList<EasyDictionary> dics2 = DataHelper.QueryDictList(sql);
//                foreach (EasyDictionary ea in dics2)
//                {
//                    DataRow dr = tbl.NewRow();
//                    dr["ProductId"] = ea.Get<string>("ProductId");
//                    dr["Quantity"] = ea.Get<int>("Quantity");
//                    dr["Name"] = ea.Get<string>("Name");
//                    dr["Code"] = ea.Get<string>("Code");
//                    dr["Isbn"] = ea.Get<string>("Isbn");
//                    dr["InWarehouseNo"] = ea.Get<string>("InWarehouseNo");
//                    dr["InWarehouseState"] = ea.Get<string>("InWarehouseState");
//                    tbl.Rows.Add(dr);
//                }
//                PageState.Add("InWarehouseDetail", tbl);
//            }
        }