Example #1
0
        protected override void OnAfterHandleExcel(ref DataTable dtSheet)
        {
            var service = new SYS_BN_UserService();

            dtSheet.Columns.Add("CreatePerson", typeof(string));
            dtSheet.Columns.Add("CreateTime", typeof(DateTime));
            dtSheet.Columns.Add("ModifyPerson", typeof(string));
            dtSheet.Columns.Add("ModifyTime", typeof(DateTime));
            dtSheet.Columns.Add("UserBarcode", typeof(string));

            string maxBarCode = db.Sql(@"SELECT ISNULL(MAX(UserBarcode),'USER00000000') FROM dbo.SYS_BN_User WHERE UserBarcode IS NOT NULL AND LTRIM(RTRIM(UserBarcode)) <> ''").QuerySingle <string>();
            long   maxNum     = Convert.ToInt64(maxBarCode.Substring(4));

            var userCodeAndBarcodeList = db.Sql(@"SELECT UserCode,UserBarcode FROM dbo.SYS_BN_User WHERE UserBarcode IS NOT NULL AND LTRIM(RTRIM(UserBarcode)) <> ''").QueryMany <dynamic>();
            Dictionary <string, string> dicUserCodeAndBarcode = new Dictionary <string, string>();

            userCodeAndBarcodeList.ForEach(item => { dicUserCodeAndBarcode.Add(item.UserCode, item.UserBarcode); });

            var userName = MmsHelper.GetUserName();
            var newDT    = DateTime.Now;

            foreach (DataRow item in dtSheet.Rows)
            {
                string dName = item["DepartmentName"].ToString();
                string sql   = string.Format(@"select DepartmentCode from SYS_BN_Department where DepartmentName='{0}'", dName);
                string hID   = db.Sql(sql).QuerySingle <string>();
                item["DepartmentCode"] = hID;

                string isenable = item["IsEnable"].ToString();
                if (isenable == "否")
                {
                    item["IsEnable"] = 0;
                }
                else
                {
                    item["IsEnable"] = 1;
                }

                var UserCode = item["UserCode"].ToString();

                item["CreatePerson"] = userName;
                item["CreateTime"]   = newDT;
                item["ModifyPerson"] = userName;
                item["ModifyTime"]   = newDT;

                if (dicUserCodeAndBarcode.ContainsKey(UserCode))
                {
                    item["UserBarcode"] = dicUserCodeAndBarcode[UserCode];
                }
                else
                {
                    Interlocked.Increment(ref maxNum);
                    item["UserBarcode"] = "USER" + maxNum.ToString().PadLeft(8, '0');
                }

                var Query = ParamDelete.Instance().AndWhere("UserCode", UserCode);
                service.Delete(Query);
            }
            base.OnAfterHandleExcel(ref dtSheet);
        }
Example #2
0
        public dynamic GetMaterialDetailByPCode(string ppdID)
        {
            var data = new WinFormClientService().GetPickMaterialDetailByPCode(ppdID);
            //var data = new WinFormClientService().GetMaterialDetailByPCode(ppdID, partCode);
            MES_MaterialPickMainService pickMainServices = new MES_MaterialPickMainService();

            if (!data.Result)
            {
                return(new
                {
                    Result = false,
                    Msg = data.Msg
                });
            }
            var warehouseList = data.Data.listmain;
            var winform       = new WinFormClientService();
            var list          = data.Data.listDetail;

            try
            {
                using (db.UseTransaction(true))
                {
                    for (int i = 0; i < warehouseList.Count - 1; i++)
                    {
                        string deststring = warehouseList[i].WarehouseCode;

                        if (string.IsNullOrEmpty(deststring))
                        {
                            throw new Exception(@"未查到" + warehouseList[i].InventoryName + "的仓库信息!");
                        }
                        for (int j = i + 1; j < warehouseList.Count; j++)
                        {
                            if (deststring.CompareTo(warehouseList[j].WarehouseCode) == 0)
                            {
                                warehouseList.RemoveAt(j);
                                j--;
                                continue;
                            }
                        }
                    }
                    int maxID = pickMainServices.GetModelList().Count > 0 ?
                                pickMainServices.GetModelList().Max(a => a.ID) + 1 : 1;

                    for (int t = 0; t < warehouseList.Count; t++)
                    {
                        SYS_BN_User          user     = new SYS_BN_UserService().GetModel(ParamQuery.Instance().AndWhere("IsEnable", 1).AndWhere("UserCode", MmsHelper.GetUserCode()));
                        MES_MaterialPickMain pickMain = new MES_MaterialPickMain();
                        pickMain.BillCode       = MmsHelper.GetOrderNumber("MES_MaterialPickMain", "BillCode", "CJLL", "", "");
                        pickMain.ID             = maxID;
                        pickMain.PickingDate    = DateTime.Now;
                        pickMain.ProjectName    = warehouseList[0].ProjectName;
                        pickMain.ContractCode   = warehouseList[0].ContractCode;
                        pickMain.BillState      = 1;
                        pickMain.IsEnable       = 1;
                        pickMain.DepartmentID   = user.DepartmentCode;
                        pickMain.DepartmentName = user.DepartmentName;
                        pickMain.WarehouseCode  = warehouseList[t].WarehouseCode;
                        pickMain.WarehouseName  = warehouseList[t].WarehouseName;
                        pickMain.CreateTime     = DateTime.Now;
                        pickMain.CreatePerson   = MmsHelper.GetUserName();
                        pickMain.ModifyPerson   = MmsHelper.GetUserName();
                        pickMain.ModifyTime     = DateTime.Now;
                        pickMain.ProductID      = warehouseList[t].ProductID;
                        pickMain.ProductName    = warehouseList[t].ProductName;
                        //pickMain.ProductName = productName;
                        //int res = db.Insert<MES_MaterialPickMain>("MES_MaterialPickMain", pickMain).Execute();
                        int res = db.Sql(WinFormClientService.GetInsertSQL(pickMain)).Execute();
                        maxID++;
                        foreach (var item in list)
                        {
                            if (item.WarehouseCode.Equals(warehouseList[t].WarehouseCode))
                            {
                                MES_MaterialPickDetail pickDetail = new MES_MaterialPickDetail();
                                pickDetail.InventoryCode    = item.InventoryCode;
                                pickDetail.InventoryName    = item.InventoryName;
                                pickDetail.MainID           = pickMain.ID;
                                pickDetail.Model            = item.Model;
                                pickDetail.ContractCode     = item.ContractCode;
                                pickDetail.ProjectName      = item.ProjectName;
                                pickDetail.RequiredQuantity = item.InventoryQuantity;
                                pickDetail.Unit             = item.Unit;
                                pickDetail.IsEnable         = 1;
                                pickDetail.CreateTime       = DateTime.Now;
                                pickDetail.CreatePerson     = MmsHelper.GetUserName();
                                pickDetail.ModifyPerson     = MmsHelper.GetUserName();
                                pickDetail.ModifyTime       = DateTime.Now;
                                res = db.Insert("MES_MaterialPickDetail", pickDetail).AutoMap(a => a.ID).ExecuteReturnLastId <int>();
                            }
                        }
                    }
                    int aaa = 1;
                    db.Commit();
                    return(new ResultModel
                    {
                        Result = true,
                        Msg = "生成领料单成功"
                    });
                }
            }
            catch (Exception ex)
            {
                db.Rollback();
                return(new
                {
                    Result = false,
                    Msg = ex.Message
                });
            }
        }