Ejemplo n.º 1
0
        public static CustomItemModel ChangeTOCustomItemModel(CustomItemValue civ)
        {
            try
            {
                if (civ == null)
                {
                    return(null);
                }

                CustomItemModel cm = new CustomItemModel();
                cm.Name  = civ.ItemName;
                cm.Value = civ.ItemValue;

                return(cm);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取excel表格的  自定义项 和 对应的值
        /// </summary>
        /// <param name="informationList"></param>
        /// <param name="customItemList"></param>
        /// <param name="customItemValueList"></param>
        private void GetCustomItemAndValue(string account, ref List <Information> informationList,
                                           ref List <CustomItem> customItemList, ref List <CustomItemValue> customItemValueList)
        {
            try
            {
                if (informationList == null || informationList.Count <= 0)
                {
                    return;
                }
                int lastSheetRowCount = 0;
                for (int i = 0; i < _workbook.NumberOfSheets; i++)
                {
                    _currentSheet = _workbook.GetSheetAt(i);

                    if (i > 0)
                    {
                        lastSheetRowCount += _workbook.GetSheetAt(i - 1).LastRowNum - 1;
                    }

                    IRow _row     = _currentSheet.GetRow(0);
                    int  colCount = _row.LastCellNum;
                    for (int k = baseColCount; k < colCount; k++)
                    {
                        var tmp = _row.GetCell(k) == null ? null : _row.GetCell(k).StringCellValue;
                        if (customItemList.SingleOrDefault(n => n.ItemContent == tmp) == null)
                        {
                            CustomItem ci = new CustomItem();
                            ci.ItemContent  = tmp;
                            ci.ItemName     = account + "C" + TimeManager.GetTimeSpan();
                            ci.InsertMember = account;
                            ci.InsertTime   = DateTime.Now;
                            ci.IsDeleted    = false;
                            ci.UpdateTime   = DateTime.Now;

                            customItemList.Add(ci);
                        }

                        for (int j = 1; j < _currentSheet.LastRowNum + 1; j++)
                        {
                            var tmpvalue = _row.GetCell(k) == null ? null : _row.GetCell(k).StringCellValue;
                            var ci       = customItemList.SingleOrDefault(n => n.ItemContent == tmpvalue);
                            if (ci == null)
                            {
                                break;
                            }
                            CustomItemValue cv = new CustomItemValue();
                            cv.CustomItemId = ci.Id;
                            cv.InsertTime   = cv.UpdateTime = DateTime.Now;
                            cv.IsDeleted    = false;
                            cv.ItemName     = ci.ItemName;
                            cv.InforId      = informationList[lastSheetRowCount + j - 1].Id;
                            try
                            {
                                cv.ItemValue = _currentSheet.GetRow(j).GetCell(k) == null ? null : _currentSheet.GetRow(j).GetCell(k).NumericCellValue.ToString();
                            }
                            catch (Exception)
                            {
                                cv.ItemValue = _currentSheet.GetRow(j).GetCell(k) == null ? null : _currentSheet.GetRow(j).GetCell(k).StringCellValue;
                            }

                            customItemValueList.Add(cv);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.writeLog_error(ex.Message);
                LogHelper.writeLog_error(ex.StackTrace);
                throw;
            }
        }
Ejemplo n.º 3
0
        public ActionResult Import(Information InformationModel, List <FormModel> CustomItemModel)
        {
            AjaxResult ar = new AjaxResult();

            if (InformationModel == null)
            {
                ar.state   = ResultType.error.ToString();
                ar.message = "提交数据有误,添加新纪录失败";
                return(Json(ar, JsonRequestBehavior.AllowGet));
            }

            try
            {
                var currentUser = LoginManager.GetCurrentUser();
                if (!_informationBLL.IsExsit(InformationModel.Phone,
                                             InformationModel.QQ, InformationModel.WebCat, currentUser.CompanyCode))
                {
                    #region 注释
                    //var state = _informationBLL.AddInformation(InformationModel, currentUser.Account, currentUser.CompanyCode);
                    //if (state == OperatorState.empty)
                    //{
                    //    ar.state = ResultType.error.ToString();
                    //    ar.message = "提交的数据为空,添加新纪录失败";
                    //}
                    //else if (state == OperatorState.error)
                    //{
                    //    ar.state = ResultType.error.ToString();
                    //    ar.message = "添加新纪录失败";
                    //}
                    //else if (state == OperatorState.success)
                    //{
                    //    //ar.state = ResultType.success.ToString();
                    //    //ar.message = "添加新纪录成功";
                    //}
                    #endregion

                    using (var db = new DCSDBContext())
                    {
                        #region 开始一个事务
                        using (var trans = db.Database.BeginTransaction())
                        {
                            try
                            {
                                InformationModel.InsertMember = InformationModel.UsageMember = currentUser.Account;
                                InformationModel.State        = (int)InformatinState.UnAssigned;
                                InformationModel.InsertTime   = DateTime.Now;
                                InformationModel.UpdateTime   = DateTime.Now;
                                InformationModel.CompanyCode  = currentUser.CompanyCode;
                                InformationModel.DataCode     = "DC" + currentUser.CompanyCode + TimeManager.GetTimeSpan() + RandomManager.GenerateRandom(5);

                                db.Informations.Add(InformationModel);

                                List <CustomItem> customItemList = new List <CustomItem>();
                                _customItemBLL.GetCustomItems(currentUser.Account, ref customItemList);

                                foreach (var item in customItemList)
                                {
                                    var             cm = CustomItemModel.Where(n => n.name == item.ItemName).SingleOrDefault();
                                    CustomItemValue cv = new CustomItemValue();

                                    cv.InforId      = InformationModel.Id;
                                    cv.InsertTime   = cv.UpdateTime = DateTime.Now;
                                    cv.IsDeleted    = false;
                                    cv.ItemValue    = cm.value ?? "";
                                    cv.CustomItemId = item.Id;
                                    cv.ItemName     = item.ItemName;

                                    db.CustomItemValues.Add(cv);
                                }

                                db.SaveChanges();

                                // 修改用户的以收集数据的数量  + 1
                                currentUser.Cocount += 1;
                                db.Set <Member>().Attach(currentUser);
                                db.Entry(currentUser).State = System.Data.Entity.EntityState.Modified;

                                db.SaveChanges();

                                trans.Commit();

                                ar.state   = ResultType.success.ToString();
                                ar.message = "添加成功";
                            }
                            catch (Exception ex)
                            {
                                LogHelper.writeLog_error(ex.Message);
                                LogHelper.writeLog_error(ex.StackTrace);

                                trans.Rollback();
                                ar.state   = ResultType.error.ToString();
                                ar.message = "添加失败,数据已回滚";
                            }
                        }
                        #endregion
                    }
                }
                else
                {
                    ar.state   = ResultType.error.ToString();
                    ar.message = "已存在相同记录,添加新纪录失败";
                }
            }
            catch (Exception ex)
            {
                LogHelper.writeLog_error(ex.Message);
                LogHelper.writeLog_error(ex.StackTrace);

                ar.state   = ResultType.error.ToString();
                ar.message = "系统错误,添加新纪录失败";
            }
            return(Json(ar, JsonRequestBehavior.AllowGet));
        }