private void DoBatchDelete()
        {
            int            index  = 0;
            IList <object> idList = RequestData.GetList <object>("IdList");

            if (idList != null && idList.Count > 0)
            {
                foreach (object obj in idList)
                {
                    Compressor compEnt = Compressor.Find(obj.ToString());
                    string     sql1    = @"from InWarehouseDetail  WHERE PATINDEX('%{0}%', SeriesArray) >0";
                    sql1 = string.Format(sql1, compEnt.SeriesNo);
                    IList <InWarehouseDetail> iwdEnts = InWarehouseDetail.FindAll(sql1);
                    if (iwdEnts.Count > 0)
                    {
                        index = iwdEnts[0].SeriesArray.IndexOf(compEnt.SeriesNo);
                        iwdEnts[0].SeriesArray = iwdEnts[0].SeriesArray.Remove(index, compEnt.SeriesNo.Length);
                        iwdEnts[0].DoUpdate();
                    }
                    string sql2 = @"from OtherInWarehouseDetail  WHERE PATINDEX('%{0}%', SeriesArray) > 0";
                    sql2 = string.Format(sql2, compEnt.SeriesNo);
                    IList <OtherInWarehouseDetail> oiwdEnts = OtherInWarehouseDetail.FindAll(sql2);
                    if (oiwdEnts.Count > 0)
                    {
                        index = oiwdEnts[0].SeriesArray.IndexOf(compEnt.SeriesNo);
                        oiwdEnts[0].SeriesArray = oiwdEnts[0].SeriesArray.Remove(index, compEnt.SeriesNo.Length);
                        oiwdEnts[0].DoUpdate();
                    }
                }
            }
            Compressor.DoBatchDelete(idList.ToArray());//不能仅仅删除压缩机记录 还得把InWarehouseDetail 或者OtherInWarehouseDetail 记录的压缩机序列号删除
        }
 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;
     }
 }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string action            = Request["action"];
            string PurchaseInvoiceId = Request["PurchaseInvoiceId"];

            string where = "";
            string          sql   = "";
            PurchaseInvoice Pient = null;
            DataTable       dt;

            switch (action)
            {
            case "load":
                if (!string.IsNullOrEmpty(Request["InvoiceNo"]))
                {
                    where += " and InvoiceNo like '%" + Request["InvoiceNo"].Trim() + "%'";
                }
                if (!string.IsNullOrEmpty(Request["SupplierName"]))
                {
                    where += " and SupplierName like '%" + Request["SupplierName"].Trim() + "%'";
                }

                if (!string.IsNullOrEmpty(Request["ProductCode"]))
                {
                    where += " and Id in (select distinct PurchaseInvoiceId from SHHG_AimExamine..PurchaseInvoiceDetail where  ProductCode like '%" + Request["ProductCode"] + "%')";
                }
                sql = @"select * from SHHG_AimExamine..PurchaseInvoice where 1=1 " + where;
                dt  = DataHelper.QueryDataTable(GetPageSql(sql));
                Response.Write("{total:" + totalProperty + ",rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "loaddetail":
                sql = @"select *  from SHHG_AimExamine..PurchaseInvoiceDetail 
                             where PurchaseInvoiceId='" + PurchaseInvoiceId + "' order by ProductCode asc";
                dt  = DataHelper.QueryDataTable(sql);
                Response.Write("{innerrows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "delete":
                string Id = Request["Id"];
                Pient = PurchaseInvoice.Find(Id);
                IList <PurchaseInvoiceDetail> PidEnts = PurchaseInvoiceDetail.FindAllByProperty("PurchaseInvoiceId", Id);
                foreach (PurchaseInvoiceDetail PidEnt in PidEnts)
                {
                    sql = @"select sum(isnull(InvoiceQuantity,0)) from SHHG_AimExamine..PurchaseInvoiceDetail where InWarehouseDetailId='" + PidEnt.InWarehouseDetailId + "'";
                    PidEnt.DoDelete();
                    if (!string.IsNullOrEmpty(PidEnt.InWarehouseDetailId))
                    {
                        InWarehouseDetail iwdEnt = InWarehouseDetail.Find(PidEnt.InWarehouseDetailId);
                        iwdEnt.KaiPiaoQuan = DataHelper.QueryValue <Int32>(sql);
                        iwdEnt.DoUpdate();
                    }
                }
                Pient.DoDelete();
                break;
            }
        }
        private void ProcessPurchaseOrderAndDetail(InWarehouse iwEnt)
        {
            string purchaseOrderId            = string.Empty;
            IList <InWarehouseDetail> iwdEnts = InWarehouseDetail.FindAll("from InWarehouseDetail where InWarehouseId='" + iwEnt.Id + "'");
            PurchaseOrderDetail       podEnt  = null;
            ArrayList poIdArray      = new ArrayList();
            int       actuallyInQuan = 0;

            foreach (InWarehouseDetail iwdEnt in iwdEnts)
            {
                if (iwdEnt.InWarehouseState == "已入库")//只有入库单详细的状态是已入库 才去遍历采购详细
                {
                    podEnt = PurchaseOrderDetail.Find(iwdEnt.PurchaseOrderDetailId);
                    if (podEnt.PurchaseOrderId != purchaseOrderId)
                    {
                        purchaseOrderId = podEnt.PurchaseOrderId;
                        poIdArray.Add(podEnt.PurchaseOrderId);
                    }
                    actuallyInQuan = DataHelper.QueryValue <int>("select  SHHG_AimExamine.dbo.fun_ActuallyHaveInQuantityByPodId('" + podEnt.Id + "')");
                    if (podEnt.Quantity == actuallyInQuan)
                    {
                        podEnt.InWarehouseState = "已入库";
                        podEnt.DoUpdate();
                    }
                }
            }//循环完毕后 再根据记录的采购单ID集合。对采购单遍历
            for (int i = 0; i < poIdArray.Count; i++)
            {
                IList <PurchaseOrderDetail> podEnts = PurchaseOrderDetail.FindAll("from PurchaseOrderDetail where InWarehouseState='未入库' and PurchaseOrderId='" + poIdArray[i].ToString() + "'");
                if (podEnts.Count == 0)
                {
                    PurchaseOrder poEnt = PurchaseOrder.Find(poIdArray[i].ToString());
                    poEnt.InWarehouseState = "已入库";
                    poEnt.DoUpdate();
                    if (poEnt.InvoiceState == "已关联" && poEnt.PayState == "已付款")
                    {
                        poEnt.OrderState = "已结束";
                        poEnt.DoUpdate();
                    }
                }
            }
        }
        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();
                }
            }
        }
        private void ProcessInWarehouse(InWarehouse tempEnt)
        {
            if (tempEnt.InWarehouseType == "采购入库")
            {
                //判断其下所有的入库详细状态都未已入库 则自己的状态改为已入库
                IList <InWarehouseDetail> iwdEnts = InWarehouseDetail.FindAll("from InWarehouseDetail where InWarehouseState='未入库' and InWarehouseId='" + tempEnt.Id + "'");
                if (iwdEnts.Count == 0)
                {
                    tempEnt.State = "已入库";
                    tempEnt.InWarehouseEndTime = System.DateTime.Now;
                    tempEnt.CheckUserId        = UserInfo.UserID;
                    tempEnt.CheckUserName      = UserInfo.Name;
                    tempEnt.DoUpdate();
                }
            }
            else
            {
                IList <OtherInWarehouseDetail> oiwdEnts = OtherInWarehouseDetail.FindAll("from OtherInWarehouseDetail where InWarehouseState='未入库' and InWarehouseId='" + tempEnt.Id + "'");
                if (oiwdEnts.Count == 0)//如果明细都入库了
                {
                    //add by cc
                    string db = ConfigurationManager.AppSettings["ExamineDB"];
                    if (tempEnt.InWarehouseType == "退货入库")
                    {
                        ReturnOrder rtnOrder = ReturnOrder.TryFind(tempEnt.PublicInterface);
                        if (rtnOrder != null)
                        {
                            rtnOrder.State = "已完成";
                            rtnOrder.DoSave();
                            //判断是否已经全部退货
                            //string DeliveryState = "";
                            //string tempId = DataHelper.QueryValue<string>("select top 1 Id from " + db + "..Saleorders where number='" + rtnOrder.OrderNumber + "'");
                            //if (!string.IsNullOrEmpty(tempId))
                            //{
                            //    DeliveryState = DataHelper.QueryValue<string>("select " + db + ".dbo.fun_getDeliveryState('" + tempId + "')");
                            //}

                            ////更新SaleOrder表出库状态
                            //if (DeliveryState == "已全部退货")
                            //{
                            //    DataHelper.ExecSql("update " + db + "..SaleOrders set DeState='已全部退货',DeliveryState='已全部退货' where Number='" + rtnOrder.OrderNumber + "'");
                            //}
                            //else
                            //{
                            //    DataHelper.ExecSql("update " + db + "..SaleOrders set DeState='" + DeliveryState + "' where Number='" + rtnOrder.OrderNumber + "'");
                            //    //DataHelper.ExecSql("update " + db + "..SaleOrders set DeState=" + db + ".dbo.fun_getDeliveryState(Id) where Number='" + rtnOrder.OrderNumber + "'");
                            //}
                        }
                    }
                    //else if (tempEnt.InWarehouseType == "换货入库")
                    //{
                    //    ChangeProduct dorder = ChangeProduct.TryFind(tempEnt.PublicInterface);
                    //    if (dorder != null)
                    //    {
                    //        if ((dorder.State + "").Contains("已出库"))
                    //        {
                    //            dorder.State = "已完成";
                    //        }
                    //        else
                    //        {
                    //            dorder.State += ",仓库已入库:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm");
                    //        }
                    //        dorder.DoSave();

                    //        //更新SaleOrder表出库状态
                    //        DataHelper.ExecSql("update " + db + "..SaleOrders set DeState=" + db + ".dbo.fun_getDeliveryState(Id) where Number='" + dorder.OrderNumber + "'");
                    //    }
                    //}
                    //end add by cc
                    else if (tempEnt.InWarehouseType == "调拨入库")
                    {
                        WarehouseExchange weEnt = WarehouseExchange.TryFind(tempEnt.PublicInterface);
                        weEnt.InWarehouseState = "已入库";
                        weEnt.DoUpdate();
                        if (weEnt.OutWarehouseState == "已出库")
                        {
                            weEnt.ExchangeState = "已结束";
                            weEnt.EndTime       = System.DateTime.Now;
                            weEnt.DoUpdate();
                        }
                    }
                    tempEnt.State = "已入库";
                    tempEnt.InWarehouseEndTime = System.DateTime.Now;
                    tempEnt.CheckUserId        = UserInfo.UserID;
                    tempEnt.CheckUserName      = UserInfo.Name;
                    tempEnt.DoUpdate();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            op = RequestData.Get <string>("op");
            id = RequestData.Get <string>("id");
            switch (RequestActionString)
            {
            case "IsIsbn":
                string          val     = RequestData.Get <string>("Value");
                IList <Product> proEnts = Product.FindAll("from Product where Isbn='" + val + "'");
                if (proEnts.Count > 0)
                {
                    PageState.Add("IsIsbn", true);
                }
                else
                {
                    PageState.Add("IsIsbn", false);
                }
                break;

            case "GetPackageInfo":
                string Isbn = RequestData.Get <string>("Isbn");
                sql = "select * from SHHG_AimExamine..Products where FirstSkinIsbn='" + Isbn + "' and FirstSkinCapacity is not null";
                IList <EasyDictionary> dics = DataHelper.QueryDictList(sql);
                if (dics.Count > 0)
                {
                    PageState.Add("ProductIsbn", dics[0].Get <string>("Isbn").ToUpper());
                    PageState.Add("ProductQuan", dics[0].Get <int>("FirstSkinCapacity"));
                }
                sql  = "select * from SHHG_AimExamine..Products where SecondSkinIsbn='" + Isbn + "' and SecondSkinCapacity is not null";
                dics = DataHelper.QueryDictList(sql);
                if (dics.Count > 0)
                {
                    PageState.Add("ProductIsbn", dics[0].Get <string>("Isbn").ToUpper());
                    PageState.Add("ProductQuan", dics[0].Get <int>("SecondSkinCapacity"));
                }
                break;

            case "ScanSkin":    //判断包装编号是否存在
                string       skinNo = RequestData.Get <string>("SkinNo");
                IList <Skin> sEnts  = Skin.FindAll("from Skin where SkinNo='" + skinNo + "'");
                if (sEnts.Count > 0)    //如果该包装的记录不存在
                {
                    PageState.Add("SkinExist", true);
                }
                else
                {
                    PageState.Add("SkinExist", false);
                }
                break;

            case "ScanCompressor":
                string             seriesNo = RequestData.Get <string>("SeriesNo");
                IList <Compressor> cEnts    = Compressor.FindAll("from Compressor where SeriesNo='" + seriesNo + "'");
                if (cEnts.Count == 0)
                {
                    PageState.Add("CompressorExist", false);
                }
                else
                {
                    PageState.Add("CompressorExist", true);
                }
                break;

            case "InWarehouse":
                InWarehouse    iwEnt      = InWarehouse.TryFind(id);
                IList <string> entStrList = RequestData.GetList <string>("data");
                if (entStrList != null && entStrList.Count > 0)
                {
                    for (int j = 0; j < entStrList.Count; j++)
                    {
                        Newtonsoft.Json.Linq.JObject objL = JsonHelper.GetObject <Newtonsoft.Json.Linq.JObject>(entStrList[j]);
                        if (Convert.ToInt32(objL.Value <string>("ActuallyQuantity")) > 0)    //只有输入了入库数量才会增加实际入库记录
                        {
                            InWarehouseDetailDetail iwddEnt = new InWarehouseDetailDetail(); //新建一个实际入库详细信息
                            if (iwEnt.InWarehouseType == "采购入库")
                            {
                                iwddEnt.InWarehouseDetailId   = objL.Value <string>("Id");
                                iwddEnt.PurchaseOrderDetailId = objL.Value <string>("PurchaseOrderDetailId");
                            }
                            else    //其他入库的情形
                            {
                                iwddEnt.OtherInWarehouseDetailId = objL.Value <string>("Id");
                            }
                            iwddEnt.Quantity  = Convert.ToInt32(objL.Value <string>("ActuallyQuantity"));
                            iwddEnt.ProductId = objL.Value <string>("ProductId");
                            iwddEnt.Remark    = objL.Value <string>("Remark");
                            iwddEnt.DoCreate();

                            StockLog slEnt = new StockLog();    //创建库存变更日志
                            slEnt.InOrOutDetailId = objL.Value <string>("Id");
                            slEnt.InOrOutBillNo   = iwEnt.InWarehouseNo;
                            slEnt.OperateType     = "产品入库";
                            slEnt.WarehouseId     = iwEnt.WarehouseId;
                            slEnt.WarehouseName   = iwEnt.WarehouseName;
                            IList <StockInfo> siEnts = StockInfo.FindAllByProperties(StockInfo.Prop_ProductId, objL.Value <string>("ProductId"), StockInfo.Prop_WarehouseId, iwEnt.WarehouseId);
                            if (siEnts.Count > 0)
                            {
                                slEnt.StockQuantity = siEnts[0].StockQuantity;
                            }
                            slEnt.Quantity  = Convert.ToInt32(objL.Value <string>("ActuallyQuantity"));
                            slEnt.ProductId = objL.Value <string>("ProductId");
                            Product pEnt = Product.Find(objL.Value <string>("ProductId"));
                            slEnt.ProductName = pEnt.Name;
                            slEnt.ProductCode = pEnt.Code;
                            slEnt.ProductIsbn = pEnt.Isbn;
                            slEnt.ProductPcn  = pEnt.Pcn;
                            slEnt.DoCreate();

                            ProcessSkin(objL.Value <string>("SkinArray"), objL.Value <string>("ISBN"), iwEnt.Id);
                            ProcessCompressor(objL.Value <string>("SeriesArray"), objL.Value <string>("ISBN"), iwEnt.Id);
                            processremark(objL.Value <string>("Remark"), pEnt, iwEnt.Id);

                            //如果实际入库数量和未入库的数量相等 则入库状态为已入库
                            if (objL.Value <string>("ActuallyQuantity") == objL.Value <string>("NoIn"))
                            {
                                if (iwEnt.InWarehouseType == "采购入库")
                                {
                                    InWarehouseDetail iwdEnt = InWarehouseDetail.Find(objL.Value <string>("Id"));
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SkinArray")))
                                    {
                                        iwdEnt.SkinArray = objL.Value <string>("SkinArray").ToString();
                                    }
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SeriesArray")))
                                    {
                                        iwdEnt.SeriesArray = objL.Value <string>("SeriesArray").ToString();
                                    }
                                    iwdEnt.InWarehouseState = "已入库";
                                    iwdEnt.DoUpdate();
                                }
                                else
                                {
                                    OtherInWarehouseDetail oiwdEnt = OtherInWarehouseDetail.Find(objL.Value <string>("Id"));
                                    oiwdEnt.InWarehouseState = "已入库";
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SkinArray")))
                                    {
                                        oiwdEnt.SkinArray = objL.Value <string>("SkinArray").ToString();
                                    }
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SeriesArray")))
                                    {
                                        oiwdEnt.SeriesArray = objL.Value <string>("SeriesArray").ToString();
                                    }
                                    oiwdEnt.DoUpdate();
                                }
                            }
                            else    //如果未入库的数量不等于现在输入的数量。只更新包装和压缩机序列号集合
                            {
                                if (iwEnt.InWarehouseType == "采购入库")
                                {
                                    InWarehouseDetail iwdEnt = InWarehouseDetail.Find(objL.Value <string>("Id"));
                                    iwdEnt.Remark = objL.Value <string>("Remark");
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SkinArray")))
                                    {
                                        iwdEnt.SkinArray = objL.Value <string>("SkinArray").ToString();
                                    }
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SeriesArray")))
                                    {
                                        iwdEnt.SeriesArray = objL.Value <string>("SeriesArray").ToString();
                                    }
                                    iwdEnt.DoUpdate();
                                }
                                else
                                {
                                    OtherInWarehouseDetail oiwdEnt = OtherInWarehouseDetail.Find(objL.Value <string>("Id"));
                                    oiwdEnt.Remark = objL.Value <string>("Remark");
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SkinArray")))
                                    {
                                        oiwdEnt.SkinArray = objL.Value <string>("SkinArray").ToString();
                                    }
                                    if (!string.IsNullOrEmpty(objL.Value <string>("SeriesArray")))
                                    {
                                        oiwdEnt.SeriesArray = objL.Value <string>("SeriesArray").ToString();
                                    }
                                    oiwdEnt.DoUpdate();
                                }
                            }
                            //修改库存
                            InStorage(iwddEnt.ProductId, iwddEnt.Quantity.Value, iwEnt.WarehouseId);
                        }
                    }
                }
                ProcessInWarehouse(iwEnt);
                if (iwEnt.InWarehouseType == "采购入库")    //处理采购单和采购单详细
                {
                    ProcessPurchaseOrderAndDetail(iwEnt);
                }
                break;

            default:
                DoSelect();
                break;
            }
        }
        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;
            }
        }
Exemple #10
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 where = "";
            DataTable dt    = null;
            string    id    = Request["id"];
            PayBill   pbEnt = null;

            if (!string.IsNullOrEmpty(id))
            {
                pbEnt = PayBill.Find(id);
            }
            IList <PayBillDetail> pbdEnts = null;

            switch (action)
            {
            case "load":
                if (!string.IsNullOrEmpty(Request["PayBillNo"]))
                {
                    where += " and PayBillNo like '%" + Request["PayBillNo"].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 PayBillId from SHHG_AimExamine..PayBillDetail where  ProductCode like '%" + Request["ProductCode"] + "%')";
                }
                sql = @"select * from SHHG_AimExamine..PayBill where 1=1 " + where;
                dt  = DataHelper.QueryDataTable(GetPageSql(sql));
                Response.Write("{total:" + totalProperty + ",rows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "loaddetail":
                sql = @"select a.*,c.PurchaseOrderNo from SHHG_AimExamine..PayBillDetail a 
                            left join SHHG_AimExamine..PurchaseOrderDetail b on a.PurchaseOrderDetailId=b.Id 
                            left join SHHG_AimExamine..PurchaseOrder c on b.PurchaseOrderId=c.Id 
                            where a.PayBillId='" + id + "' order by a.ProductCode asc";
                dt  = DataHelper.QueryDataTable(sql);
                Response.Write("{innerrows:" + JsonHelper.GetJsonStringFromDataTable(dt) + "}");
                Response.End();
                break;

            case "delete":
                pbEnt   = PayBill.Find(id);
                pbdEnts = PayBillDetail.FindAllByProperty("PayBillId", id);
                foreach (PayBillDetail tempEnt in pbdEnts)
                {
                    //删除完付款单明细后需要更新入库单明细的生成付款单的数量
                    if (!string.IsNullOrEmpty(tempEnt.InWarehouseDetailId))
                    {
                        InWarehouseDetail iwdEnt = InWarehouseDetail.Find(tempEnt.InWarehouseDetailId);
                        iwdEnt.FuKuanDanQuan = iwdEnt.FuKuanDanQuan - tempEnt.PayQuantity;
                        iwdEnt.DoUpdate();
                        tempEnt.DoDelete();
                    }
                }
                //如果已经审批过了,还需要删除workflowinstance    task记录
                IList <WorkflowInstance> wiEnts = WorkflowInstance.FindAllByProperty(WorkflowInstance.Prop_EFormInstanceID, pbEnt.Id);
                foreach (WorkflowInstance wiEnt in wiEnts)
                {
                    IList <Task> tEnts = Task.FindAllByProperty(Task.Prop_WorkflowInstanceID, wiEnt.ID);
                    foreach (Task tEnt in tEnts)
                    {
                        tEnt.DoDelete();
                    }
                }
                pbEnt.DoDelete();
                Response.Write("{success:true}");
                Response.End();
                break;

            case "examine":
                WorkflowTemplate ne         = WorkflowTemplate.FindAllByProperties(Aim.WorkFlow.WorkflowTemplate.Prop_Code, Request["flowkey"])[0];
                string           formUrl    = "/PurchaseManagement/PayBillView.aspx?id=" + id; //启动流程表单路径,后面加上参数传入
                Guid             instanceid = Aim.WorkFlow.WorkFlow.StartWorkFlow(id, formUrl, "付款单【" + pbEnt.PayBillNo + "】申请人【" + pbEnt.CreateName + "】", Request["flowkey"], WebPortalService.CurrentUserInfo.UserID, WebPortalService.CurrentUserInfo.Name);
                pbEnt.WorkFlowState = "flowing";
                pbEnt.ExamineResult = "已提交";
                pbEnt.DoUpdate();
                Response.Write("{success:true,instanceid:'" + instanceid + "'}");
                Response.End();
                break;

            case "autoexec":
                Task task = Task.FindAllByProperties(Task.Prop_WorkflowInstanceID, Request["instanceid"])[0];
                Aim.WorkFlow.WorkFlow.AutoExecute(task);
                Response.Write("{success:true}");
                Response.End();
                break;
            }
        }