Exemplo n.º 1
0
 /// <summary>
 /// 保存表单(新增、修改)
 /// </summary>
 /// <param name="keyValue">主键值</param>
 /// <param name="entity">实体对象</param>
 /// <returns></returns>
 public void SaveForm(string keyValue, ContractServiceEntity entity)
 {
     try
     {
         service.SaveForm(keyValue, entity);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 2
0
        public ActionResult SaveContractForm(string keyValue, ContractModel model)
        {
            ContractEntity entity = new ContractEntity();

            entity.ContractId    = model.ContractId;
            entity.ContractMoney = model.ContractMoney;
            entity.ContractType  = model.ContractType;
            entity.CustomerId    = model.CustomerId;
            entity.CustomerName  = model.CustomerName;
            entity.Deadline      = model.Deadline;
            entity.Description   = model.Description;
            entity.EffectiveDate = model.EffectiveDate;
            entity.PaymentMethod = model.PaymentMethod;
            entity.PhoneNumber   = model.PhoneNumber;
            entity.ProjectLeader = model.ProjectLeader;
            entity.ServiceType   = model.ServiceType.TrimEnd(new char[] { ',', ';' });
            entity.SignSubject   = model.SignSubject;
            entity.SignSubjectId = model.SignSubjectId;
            entity.SignType      = model.SignType;
            entity.ContractCode  = model.ContractCode;


            List <ContractServiceEntity> serviceEntityList = new List <ContractServiceEntity>();

            if (!string.IsNullOrWhiteSpace(model.ServiceTypeId))
            {
                var arrIds   = model.ServiceTypeId.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                var arrNames = model.ServiceType.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < arrIds.Length; i++)
                {
                    ContractServiceEntity serviceEntity = new ContractServiceEntity();
                    serviceEntity.ServiceTypeId = arrIds[i];
                    serviceEntity.ServiceType   = arrNames[i];
                    serviceEntity.ContractId    = model.ContractId;
                    serviceEntity.Create();
                    serviceEntityList.Add(serviceEntity);
                    //合同编码的前置
                    if (string.IsNullOrWhiteSpace(entity.ContractCode))
                    {
                        var dataItem = dataItemCache.GetDataItem(serviceEntity.ServiceTypeId);
                        if (dataItem != null)
                        {
                            entity.ContractCode = dataItem.ItemValue;
                        }
                    }
                }
            }


            contractbll.AddForm(entity, serviceEntityList);
            return(Success("操作成功。"));
        }
Exemplo n.º 3
0
 public ActionResult SaveForm(string keyValue, ContractServiceEntity entity)
 {
     contractservicebll.SaveForm(keyValue, entity);
     return(Success("操作成功。"));
 }
Exemplo n.º 4
0
        /// <summary>
        /// 保存表单(新增、修改)
        /// </summary>
        /// <param name="keyValue">主键值</param>
        /// <param name="model">实体对象</param>
        /// <returns></returns>
        public void SaveForm(string keyValue, ContractModel model)
        {
            ContractEntity entity = new ContractEntity();

            entity.ContractId    = model.ContractId;
            entity.ContractMoney = model.ContractMoney;
            entity.ContractType  = model.ContractType;
            entity.CustomerId    = model.CustomerId;
            entity.CustomerName  = model.CustomerName;
            entity.Deadline      = model.Deadline;
            entity.Description   = model.Description;
            entity.EffectiveDate = model.EffectiveDate;
            entity.PaymentMethod = model.PaymentMethod;
            entity.PhoneNumber   = model.PhoneNumber;
            entity.ProjectLeader = model.ProjectLeader;
            entity.ServiceType   = model.ServiceType.TrimEnd(new char[] { ',', ';' });
            entity.SignSubject   = model.SignSubject;
            entity.SignSubjectId = model.SignSubjectId;
            entity.SignType      = model.SignType;
            if (!string.IsNullOrEmpty(keyValue))
            {
                entity.Modify(keyValue);
            }
            else
            {
                entity.Create();
            }
            List <ContractServiceEntity> list = new List <ContractServiceEntity>();

            if (!string.IsNullOrWhiteSpace(model.ServiceTypeId))
            {
                var arrIds   = model.ServiceTypeId.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                var arrNames = model.ServiceType.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

                for (int i = 0; i < arrIds.Length; i++)
                {
                    ContractServiceEntity serviceEntity = new ContractServiceEntity();
                    serviceEntity.ServiceTypeId = arrIds[i];
                    serviceEntity.ServiceType   = arrNames[i];
                    serviceEntity.ContractId    = entity.ContractId;
                    serviceEntity.Create();
                    list.Add(serviceEntity);
                }
            }
            IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();

            try
            {
                if (!string.IsNullOrEmpty(keyValue))
                {
                    db.Update(entity);
                }
                else
                {
                    //获得指定模块或者编号的单据号
                    entity.ContractCode += coderuleService.SetBillCode(entity.CreateUserId, SystemInfo.CurrentModuleId, "", db);
                    db.Insert(entity);
                    db.Insert(list);
                }
                db.Commit();
            }
            catch (Exception)
            {
                db.Rollback();
                throw;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public ActionResult ExcelImportData()
        {
            int    SuccessCount = 0;
            int    ErrorCount   = 0;
            string virtualPath  = "";
            string fullFileName = "";
            string error        = string.Empty;

            //读取上传文件
            System.Web.HttpPostedFileBase pstFile = Request.Files["file"];

            if (pstFile != null)
            {
                //上传文件
                if (UploadifyFile(pstFile, ref virtualPath, ref fullFileName))
                {
                    #region 读取Excel内容

                    IWorkbook  workbook = null;
                    FileStream fs       = null;
                    string     fileName = fullFileName;
                    ISheet     sheet    = null;
                    DataTable  data     = new DataTable();
                    int        startRow = 0;

                    #region 读取Excel 导入到系统中
                    try
                    {
                        fs = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite);
                        if (fileName.IndexOf(".xlsx") > 0) // 2007版本
                        {
                            workbook = new XSSFWorkbook(fs);
                        }
                        else if (fileName.IndexOf(".xls") > 0) // 2003版本
                        {
                            workbook = new HSSFWorkbook(fs);
                        }


                        sheet = workbook.GetSheet("Sheet1");
                        if (sheet == null) //如果没有找到指定的sheetName对应的sheet ,则尝试获取第一个sheet
                        {
                            sheet = workbook.GetSheetAt(0);
                        }
                        if (sheet != null)
                        {
                            IRow firstRow  = sheet.GetRow(0);
                            int  cellCount = firstRow.LastCellNum; //一行最后一个cell的编号 即总的列数

                            //列名的集合
                            List <string> TitleList = new List <string>();
                            //导入薪资Excel的最后一列加上状态
                            ICell resultCell = firstRow.CreateCell(cellCount + 1);
                            resultCell.SetCellValue("导入结果");

                            #region 第一行是否是DataTable的列名

                            for (int i = firstRow.FirstCellNum; i < cellCount; ++i)
                            {
                                ICell cell = firstRow.GetCell(i);
                                if (cell != null)
                                {
                                    string cellValue = cell.StringCellValue.Trim();
                                    if (cellValue != null)
                                    {
                                        //添加到集合列中
                                        DataColumn column = new DataColumn(cellValue);
                                        data.Columns.Add(column);
                                        TitleList.Add(cellValue);
                                    }
                                }
                            }
                            //最后一列显示导入结果状态

                            DataColumn lastColumn = new DataColumn("结果");
                            data.Columns.Add(lastColumn);


                            startRow = sheet.FirstRowNum + 1;

                            #endregion

                            #region 导入内容
                            //获取当前用户ID
                            string currentPerson = SystemInfo.CurrentUserId;



                            //记录薪资项目和对应的值
                            Dictionary <string, string> dicList = new Dictionary <string, string>();


                            #region 循环所有行数
                            //最后一列的标号
                            int rowCount = sheet.LastRowNum;
                            for (int i = startRow; i <= rowCount; ++i)
                            {
                                IRow row = sheet.GetRow(i);
                                if (row == null)
                                {
                                    continue;              //没有数据的行默认是null       
                                }
                                if (row.FirstCellNum > 0)
                                {
                                    continue;                      //不是从第一个单元格开始
                                }
                                DataRow dataRow = data.NewRow();

                                //清除项目
                                dicList.Clear();

                                error = string.Empty;
                                ContractEntity entity = new ContractEntity();
                                List <ContractServiceEntity> serviceEntityList = new List <ContractServiceEntity>();
                                try
                                {
                                    #region 每行的列

                                    for (int j = row.FirstCellNum; j < cellCount; ++j)
                                    {
                                        if (row.GetCell(j) != null) //同理,没有数据的单元格都默认是null
                                        {
                                            string CellValue = string.Empty;

                                            #region 获取单元格的值
                                            switch (row.GetCell(j).CellType)
                                            {
                                            case CellType.Blank:
                                            case CellType.Error:
                                            case CellType.Unknown:
                                                break;

                                            case CellType.Boolean:
                                                CellValue = row.GetCell(j).BooleanCellValue ? "1" : "0";
                                                break;

                                            case CellType.Formula:
                                                //单元格函数
                                                CellValue = row.GetCell(j).CellFormula;

                                                if (DateUtil.IsCellDateFormatted(row.GetCell(j)))
                                                {
                                                    DataFormatter formatter = new DataFormatter();
                                                    CellValue = formatter.FormatCellValue(row.GetCell(j));
                                                }
                                                else
                                                {
                                                    CellValue = row.GetCell(j).NumericCellValue.ToString();
                                                }
                                                break;

                                            case CellType.Numeric:
                                                //数字类型
                                                if (DateUtil.IsCellDateFormatted(row.GetCell(j)))
                                                {
                                                    DataFormatter formatter = new DataFormatter();
                                                    CellValue = formatter.FormatCellValue(row.GetCell(j));
                                                }
                                                else
                                                {
                                                    CellValue = row.GetCell(j).NumericCellValue.ToString();
                                                }
                                                break;

                                            case CellType.String:
                                                //字符串
                                                CellValue = row.GetCell(j).StringCellValue;
                                                break;

                                            default:
                                                break;
                                            }

                                            #endregion

                                            dataRow[j] = CellValue;
                                            #region  务类型
                                            if (TitleList[j] == "服务类型")
                                            {
                                                string[] strArr = CellValue.Split(new char[] { ',', ';', '^', '|', ',' }, StringSplitOptions.RemoveEmptyEntries);
                                                if (strArr.Length > 0)
                                                {
                                                    for (int q = 0; q < strArr.Length; q++)
                                                    {
                                                        var type        = strArr[q];
                                                        var productInfo = itemCache.GetDataItemList("Client_ProductInfo").FirstOrDefault(s => s.ItemName == type);
                                                        if (productInfo != null)
                                                        {
                                                            ContractServiceEntity serviceEntity = new ContractServiceEntity();
                                                            serviceEntity.ServiceTypeId = productInfo.ItemDetailId;
                                                            serviceEntity.ServiceType   = productInfo.ItemName;
                                                            serviceEntity.ContractId    = "";
                                                            serviceEntity.Create();
                                                            serviceEntityList.Add(serviceEntity);
                                                            //合同编码的前置
                                                            if (string.IsNullOrWhiteSpace(entity.ContractCode))
                                                            {
                                                                var dataItem = itemCache.GetDataItem(serviceEntity.ServiceTypeId);
                                                                if (dataItem != null)
                                                                {
                                                                    entity.ContractCode = dataItem.ItemValue;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                if (serviceEntityList.Count < 1)
                                                {
                                                    error = "服务类型数据有误";
                                                    break;
                                                }
                                                var serviceList = serviceEntityList.Select(s => s.ServiceType);
                                                entity.ServiceType = string.Join(",", serviceList);
                                            }
                                            #endregion
                                            error = SetEntityValue(entity, TitleList[j], CellValue.Trim());
                                            if (!string.IsNullOrWhiteSpace(error))
                                            {
                                                break;
                                            }
                                        }
                                    }
                                    #endregion

                                    if (error == string.Empty)
                                    {
                                        string moduleCode = string.Empty;
                                        if (entity.ContractType == 21)
                                        {
                                            moduleCode = "10007";
                                        }
                                        else
                                        {
                                            moduleCode = "10008";
                                        }
                                        contractbll.AddForm(entity, serviceEntityList, "", moduleCode);
                                        error = "导入成功";
                                        SuccessCount++;
                                    }
                                    else
                                    {
                                        ErrorCount++;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    error = ex.Message;
                                    ErrorCount++;
                                }
                                dataRow[cellCount] = error;
                                data.Rows.Add(dataRow);

                                ICell cell = row.CreateCell(cellCount + 1);
                                cell.SetCellValue(error);
                            }
                            #endregion

                            #endregion
                        }

                        ViewBag.ResultImportData = data;
                    }
                    catch (Exception ex)
                    {
                        Response.Write("批量导入客户异常1: " + ex.Message);
                        error = "批量导入客户异常: " + ex.Message;
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                        fs = null;
                    }
                    #endregion

                    try
                    {
                        using (FileStream fileWrite = new FileStream(fullFileName, FileMode.Create))
                        {
                            workbook.Write(fileWrite);
                        }
                    }
                    catch (Exception ex)
                    {
                    }


                    #endregion
                }
            }
            error         = "导入数据不存在,请返回批量导入页面!";
            ViewBag.Error = error;

            ViewBag.Url          = virtualPath;
            ViewBag.ErrorCount   = ErrorCount;
            ViewBag.SuccessCount = SuccessCount;
            return(View("ExportError"));
        }
Exemplo n.º 6
0
        public ActionResult KeFuAddForm(string keyValue, ContractModel model)
        {
            if (string.IsNullOrWhiteSpace(model.VerificationCode))
            {
                return(Error("验证码不能为空,请输入正确的验证码"));
            }
            var sms = smsLogBLL.GetLatestCurrent(model.PhoneNumber.ToString(), 1200);

            if (sms == null || model.VerificationCode != sms.MsgValue)
            {
                return(Error("您输入的验证码不正确"));
            }

            ContractEntity entity = new ContractEntity();

            entity.ContractId     = model.ContractId;
            entity.ContractMoney  = model.ContractMoney;
            entity.ContractType   = model.ContractType;
            entity.CustomerId     = model.CustomerId;
            entity.CustomerName   = model.CustomerName;
            entity.Deadline       = model.Deadline;
            entity.Description    = model.Description;
            entity.EffectiveDate  = model.EffectiveDate;
            entity.PaymentMethod  = model.PaymentMethod;
            entity.PhoneNumber    = model.PhoneNumber;
            entity.ProjectLeader  = model.ProjectLeader;
            entity.ServiceType    = model.ServiceType.TrimEnd(new char[] { ',', ';' });
            entity.SignSubject    = model.SignSubject;
            entity.SignSubjectId  = model.SignSubjectId;
            entity.SignType       = model.SignType;
            entity.ContractCode   = model.ContractCode;
            entity.CreateUserName = model.CreateUserName;

            List <ContractServiceEntity> serviceEntityList = new List <ContractServiceEntity>();

            if (!string.IsNullOrWhiteSpace(model.ServiceTypeId))
            {
                var arrIds   = model.ServiceTypeId.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                var arrNames = model.ServiceType.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < arrIds.Length; i++)
                {
                    ContractServiceEntity serviceEntity = new ContractServiceEntity();
                    serviceEntity.ServiceTypeId = arrIds[i];
                    serviceEntity.ServiceType   = arrNames[i];
                    serviceEntity.ContractId    = model.ContractId;
                    serviceEntity.Create();
                    serviceEntityList.Add(serviceEntity);
                    //合同编码的前置
                    if (string.IsNullOrWhiteSpace(entity.ContractCode))
                    {
                        var dataItem = itemCache.GetDataItem(serviceEntity.ServiceTypeId);
                        if (dataItem != null)
                        {
                            entity.ContractCode = dataItem.ItemValue;
                        }
                    }
                }
            }
            string moduleCode = string.Empty;

            if (entity.ContractType == 21)
            {
                moduleCode = "10007";
            }
            else
            {
                moduleCode = "10008";
            }

            contractbll.AddForm(entity, serviceEntityList, moduleCode, moduleCode);
            return(Success("操作成功。"));
        }