/// <summary>
        /// 导出组织机构
        /// </summary>
        /// <param name="context"></param>
        private void OnExportOrgDepmt(HttpContext context)
        {
            var bll = new OrgDepmt();
            var dt  = bll.GetExportData("", null);

            HttpClientHelper.Export(context, dt);
        }
Exemple #2
0
        public ResResultModel SaveOrgDepmt(OrgDepmtFmModel model)
        {
            try
            {
                if (model == null)
                {
                    return(ResResult.Response(false, "未获取到任何参数"));
                }
                if (string.IsNullOrWhiteSpace(model.Coded) || string.IsNullOrWhiteSpace(model.Named))
                {
                    return(ResResult.Response(false, "编码或名称不能为空字符串"));
                }
                var Id       = Guid.Empty;
                var parentId = Guid.Empty;
                if (model.Id != null && !string.IsNullOrWhiteSpace(model.Id.ToString()))
                {
                    Guid.TryParse(model.Id.ToString(), out Id);
                }
                if (model.ParentId != null && !string.IsNullOrWhiteSpace(model.ParentId.ToString()))
                {
                    Guid.TryParse(model.ParentId.ToString(), out parentId);
                }

                var bll    = new OrgDepmt();
                int effect = 0;

                var modelInfo = new OrgDepmtInfo();
                modelInfo.Id              = Id;
                modelInfo.ParentId        = parentId;
                modelInfo.Coded           = model.Coded;
                modelInfo.Named           = model.Named;
                modelInfo.Remark          = model.Remark;
                modelInfo.Sort            = model.Sort;
                modelInfo.LastUpdatedDate = DateTime.Now;
                modelInfo.UserId          = Guid.Parse(SecurityService.GetUserId().ToString());

                if (modelInfo.Id.Equals(Guid.Empty))
                {
                    modelInfo.Id = Guid.NewGuid();
                    effect       = bll.InsertByOutput(modelInfo);
                }
                else
                {
                    effect = bll.Update(modelInfo);
                }
                if (effect < 1)
                {
                    return(ResResult.Response(false, "操作失败,数据库操作异常"));
                }

                return(ResResult.Response(true, "操作成功", modelInfo.Id));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, "操作异常:" + ex.Message + ""));
            }
        }
Exemple #3
0
 public ResResultModel GetOrgDepmtTree()
 {
     try
     {
         var bll = new OrgDepmt();
         return(ResResult.Response(true, "", bll.GetTreeJson()));
     }
     catch (Exception ex)
     {
         return(ResResult.Response(false, ex.Message, ""));
     }
 }
Exemple #4
0
 public ResResultModel DeleteOrgDepmt(Guid Id)
 {
     try
     {
         if (Id.Equals(Guid.Empty))
         {
             return(ResResult.Response(false, "参数值无效"));
         }
         var bll = new OrgDepmt();
         return(ResResult.Response(bll.Delete(Id) > 0, ""));
     }
     catch (Exception ex)
     {
         return(ResResult.Response(false, "操作异常:" + ex.Message + ""));
     }
 }
Exemple #5
0
 public ResResultModel GetOrgDepmtTreeByCompanyId(object companyId)
 {
     try
     {
         var gId = Guid.Empty;
         if (companyId != null)
         {
             Guid.TryParse(companyId.ToString(), out gId);
         }
         var bll = new OrgDepmt();
         return(ResResult.Response(true, "", bll.GetTreeByCompany(gId)));
     }
     catch (Exception ex)
     {
         return(ResResult.Response(false, ex.Message, ""));
     }
 }
Exemple #6
0
        private void ImportByAssetInStore(HttpContext context, HttpPostedFile file)
        {
            //NpoiHelper npoi = new NpoiHelper();
            //var dt = npoi.GetExcelData(Path.GetExtension(file.FileName), file.InputStream);
            var dt  = new DataTable();
            var drc = dt.Rows;

            if (drc.Count == 0)
            {
                context.Response.Write(ResResult.ResJsonString(false, "导入的数据不能为空字符串", ""));
                return;
            }
            Category cBll  = new Category();
            OrgDepmt odBll = new OrgDepmt();
            Region   rBll  = new Region();
            decimal  d     = decimal.MinValue;
            DateTime time  = DateTime.MinValue;
            var      list  = new List <AssetInStoreInfo>();

            foreach (DataRow dr in drc)
            {
                if (string.IsNullOrWhiteSpace(dr["资产条码"].ToString()) || string.IsNullOrWhiteSpace(dr["资产名称"].ToString()) || string.IsNullOrWhiteSpace(dr["资产类别编码"].ToString()) || string.IsNullOrWhiteSpace(dr["使用公司编码"].ToString()) || string.IsNullOrWhiteSpace(dr["存放地点"].ToString()) || string.IsNullOrWhiteSpace(dr["所属公司编码"].ToString()) || string.IsNullOrWhiteSpace(dr["购入时间"].ToString()))
                {
                    throw new ArgumentException("带有“*”的列为必填项,请正确操作");
                }
                var model = new AssetInStoreInfo();
                model.Barcode = dr["资产条码"].ToString();
                model.Named   = dr["资产名称"].ToString();
                var categoryModel = cBll.GetModelByCode(dr["资产类别编码"].ToString().Trim());
                if (categoryModel == null)
                {
                    throw new ArgumentException("资产类别编码“" + dr["资产类别编码"].ToString().Trim() + "”对应的数据不存在或已被删除");
                }
                model.CategoryId = categoryModel.Id;

                if (!decimal.TryParse(dr["金额"].ToString(), out d))
                {
                    throw new ArgumentException("金额“" + dr["金额"].ToString() + "”不正确");
                }
                model.Price     = d;
                model.SpecModel = dr["规格型号"].ToString();
                model.Unit      = dr["计量单位"].ToString();

                var useCompanyModel = odBll.GetModelByCode(dr["使用公司编码"].ToString());
                if (useCompanyModel == null)
                {
                    throw new ArgumentException("使用公司编码“" + dr["使用公司编码"].ToString() + "”对应的数据不存在或已被删除");
                }
                var orgdModel = odBll.GetModelByCode(dr["使用部门编码"].ToString());
                if (orgdModel == null)
                {
                    throw new ArgumentException("使用部门编码“" + dr["使用部门编码"].ToString() + "”对应的数据不存在或已被删除");
                }

                model.UseCompanyId = useCompanyModel.Id;
                model.UseDepmtId   = orgdModel.Id;

                var rModel = rBll.GetModelByCode(dr["区域编码"].ToString());
                if (rModel == null)
                {
                    throw new ArgumentException("区域编码“" + dr["区域编码"].ToString() + "”对应的数据不存在或已被删除");
                }
                model.RegionId = rModel.Id;

                var ownedCompanyModel = odBll.GetModelByCode(dr["所属公司编码"].ToString());
                if (ownedCompanyModel == null)
                {
                    throw new ArgumentException("所属公司编码“" + dr["所属公司编码"].ToString() + "”对应的数据不存在或已被删除");
                }
                model.OwnedCompanyId = ownedCompanyModel.Id;

                model.UsePerson     = dr["使用人"].ToString();
                model.StoreLocation = dr["存放地点"].ToString();
                model.Manager       = dr["管理员姓名"].ToString();
                if (!DateTime.TryParse(dr["购入时间"].ToString(), out time))
                {
                    throw new ArgumentException("购入时间“" + dr["购入时间"].ToString() + "”不正确");
                }
                model.BuyDate  = time;
                model.Supplier = dr["供应商"].ToString();
                model.Remark   = dr["备注"].ToString();
                model.SNCode   = dr["SN号"].ToString();

                model.UseExpireMonth  = 1200;
                model.PictureId       = Guid.Empty;
                model.LastUpdatedDate = DateTime.Now;

                list.Add(model);
            }

            AssetInStore aisBll = new AssetInStore();
            var          index  = 0;
            var          userId = WebCommon.GetUserId();

            foreach (var model in list)
            {
                model.UserId = userId;
                if (aisBll.Insert(model) < 1)
                {
                    throw new ArgumentException(string.Format("{0}", index > 0 ? "部分数据已经成功导入,但是执行到第“" + index + "”行时发生异常" : "数据导入失败,行“" + index + "”发生异常"));
                }
                index++;
            }
            context.Response.Write(ResResult.ResJsonString(true, "导入成功", ""));
        }
        /// <summary>
        /// 导入资产信息
        /// </summary>
        /// <param name="context"></param>
        private void OnImportProduct(HttpContext context)
        {
            var files = context.Request.Files;

            if (files.Count == 0)
            {
                throw new ArgumentException(MC.M_UploadFileNotExist);
            }

            var appCode = context.Request.Form["AppCode"];
            var userId  = WebCommon.GetUserId();
            var orgId   = new Staff().GetOrgId(userId);

            var bll      = new Product();
            var orgBll   = new OrgDepmt();
            var spBll    = new StoragePlace();
            var cBll     = new Category();
            int effect   = 0;
            var currTime = DateTime.Now;

            foreach (string item in files.AllKeys)
            {
                HttpPostedFile file = files[item];
                if (file == null || file.ContentLength == 0)
                {
                    continue;
                }
                var dt = ExcelHelper.Import(file.InputStream);
                if (dt == null || dt.Rows.Count == 0)
                {
                    throw new CustomException(MC.M_UploadFileDataNotExist);
                }
                //var id = Guid.Empty;

                var drc = dt.Rows;
                foreach (DataRow dr in drc)
                {
                    var currInfo = new ProductInfo();

                    #region 请求参数集

                    if (dr["资产分类编码"] != null)
                    {
                        currInfo.CategoryCode = dr["资产分类编码"].ToString().Trim();
                    }
                    if (dr["资产分类"] != null)
                    {
                        currInfo.CategoryName = dr["资产分类"].ToString().Trim();
                    }

                    if (string.IsNullOrWhiteSpace(currInfo.CategoryCode) || string.IsNullOrWhiteSpace(currInfo.CategoryName))
                    {
                        throw new CustomException(MC.GetString(MC.Request_InvalidArgument, "资产编码、资产名称"));
                    }
                    var oldCategoryInfo = cBll.GetModel(currInfo.CategoryCode, currInfo.CategoryName);
                    if (oldCategoryInfo == null)
                    {
                        throw new CustomException(MC.GetString(MC.P_InvalidError, string.Format("资产分类编码“{0}”、资产分类为“{1}”", currInfo.CategoryCode, currInfo.CategoryName)));
                    }
                    currInfo.CategoryId = oldCategoryInfo.Id;

                    //if (dr["资产编码"] != null) currInfo.Coded = dr["资产编码"].ToString().Trim();
                    if (dr["资产名称"] != null)
                    {
                        currInfo.Named = dr["资产名称"].ToString().Trim();
                    }
                    //if (bll.IsExist(currInfo.Coded, currInfo.Named)) continue;
                    var sCoded = bll.GetRndCode(oldCategoryInfo.Coded, 8);
                    currInfo.Coded = sCoded;
                    var qty = 0;
                    if (dr["数量"] != null)
                    {
                        int.TryParse(dr["数量"].ToString(), out qty);
                    }
                    currInfo.Qty = 1;
                    if (qty < 1)
                    {
                        throw new CustomException(string.Format("数量为“{0}”", qty));
                    }
                    if (dr["规格型号"] != null)
                    {
                        currInfo.SpecModel = dr["规格型号"].ToString().Trim();
                    }
                    var price = 0m;
                    if (dr["单价"] != null && decimal.TryParse(dr["单价"].ToString(), out price))
                    {
                        currInfo.Price = price;
                    }
                    var amount = 0m;
                    if (dr["金额"] != null && decimal.TryParse(dr["金额"].ToString(), out amount))
                    {
                        currInfo.Amount = amount;
                    }
                    if (dr["计量单位"] != null)
                    {
                        currInfo.MeterUnit = dr["计量单位"].ToString().Trim();
                    }
                    var pieceQty = 0;
                    //if (dr["件数"] != null && int.TryParse(dr["件数"].ToString(),out pieceQty)) currInfo.PieceQty = pieceQty;
                    if (dr["资产属性"] != null)
                    {
                        currInfo.Pattr = dr["资产属性"].ToString().Trim();
                    }
                    if (dr["资产来源"] != null)
                    {
                        currInfo.SourceFrom = dr["资产来源"].ToString().Trim();
                    }
                    if (dr["供应商"] != null)
                    {
                        currInfo.Supplier = dr["供应商"].ToString().Trim();
                    }
                    var buyDate = DateTime.MinValue;
                    if (dr["购入日期"] != null)
                    {
                        DateTime.TryParse(dr["购入日期"].ToString(), out buyDate);
                    }
                    if (buyDate == DateTime.MinValue)
                    {
                        buyDate = DateTime.Parse("1754-01-01");
                    }
                    currInfo.BuyDate = buyDate;
                    var enableDate = DateTime.MinValue;
                    if (dr["启用日期"] != null && DateTime.TryParse(dr["启用日期"].ToString(), out enableDate))
                    {
                        currInfo.EnableDate = enableDate.ToString("yyyy-MM-dd");
                    }
                    if (dr["使用期限"] != null)
                    {
                        currInfo.UseDateLimit = dr["使用期限"].ToString().Trim();
                    }
                    if (dr["使用部门"] != null)
                    {
                        currInfo.UseOrgName = dr["使用部门"].ToString().Trim();
                    }
                    if (dr["使用部门编码"] != null)
                    {
                        currInfo.UseOrgCode = dr["使用部门编码"].ToString().Trim();
                    }
                    if (!string.IsNullOrEmpty(currInfo.UseOrgCode) || !string.IsNullOrEmpty(currInfo.UseOrgName))
                    {
                        var useOrgInfo = orgBll.GetModel(currInfo.UseOrgCode, currInfo.UseOrgName);
                        if (useOrgInfo == null)
                        {
                            throw new CustomException(MC.GetString(MC.P_InvalidError, string.Format("使用部门编码“{0}”、使用部门“{1}”", currInfo.UseOrgCode, currInfo.UseOrgName)));
                        }
                        currInfo.UseDepmtId = useOrgInfo.Id;
                    }

                    if (dr["实物管理部门"] != null)
                    {
                        currInfo.MgrOrgName = dr["实物管理部门"].ToString().Trim();
                    }
                    if (dr["实物管理部门编码"] != null)
                    {
                        currInfo.MgrOrgCode = dr["实物管理部门编码"].ToString().Trim();
                    }
                    if (!string.IsNullOrEmpty(currInfo.MgrOrgCode) || !string.IsNullOrEmpty(currInfo.MgrOrgName))
                    {
                        var mgrOrgInfo = orgBll.GetModel(currInfo.MgrOrgCode, currInfo.MgrOrgName);
                        if (mgrOrgInfo == null)
                        {
                            throw new CustomException(MC.GetString(MC.P_InvalidError, string.Format("实物管理部门编码“{0}”、实物管理部门“{1}”", currInfo.MgrOrgCode, currInfo.MgrOrgName)));
                        }
                        currInfo.MgrDepmtId = mgrOrgInfo.Id;
                    }

                    if (dr["存放地点"] != null)
                    {
                        currInfo.StoragePlaceName = dr["存放地点"].ToString().Trim();
                    }
                    if (dr["存放地点编码"] != null)
                    {
                        currInfo.StoragePlaceCode = dr["存放地点编码"].ToString().Trim();
                    }
                    if (!string.IsNullOrEmpty(currInfo.StoragePlaceCode) || !string.IsNullOrEmpty(currInfo.StoragePlaceName))
                    {
                        var storagePlaceInfo = spBll.GetModel(currInfo.StoragePlaceCode, currInfo.StoragePlaceName);
                        if (storagePlaceInfo == null)
                        {
                            throw new CustomException(MC.GetString(MC.P_InvalidError, string.Format("存放地点编码“{0}”、存放地点“{1}”", currInfo.StoragePlaceCode, currInfo.StoragePlaceName)));
                        }
                        currInfo.StoragePlaceId = storagePlaceInfo.Id;
                    }

                    if (dr["使用人"] != null)
                    {
                        currInfo.UsePersonName = dr["使用人"].ToString().Trim();
                    }

                    #endregion

                    currInfo.AppCode         = appCode;
                    currInfo.UserId          = userId;
                    currInfo.DepmtId         = orgId;
                    currInfo.RecordDate      = currTime;
                    currInfo.LastUpdatedDate = currTime;

                    effect += bll.Insert(currInfo);

                    if (qty > 1)
                    {
                        for (var i = 1; i < qty; i++)
                        {
                            currInfo.Coded = bll.GetRndCode(sCoded, 11);
                            effect        += bll.Insert(currInfo);
                        }
                    }
                }
            }
            if (effect < 1)
            {
                context.Response.Write(ResResult.ResJsonString(false, MC.M_Save_Error, ""));
            }
            else
            {
                context.Response.Write(ResResult.ResJsonString(true, MC.M_Save_Ok, effect));
            }
        }
        /// <summary>
        /// 导入组织机构
        /// </summary>
        /// <param name="context"></param>
        private void OnImportOrgDepmt(HttpContext context)
        {
            var files = context.Request.Files;

            if (files.Count == 0)
            {
                throw new ArgumentException(MC.M_UploadFileNotExist);
            }

            var appCode = context.Request.Form["AppCode"];
            var userId  = WebCommon.GetUserId();
            var orgId   = new Staff().GetOrgId(userId);

            var bll    = new OrgDepmt();
            int effect = 0;

            var categories = bll.GetList();

            foreach (string item in files.AllKeys)
            {
                HttpPostedFile file = files[item];
                if (file == null || file.ContentLength == 0)
                {
                    continue;
                }
                var dt = ExcelHelper.Import(file.InputStream);
                if (dt == null || dt.Rows.Count == 0)
                {
                    throw new ArgumentException(MC.M_UploadFileDataNotExist);
                }
                var currTime = DateTime.Now;
                var sEmpty   = string.Empty;

                var drc = dt.Rows;
                foreach (DataRow dr in drc)
                {
                    #region 请求参数集

                    string coded = string.Empty;
                    if (dr["资产分类编码"] != null)
                    {
                        coded = dr["资产分类编码"].ToString().Trim();
                    }
                    string named = string.Empty;
                    if (dr["资产分类名称"] != null)
                    {
                        named = dr["资产分类名称"].ToString().Trim();
                    }
                    string parentCode = string.Empty;
                    if (dr["所属上级分类编码"] != null)
                    {
                        parentCode = dr["所属上级分类编码"].ToString().Trim();
                    }
                    string parentName = string.Empty;
                    if (dr["所属上级分类"] != null)
                    {
                        parentName = dr["所属上级分类"].ToString().Trim();
                    }
                    int sort = 0;
                    if (dr["排序"] != null)
                    {
                        int.TryParse(dr["排序"].ToString(), out sort);
                    }
                    if (string.IsNullOrWhiteSpace(coded) || string.IsNullOrWhiteSpace(named))
                    {
                        continue;
                    }

                    var id       = Guid.NewGuid();
                    var parentId = Guid.Empty;
                    if (string.IsNullOrWhiteSpace(parentCode))
                    {
                        parentCode = named;
                    }
                    var parentInfo = bll.GetModel(parentCode, parentName);
                    var step       = id.ToString();
                    var ids        = new List <Guid>();
                    if (parentInfo != null)
                    {
                        parentId = parentInfo.Id;
                        bll.GetStep(categories, parentId, ref ids);
                        if (ids.Count > 0)
                        {
                            Array.Reverse(ids.ToArray());
                            step += "," + string.Join(",", ids.ToArray());
                        }
                    }

                    var currInfo = new OrgDepmtInfo(id, appCode, userId, orgId, parentId, coded, named, step, sort, sEmpty, currTime, currTime);
                    effect += bll.Insert(currInfo);

                    #endregion
                }
            }
            if (effect < 1)
            {
                context.Response.Write(ResResult.ResJsonString(false, MC.M_Save_Error, ""));
            }
            else
            {
                context.Response.Write(ResResult.ResJsonString(true, MC.M_Save_Ok, effect));
            }
        }