Beispiel #1
0
        public ActionResult Edit(string contactId)
        {
            IList <Global.Common.Models.ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll();

            //事项分类
            Global.Common.Models.ParamModel caseType = paramList.SingleOrDefault(m => m.ParamCode.Equals(Constants.SysParamType.ContactCaseType));
            ViewBag.CaseType = new SelectList(caseType.itemsList, "ParamItemValue", "ParamItemName");

            //公司名称
            Global.Common.Models.ParamModel company = paramList.SingleOrDefault(t => t.ParamCode == Constants.SysParamType.CompanyInfo);
            if (null == company)
            {
                company = new Global.Common.Models.ParamModel();
            }
            Global.Common.Models.ParamItemModel companyInfo = company.itemsList.SingleOrDefault(s => s.ParamItemName.Equals("公司名称"));

            ContactModel model = null;

            if (contactId == "0")
            {
                model             = new ContactModel();
                model.CompanyName = companyInfo == null ? "" : companyInfo.ParamItemValue;
            }
            else
            {
                model = ServiceProvider.ContactService.GetById(UtilsHelper.Decrypt2Int(contactId));
                IList <BusinessAttachmentModel> businessAttachList = ServiceProvider.BusinessAttachmentService.GetByBusinessTypeAndId(Constants.AttachmentBusinessType.联络单.GetHashCode(), model.ContactId);
                if (businessAttachList.Count > 0 && businessAttachList.First() != null)
                {
                    ViewBag.FileId   = UtilsHelper.Encrypt(businessAttachList.First().FileId.ToString());
                    ViewBag.FileName = businessAttachList.First().FileName;
                }
            }
            return(View(model));
        }
Beispiel #2
0
        public string GetOrderListJsonData()
        {
            IList <Global.Common.Models.ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll();

            Global.Common.Models.ParamModel company = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.CompanyInfo);
            if (null == company)
            {
                company = new Global.Common.Models.ParamModel();
            }
            Global.Common.Models.ParamItemModel pCompany = company.itemsList.SingleOrDefault(s => s.ParamItemName.Equals("公司编号"));

            StringBuilder            sb            = new StringBuilder();
            List <MeasureOrderModel> orderBillList = new List <MeasureOrderModel>();
            string endDate                  = DateTime.Now.ToString("yyyy-MM-dd");
            string startDate                = DateTime.Now.AddYears(-2).ToString("yyyy-MM-dd");
            string orderJsonData            = WSProvider.MeasureLabProvider.OrderSearch(startDate, endDate, Global.Business.ServiceProvider.ParamService.GetaccessToken(Instrument.Common.Constants.SysParamType.CompanyInfo));
            Dictionary <string, object> dic = ToolsLib.Utility.CommonUtils.JsonDeserialize(orderJsonData, typeof(Dictionary <string, object>)) as Dictionary <string, object>;

            if (dic["Msg"].ToString() == "OK")
            {
                orderBillList = ToolsLib.Utility.CommonUtils.JsonDeserialize(dic["Data"].ToString(), typeof(List <MeasureOrderModel>)) as List <MeasureOrderModel>;
            }
            else
            {
                return("{\"data\":[]}");
            }
            sb.Insert(0, "{\"data\":[");
            foreach (var item in orderBillList)
            {
                if (LoginHelper.LoginUserAuthorize.ContainsKey("订单查询-查看仪器"))
                {
                    sb.AppendFormat("[\" <a href='#' OrderNumber='{0}'  onclick='fnCheckInstrument(this)'>查看仪器</a>&nbsp;&nbsp;", item.OrderNumber);
                }
                if (LoginHelper.LoginUserAuthorize.ContainsKey("/Order/BatchDownloadCert".ToLower()))
                {
                    sb.AppendFormat("<a href='#' orderNumber='{0}' onclick='fnBatchDownloadCert(this)'>批量下载证书</a>\"", item.OrderNumber);
                }
                sb.AppendFormat(",\"{0}\"", item.OrderNumber);
                sb.AppendFormat(",\"{0}\"", item.CreateDate.ToShortDateString());
                sb.AppendFormat(",\"{0}\"", item.SaleName);
                sb.AppendFormat(",\"{0}\"", item.InstrumentCount);
                sb.AppendFormat(",\"{0}\"", item.IsComplete == true ? "完工" : "未完工");
                sb.AppendFormat(",\"{0}\"", item.IsCompleteCert == true ? "完工" : "未完工");
                //sb.AppendFormat(",\"{0}\"", item.IsInvoice == true ? "已开票" : "未开票");
                //sb.AppendFormat(",\"{0}\"", item.IsPay == true ? "已付款" : "未付款");
                sb.Append("],");
            }
            if (orderBillList.Count > 0)
            {
                sb.Remove(sb.Length - 1, 1);
            }
            sb.Append("]}");
            return(sb.ToString());
        }
Beispiel #3
0
        /// <summary>
        /// 生成委托单号
        /// </summary>
        /// <returns></returns>
        public string GenerateUniqueOrderNumber()
        {
            IList <Global.Common.Models.ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll();

            Global.Common.Models.ParamModel company = paramList.SingleOrDefault(t => t.ParamCode == Constants.SysParamType.CompanyInfo);
            if (null == company)
            {
                company = new Global.Common.Models.ParamModel();
            }
            Global.Common.Models.ParamItemModel CompanyCode = company.itemsList.SingleOrDefault(s => s.ParamItemName.Equals("公司编号"));
            string orderNumber = "";

            do
            {
                orderNumber = CompanyCode.ParamItemValue + DateTime.Now.ToString("yyyyMMdd") + ToolsLib.Utility.StrUtils.GetRandomNumb(4);
            }while (DBProvider.OrderDAO.IsExistOrderNumber(orderNumber));
            return(orderNumber);
        }
        public JsonResult GetAllCertificationJsonData()
        {
            DataTableUtils.DataTableModel dtm = DataTableUtils.GetJquerydataTableParams();
            //string where = GetCertificationSearchCondition(dtm);
            PagingModel paging = new PagingModel();

            paging.PageSize          = dtm.PageSize;
            paging.PageCurrent       = dtm.PageIndex;
            dtm.iTotalDisplayRecords = dtm.iTotalRecords;
            paging.FieldShow         = @"LogId,InstrumentId,CertificationCode,FileId,CheckDate,EndDate,SendInstrumentDate,CheckResult,ErrorValue,RecordState,IsUseding,CertMoney,CreateDate,CreateUser";
            paging.Where             = string.IsNullOrWhiteSpace(dtm.FieldCondition) ? dtm.FieldCondition = "1=1" : dtm.FieldCondition;
            //是否超期
            string overTime = Request["searchIsOverTime"];

            if (!string.IsNullOrEmpty(overTime))
            {
                if (overTime == "0")
                {
                    paging.Where = string.Format("{0} and {1}", paging.Where, "GetDate()<=EndDate");//未超期
                }
                else
                {
                    paging.Where = string.Format("{0} and {1}", paging.Where, "GetDate()>EndDate");//已超期
                }
            }
            //是否上传报告
            string UpdateReport = Request["searchIsUpdateReport"];

            if (!string.IsNullOrEmpty(UpdateReport))
            {
                paging.Where = string.Format("{0} and {1}", paging.Where, UpdateReport == "0" ? "(FileId IS null or FileId=0)" : "FileId>0");
            }

            //添加委托单查询条件.
            string orderParam = Request["InstrumentParam"];

            if (!string.IsNullOrWhiteSpace(orderParam))
            {
                orderParam = string.Format(" and {0}", orderParam);
            }
            paging.Where = string.Format("{0} and (InstrumentId In (Select InstrumentId From Instrument_BaseInfo Where {2}{1}))", paging.Where, orderParam, GetManageCondition("InstrumentForm=0 "));

            DateTime                dueEndDate;
            bool                    isOverTime = false;
            IList <Hashtable>       instrumentCertificationList = ServiceProvider.InstrumentCertificationService.GetInstrumentCertificationListForPaging(paging);
            IList <int>             instrumentIds  = instrumentCertificationList.Select(s => Convert.ToInt32(s["InstrumentId"])).Distinct().ToList();
            IList <InstrumentModel> instrumentList = ServiceProvider.InstrumentService.GetByIds(instrumentIds);

            dtm.iTotalRecords        = paging.RecordCount;
            dtm.iTotalDisplayRecords = dtm.iTotalRecords;

            ////系统参数
            IList <ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll();

            Global.Common.Models.OrgModel               belongDeptModel = new Global.Common.Models.OrgModel();
            Global.Common.Models.ParamItemModel         mInstrumentCate = null;
            IList <Global.Common.Models.ParamItemModel> paramItemList   = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.InstrumentCate).itemsList;
            ///周检状态
            IList <ParamItemModel> CertificationState = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.InstrumentCertificationState).itemsList;
            ParamItemModel         mParamItem         = new ParamItemModel();

            StringBuilder sbData = new StringBuilder();

            dtm.aaData = new List <List <string> >();
            foreach (var item in instrumentCertificationList)
            {
                InstrumentModel instrumentModel = instrumentList.SingleOrDefault(p => p.InstrumentId == Convert.ToInt32(item["InstrumentId"]));
                if (instrumentModel == null)
                {
                    instrumentModel = new InstrumentModel();
                }
                if (item["EndDate"] == null)
                {
                    isOverTime = true;
                }
                else
                {
                    dueEndDate = Convert.ToDateTime(string.Format("{0:d}", item["EndDate"]));
                    //是否过期
                    isOverTime = DateTime.Now.CompareTo(dueEndDate) > 0 ? true : false;
                }
                dtm.aaData.Add(new List <string>());
                sbData.Clear();
                sbData.AppendFormat("<a href='#' onclick='fnDetails({0})'>详细</a>&nbsp;&nbsp;", item["LogId"]);
                if (item["FileId"] != null)
                {
                    sbData.Append("<a href='#' onclick='fnDownFile(\"" + UtilsHelper.Encrypt(item["FileId"].ToString()) + "\");'>下 载</a>&nbsp;&nbsp;");
                    //sbData.Append(string.Format("<a href='/Certification/ReadCert?Id={1}' target='_blank' >{0}</a>","浏 览", UtilsHelper.Encrypt(item["FileId"].ToString())));
                }
                dtm.aaData[dtm.aaData.Count - 1].Add(sbData.ToString());
                mParamItem = CertificationState.SingleOrDefault(c => c.ParamItemValue == string.Format("{0}", item["RecordState"]));
                dtm.aaData[dtm.aaData.Count - 1].Add(mParamItem == null ? "" : mParamItem.ParamItemName);                    //状态
                dtm.aaData[dtm.aaData.Count - 1].Add(isOverTime ? "已超期" : "未超期");                                            //证书超期
                dtm.aaData[dtm.aaData.Count - 1].Add(item["FileId"] == null || item["FileId"].ToString() == "" ? "否" : "是"); //是否上传证书
                dtm.aaData[dtm.aaData.Count - 1].Add(item["EndDate"] == null ? null : string.Format("{0:yyyy-MM-dd}", item["EndDate"]));
                dtm.aaData[dtm.aaData.Count - 1].Add(item["CertificationCode"] == null ? "" : item["CertificationCode"].ToString());
                dtm.aaData[dtm.aaData.Count - 1].Add(string.Format("{0:F2}", item["CertMoney"]));
                dtm.aaData[dtm.aaData.Count - 1].Add(instrumentModel.InstrumentName);
                mInstrumentCate = paramItemList.SingleOrDefault(t => t.ParamItemValue == Convert.ToString(instrumentModel.InstrumentCate));
                dtm.aaData[dtm.aaData.Count - 1].Add(mInstrumentCate == null ? "" : mInstrumentCate.ParamItemName);
                dtm.aaData[dtm.aaData.Count - 1].Add(instrumentModel.ManageNo);
                dtm.aaData[dtm.aaData.Count - 1].Add(instrumentModel.Specification);
                dtm.aaData[dtm.aaData.Count - 1].Add(instrumentModel.SerialNo);
                dtm.aaData[dtm.aaData.Count - 1].Add(item["CheckDate"] == null ? null : string.Format("{0:yyyy-MM-dd}", item["CheckDate"]));

                dtm.aaData[dtm.aaData.Count - 1].Add(item["CheckResult"] == null ? null : item["CheckResult"].ToString());
                dtm.aaData[dtm.aaData.Count - 1].Add(item["ErrorValue"] == null ? null : item["ErrorValue"].ToString());

                dtm.aaData[dtm.aaData.Count - 1].Add(item["CreateDate"] == null ? null : string.Format("{0:yyyy-MM-dd}", item["CreateDate"]));
                dtm.aaData[dtm.aaData.Count - 1].Add(item["CreateUser"] == null ? null : item["CreateUser"].ToString());
            }
            JsonResult jr = Json(new
            {
                sEcho                = dtm.sEcho,
                iTotalRecords        = dtm.iTotalRecords,
                iTotalDisplayRecords = dtm.iTotalDisplayRecords,
                aaData               = dtm.aaData,
            }, JsonRequestBehavior.AllowGet);

            return(jr);
        }
Beispiel #5
0
        /// <summary>
        /// 仪器送检
        /// 仪器手机App接口和网页功能公用方法
        /// </summary>
        /// <param name="instrumentIds">以逗号分隔的仪器标识(未加密)</param>
        /// <param name="orderJson">送检单Json数据(送检人SendUser,App和网页分别独立赋值)</param>
        /// <returns></returns>
        public string SendOrder(string instrumentIds, string orderJson, string OrgName, string UserName, int UserId)
        {
            string result = "";
            //组装数据
            JObject orderObj         = JObject.Parse(orderJson);
            var     instrumentIdArr  = instrumentIds.Split(',');
            var     instrumentIdList = instrumentIdArr.Select(l => Convert.ToInt32(l)).ToList();
            IList <InstrumentModel>         instrumentList         = ServiceProvider.InstrumentService.GetByIdList(instrumentIdList);                            //对应的仪器列表
            IList <InstrumentWaitSendModel> instrumentWaitSendList = ServiceProvider.InstrumentWaitSendService.GetByInstrumentIdsList(instrumentIdList, UserId); //对应的送检仪器备注
            //单号
            string orderNumber = ServiceProvider.OrderService.GenerateUniqueOrderNumber();
            //组装送检仪器MD5Code字典
            Dictionary <int, string> dictionaryMd5 = new Dictionary <int, string>();

            foreach (int instrumentId in instrumentIdList)
            {
                dictionaryMd5.Add(instrumentId, Guid.NewGuid().ToString());
            }
            IList <Global.Common.Models.ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll();

            Global.Common.Models.ParamModel company = paramList.SingleOrDefault(t => t.ParamCode == Constants.SysParamType.CompanyInfo);
            if (null == company)
            {
                company = new Global.Common.Models.ParamModel();
            }
            Global.Common.Models.ParamItemModel CompanyName = company.itemsList.SingleOrDefault(s => s.ParamItemName.Equals("公司名称"));
            Global.Common.Models.ParamItemModel CompanyCode = company.itemsList.SingleOrDefault(s => s.ParamItemName.Equals("公司编号"));

            orderObj.Add("OrderNumber", orderNumber);
            orderObj.Add("CompanyName", CompanyName == null ? "" : CompanyName.ParamItemValue);
            orderObj.Add("CompanyCode", CompanyCode == null ? "" : CompanyCode.ParamItemValue);
            //送检人部门

            orderObj.Add("SendUserOrgName", OrgName);
            orderObj.Add("InstrumentCount", instrumentList.Count);
            //orderObj.Add("SendUser", LoginHelper.LoginUser.UserName);//送检人

            //仪器Json数据组装
            JArray projectJArr = new JArray();
            int    maxLen      = int.Parse(string.IsNullOrEmpty(WebUtils.GetSettingsValue("SendOrderLength")) ? "1000" : WebUtils.GetSettingsValue("SendOrderLength"));//一次送检的最大仪器数量
            int    leftCout    = instrumentList.Count % maxLen;
            int    count       = 0;
            InstrumentWaitSendModel instrumentWaitSendModel = null;

            foreach (var item in instrumentList)
            {
                instrumentWaitSendModel = instrumentWaitSendList.SingleOrDefault(I => I.InstrumentId.Equals(item.InstrumentId));
                count++;
                JObject projectObj = new JObject();
                projectObj.Add("CertificationNumber", item.CertificateNo);
                projectObj.Add("InstrumentName", item.InstrumentName);
                projectObj.Add("Specification", item.Specification);
                projectObj.Add("ManageNumber", item.ManageNo);
                projectObj.Add("MadeNumber", item.SerialNo);
                projectObj.Add("InspectDate", item.DueStartDate);
                projectObj.Add("DueEndDate", item.DueEndDate);
                projectObj.Add("InspectOrg", item.InspectOrg);
                projectObj.Add("Remark", instrumentWaitSendModel.Remark);
                projectObj.Add("MD5Code", dictionaryMd5[item.InstrumentId]);
                projectJArr.Add(projectObj);
                if (count % maxLen == 0 || (count % maxLen == leftCout))
                {
                    string En_Order   = SSOHelper.Encrypt(orderObj.ToString());
                    string En_Project = SSOHelper.Encrypt(projectJArr.ToString());

                    string jsonData = GRGTCommonUtils.WSProvider.EbusinessProvider.SendOrder(En_Order, En_Project, Global.Business.ServiceProvider.ParamService.GetaccessToken(Instrument.Common.Constants.SysParamType.CompanyInfo));
                    Dictionary <string, object> dic = ToolsLib.Utility.CommonUtils.JsonDeserialize(jsonData, typeof(Dictionary <string, object>)) as Dictionary <string, object>;
                    result = dic["Msg"].ToString();
                    projectJArr.Clear();
                    if (!result.Equals("OK"))//一次不成功则终止推送
                    {
                        break;
                    }
                }
            }

            if (result.Equals("OK"))
            {
                OrderModel order = new OrderModel();
                order.OrderNumber     = orderNumber;//单号
                order.SendUser        = UserName;
                order.UserId          = UserId;
                order.CreateUser      = order.SendUser;
                order.ReceivedUser    = "";
                order.InstrumentCount = instrumentIdList.Count;
                ServiceProvider.OrderService.Save(order);
                //新增送检仪器清单
                InstrumentModel instrumentModel = null;

                foreach (int instrumentId in instrumentIdList)
                {
                    OrderSendInstrumentModel model = new OrderSendInstrumentModel();
                    instrumentModel         = instrumentList.SingleOrDefault(I => I.InstrumentId.Equals(instrumentId));
                    instrumentWaitSendModel = instrumentWaitSendList.SingleOrDefault(I => I.InstrumentId.Equals(instrumentId));
                    if (instrumentModel == null)
                    {
                        continue;
                    }
                    model.InstrumentId        = instrumentId;
                    model.ItemCode            = dictionaryMd5[instrumentId];
                    model.OrderId             = order.OrderId;
                    model.InstrumentName      = instrumentModel.InstrumentName;
                    model.CertificationNumber = instrumentModel.CertificateNo;
                    model.SerialNo            = instrumentModel.SerialNo;
                    model.Specification       = instrumentModel.Specification;
                    model.ManageNo            = instrumentModel.ManageNo;
                    model.InspectDate         = instrumentModel.DueStartDate;
                    model.DueEndDate          = instrumentModel.DueEndDate;
                    model.InspectOrg          = "广电计量";//
                    model.Remark = instrumentWaitSendModel.Remark;
                    ServiceProvider.OrderSendInstrumentService.Save(model);
                }
            }

            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 批量导入固定资产
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="sucessMsg"></param>
        /// <returns></returns>
        public string BatchImportAssets(DataTable dt, ref string sucessMsg)
        {
            StringBuilder result = new StringBuilder();

            Global.Common.Models.ParamItemModel   paranItem = new Global.Common.Models.ParamItemModel();
            IList <Global.Common.Models.OrgModel> orgList   = Global.Business.ServiceProvider.OrgService.GetAll();
            //系统参数
            IList <Global.Common.Models.ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll();

            //器具状态
            Global.Common.Models.ParamModel instrumentState = paramList.SingleOrDefault(t => t.ParamCode == Constants.SysParamType.AssetsState);
            if (null == instrumentState)
            {
                instrumentState = new Global.Common.Models.ParamModel();
            }
            //资产属性
            Global.Common.Models.ParamModel calibrationType = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.CalibrationType);
            if (null == calibrationType)
            {
                calibrationType = new Global.Common.Models.ParamModel();
            }

            IList <Global.Common.Models.OrgModel> belongDepartList = new List <Global.Common.Models.OrgModel>();
            InstrumentModel instrument  = new InstrumentModel();
            int             sucessCount = 0;

            foreach (DataRow dr in dt.Rows)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(dr["资产名称"].ToString()))
                    {
                        continue;
                    }
                    instrument.InstrumentForm = Constants.InstrumentForm.固定资产.GetHashCode();
                    instrument.InstrumentName = UtilsHelper.SpecialCharValidate(dr["资产名称"].ToString());
                    instrument.Specification  = UtilsHelper.SpecialCharValidate(dr["型号规格"].ToString());
                    instrument.SerialNo       = UtilsHelper.SpecialCharValidate(dr["出厂编号"].ToString());
                    //设备状态
                    paranItem = instrumentState.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["设备状态"].ToString()));
                    instrument.RecordState = paranItem == null ? 0 : Convert.ToInt32(paranItem.ParamItemValue);
                    //资产属性
                    paranItem = calibrationType.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["资产属性"].ToString()));
                    instrument.CalibrationType = paranItem == null ? 0 : Convert.ToInt32(paranItem.ParamItemValue);
                    //所属部门
                    belongDepartList = orgList.Where(o => o.OrgName.Equals(dr["所属部门"].ToString().Trim())).ToList();
                    if (belongDepartList.Count > 0)
                    {
                        instrument.BelongDepart = belongDepartList[0].OrgCode;
                    }
                    else
                    {
                        instrument.BelongDepart = "";
                    }
                    instrument.AssetsNo   = UtilsHelper.SpecialCharValidate(dr["资产编号"].ToString());
                    instrument.ManageNo   = UtilsHelper.SpecialCharValidate(dr["管理编号"].ToString());
                    instrument.LeaderName = UtilsHelper.SpecialCharValidate(dr["保管人"].ToString());
                    instrument.StorePalce = UtilsHelper.SpecialCharValidate(dr["存放地点"].ToString());
                    if (!string.IsNullOrWhiteSpace(dr["购置日期"].ToString()))
                    {
                        DateTime buyDate;
                        if (DateTime.TryParse(dr["购置日期"].ToString(), out buyDate))
                        {
                            instrument.BuyDate = buyDate;
                        }
                        else
                        {
                            result.AppendLine("购置日期【" + dr["购置日期"].ToString() + "】格式不正确");
                            continue;
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(dr["购置金额"].ToString()))
                    {
                        instrument.Price = Convert.ToDecimal(dr["购置金额"].ToString());
                    }
                    instrument.Manufacturer         = UtilsHelper.SpecialCharValidate(dr["生产厂家"].ToString());
                    instrument.ManufactureContactor = UtilsHelper.SpecialCharValidate(dr["厂家联系信息"].ToString());
                    instrument.Remark = UtilsHelper.SpecialCharValidate(dr["备注"].ToString());

                    instrument.CreateUser     = LoginHelper.LoginUser.UserName;
                    instrument.LastUpdateUser = LoginHelper.LoginUser.UserName;
                    instrument.BarCode        = DateTime.Now.ToString("yyyyMMddff") + ToolsLib.Utility.StrUtils.GetRandomNumb(6);
                    instrument.ItemCode       = Guid.NewGuid().ToString();
                    //新增
                    DBProvider.InstrumentDAO.Add4Assets(instrument);

                    //导入成功记录
                    sucessCount++;
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                    result.AppendLine("未成功导入资产:名称(" + instrument.InstrumentName + ") 资产编号(" + instrument.AssetsNo + ")");
                }
            }
            sucessMsg = "共导入" + sucessCount + "条记录";
            return(result.ToString());
        }
Beispiel #7
0
        public string BatchImportInstrument(DataTable dt, ref string sucessMsg)
        {
            StringBuilder result = new StringBuilder();

            Global.Common.Models.ParamItemModel   paranItem = new Global.Common.Models.ParamItemModel();
            IList <Global.Common.Models.OrgModel> orgList   = Global.Business.ServiceProvider.OrgService.GetAll();
            ////组织根目录
            //orgList.SingleOrDefault(o=>o.OrgCode
            //系统参数
            IList <Global.Common.Models.ParamModel> paramList = Global.Business.ServiceProvider.ParamService.GetAll();

            //器具状态
            Global.Common.Models.ParamModel instrumentState = paramList.SingleOrDefault(t => t.ParamCode == Constants.SysParamType.InstrumentState);
            if (null == instrumentState)
            {
                instrumentState = new Global.Common.Models.ParamModel();
            }

            Global.Common.Models.ParamModel instrumentType = paramList.SingleOrDefault(t => t.ParamCode == UtilConstants.SysParamType.InstrumentType);
            if (null == instrumentType)
            {
                instrumentType = new Global.Common.Models.ParamModel();
            }

            //设备分类
            Global.Common.Models.ParamModel instrumentCate = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.InstrumentCate);
            if (null == instrumentCate)
            {
                instrumentCate = new Global.Common.Models.ParamModel();
            }

            //资产属性
            Global.Common.Models.ParamModel calibrationType = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.CalibrationType);
            if (null == calibrationType)
            {
                calibrationType = new Global.Common.Models.ParamModel();
            }

            //管理级别
            Global.Common.Models.ParamModel manageLevel = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.ManageLevel);
            if (null == manageLevel)
            {
                manageLevel = new Global.Common.Models.ParamModel();
            }

            //计量类别
            Global.Common.Models.ParamModel verificationType = paramList.SingleOrDefault(t => t.ParamCode == Instrument.Common.Constants.SysParamType.VerificationType);
            if (null == verificationType)
            {
                verificationType = new Global.Common.Models.ParamModel();
            }

            IList <Global.Common.Models.OrgModel> belongDepartList = new List <Global.Common.Models.OrgModel>();
            IList <InstrumentModel> instrumentList = new List <InstrumentModel>();
            //判断是否需要检测管理编号存在
            string IsJudgeExistManageNo = WebUtils.GetSettingsValue("IsJudgeExistManageNo");

            if (IsJudgeExistManageNo == "true")
            {
                instrumentList = GetAll().Where(t => !string.IsNullOrWhiteSpace(t.ManageNo)).ToList();
            }
            IList <string>  manageNoList    = new List <string>();
            int             count           = 0;
            bool            IsSynInstrument = LoginHelper.LoginUserAuthorize.Contains("/Instrument/SynInstrument".ToLower());
            InstrumentModel instrument      = new InstrumentModel();
            int             sucessCount     = 0;

            foreach (DataRow dr in dt.Rows)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(dr["仪器名称"].ToString()))
                    {
                        //result.AppendLine("仪器名称不能为空");
                        continue;
                    }
                    instrument.InstrumentForm = Constants.InstrumentForm.仪器.GetHashCode();//仪器
                    instrument.InstrumentName = UtilsHelper.SpecialCharValidate(dr["仪器名称"].ToString());
                    //型号
                    instrument.Specification = UtilsHelper.SpecialCharValidate(dr["仪器型号"].ToString());
                    //管理编号
                    instrument.ManageNo = UtilsHelper.SpecialCharValidate(dr["管理编号"].ToString());

                    if (IsJudgeExistManageNo == "true")
                    {
                        //在库中查找管理编号
                        count = instrumentList.Where(t => t.ManageNo.Trim().Equals(instrument.ManageNo.Trim())).Count();
                        //在导入的数据中找管理编号
                        if (count == 0)
                        {
                            count = manageNoList.Where(t => t.Trim().Equals(instrument.ManageNo.Trim())).Count();
                        }
                        if (count > 0)
                        {
                            result.AppendLine("存在相同的管理编号(" + instrument.ManageNo + ")");
                            continue;
                        }
                        if (!string.IsNullOrWhiteSpace(instrument.ManageNo))
                        {
                            manageNoList.Add(instrument.ManageNo);
                        }
                    }

                    //出厂编号
                    instrument.SerialNo = UtilsHelper.SpecialCharValidate(dr["出厂编号"].ToString());
                    //技术特征
                    instrument.TechniqueCharacter = UtilsHelper.SpecialCharValidate(dr["技术特征"].ToString());
                    //计量特性
                    instrument.MeasureCharacter = UtilsHelper.SpecialCharValidate(dr["计量特性"].ToString());
                    //设备状态
                    paranItem = instrumentState.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["设备状态"].ToString()));
                    instrument.RecordState = paranItem == null ? 0 : Convert.ToInt32(paranItem.ParamItemValue);

                    //设备分类
                    paranItem = instrumentCate.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["设备分类"].ToString()));
                    instrument.InstrumentCate = paranItem == null ? 1 : Convert.ToInt32(paranItem.ParamItemValue);

                    //资产属性
                    paranItem = calibrationType.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["资产属性"].ToString()));
                    instrument.CalibrationType = paranItem == null ? 0 : Convert.ToInt32(paranItem.ParamItemValue);

                    //设备类别
                    paranItem = instrumentType.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["设备类别"].ToString()));
                    instrument.InstrumentType = paranItem == null ? 0 : Convert.ToInt32(paranItem.ParamItemValue);

                    //管理级别
                    paranItem = manageLevel.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["管理级别"].ToString()));
                    instrument.ManageLevel = paranItem == null ? "A" : paranItem.ParamItemValue;

                    //计量类别
                    paranItem = verificationType.itemsList.SingleOrDefault(i => i.ParamItemName.Equals(dr["计量类别"].ToString()));
                    instrument.VerificationType = paranItem == null ? 0 : Convert.ToInt32(paranItem.ParamItemValue);
                    //英文名称
                    instrument.EnglishName = UtilsHelper.SpecialCharValidate(dr["英文名称"].ToString());
                    //所属部门
                    belongDepartList = orgList.Where(o => o.OrgName.Equals(dr["所属部门"].ToString().Trim())).ToList();
                    if (belongDepartList.Count > 0)
                    {
                        instrument.BelongDepart = belongDepartList[0].OrgCode;
                    }
                    else
                    {
                        instrument.BelongDepart = "";
                    }
                    //仪器证书信息
                    //证书编号
                    instrument.CertificateNo = UtilsHelper.SpecialCharValidate(dr["证书编号"].ToString());
                    if (!string.IsNullOrWhiteSpace(dr["校准日期"].ToString()))
                    {
                        instrument.DueStartDate = Convert.ToDateTime(dr["校准日期"].ToString());
                    }
                    if (!string.IsNullOrWhiteSpace(dr["到期日期"].ToString()))
                    {
                        instrument.DueEndDate = Convert.ToDateTime(dr["到期日期"].ToString());
                    }
                    //计量机构
                    instrument.InspectOrg = UtilsHelper.SpecialCharValidate(dr["计量机构"].ToString());

                    //资产编号
                    instrument.AssetsNo = UtilsHelper.SpecialCharValidate(dr["资产编号"].ToString());

                    //校验周期
                    instrument.InspectCycle = UtilsHelper.SpecialCharValidate(dr["检验周期"].ToString());
                    //使用年限
                    instrument.DurableYears = UtilsHelper.SpecialCharValidate(dr["使用年限"].ToString());
                    //保管人
                    instrument.LeaderName = UtilsHelper.SpecialCharValidate(dr["保管人"].ToString());
                    //项目组
                    instrument.ProjectTeam = UtilsHelper.SpecialCharValidate(dr["项目组"].ToString());
                    //说明书编号
                    //instrument.SpecificationCode = dr[23].ToString();
                    //存放地点
                    instrument.StorePalce = UtilsHelper.SpecialCharValidate(dr["存放地点"].ToString());
                    //购置日期
                    if (!string.IsNullOrWhiteSpace(dr["购置日期"].ToString()))
                    {
                        instrument.BuyDate = Convert.ToDateTime(dr["购置日期"].ToString());
                    }
                    //购置金额
                    if (!string.IsNullOrWhiteSpace(dr["购置金额"].ToString()))
                    {
                        instrument.Price = Convert.ToDecimal(dr["购置金额"].ToString());
                    }
                    //生产厂家
                    instrument.Manufacturer = UtilsHelper.SpecialCharValidate(dr["生产厂家"].ToString());
                    //厂家联系信息
                    instrument.ManufactureContactor = UtilsHelper.SpecialCharValidate(dr["厂家联系信息"].ToString());
                    //备注
                    instrument.Remark = UtilsHelper.SpecialCharValidate(dr["备注"].ToString());

                    instrument.CreateUser     = LoginHelper.LoginUser.UserName;
                    instrument.LastUpdateUser = LoginHelper.LoginUser.UserName;
                    instrument.BarCode        = DateTime.Now.ToString("yyyyMMddff") + ToolsLib.Utility.StrUtils.GetRandomNumb(6);
                    instrument.ItemCode       = Guid.NewGuid().ToString();
                    //新增仪器
                    DBProvider.InstrumentDAO.Add4Instrument(instrument);

                    //仪器证书信息 当三个都不为空时保存
                    if (!string.IsNullOrWhiteSpace(instrument.CertificateNo) && (instrument.DueStartDate != null) && (instrument.DueEndDate != null))
                    {
                        InstrumentCertificationModel cert = new InstrumentCertificationModel();
                        cert.InstrumentId      = instrument.InstrumentId;
                        cert.CertificationCode = UtilsHelper.SpecialCharValidate(instrument.CertificateNo);
                        cert.CheckDate         = instrument.DueStartDate;
                        cert.EndDate           = instrument.DueEndDate;
                        cert.MeasureOrg        = instrument.InspectOrg;
                        cert.RecordState       = Constants.InstrumentCertificationState.完成周检.GetHashCode();
                        ServiceProvider.InstrumentCertificationService.SaveCert(cert);
                        ServiceProvider.InstrumentCertificationService.UpdateCertificationAndState(instrument.InstrumentId);
                    }
                    //同步到业务系统
                    if (IsSynInstrument && instrument.InstrumentCate > 0)
                    {
                        BeginSynInstrument(instrument.InstrumentId);
                    }
                    //导入成功记录
                    sucessCount++;
                }
                catch (Exception ex)
                {
                    log.Error(ex.Message);
                    result.AppendLine("未成功导入仪器:名称(" + instrument.InstrumentName + ") 管理编号(" + instrument.ManageNo + ")");
                }
            }
            sucessMsg = "共导入" + sucessCount + "条记录";
            return(result.ToString());
        }