Пример #1
0
        void AddProject(Entity.Project project)
        {
            ListViewItem newItem = this.listView.Items.Add(project.Name);

            this.ProjectList.Add(project, newItem);
            this.ListViewItemList.Add(newItem, project);
        }
Пример #2
0
        public async Task <ActionResult <ApiResult <int> > > Save([FromBody] Entity.Project project)
        {
            try
            {
                if (project == null || string.IsNullOrWhiteSpace(project.FullName))
                {
                    return(Error <int>("没有传递正确的项目信息"));
                }

                if (project.ID <= 0)
                {
                    //if (project.CreatedOn.Year <= 1900)
                    //    project.CreatedOn = DateTime.Now;

                    int newId = await DbHelper.InsertEntity(Connector, project);

                    return(Success(newId));
                }
                else
                {
                    await DbHelper.UpdateEntity(Connector, project);

                    return(Success(project.ID));
                }
            }
            catch (Exception ex)
            {
                return(Error <int>(ex.Message));
            }
        }
Пример #3
0
        void RemoveProject(Entity.Project project)
        {
            ListViewItem uinode = this.ProjectList[project];

            uinode.Remove();
            this.ListViewItemList.Remove(uinode);
            this.ProjectList.Remove(project);
        }
Пример #4
0
 void UIListItemActivated(object sender, EventArgs e)
 {
     if (this.ItemInvoked != null)
     {
         Entity.Project       affectedProject = this.ListViewItemList[this.listView.SelectedItems[0]];
         ItemInvokedEventArgs itemInvokedArgs = new ItemInvokedEventArgs(affectedProject);
         this.ItemInvoked(this, itemInvokedArgs);
     }
 }
Пример #5
0
        void UpdateChanges(object sender, PropertyChangedEventArgs e)
        {
            Entity.Project project = sender as Entity.Project;
            switch (e.PropertyName)
            {
            case "Name":
                this.label1.Text = project.Name;
                break;

            default:
                break;
            }
        }
Пример #6
0
        public async Task <IActionResult> Edit(ProjectViewState model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Entity.Project project;
                    if (model.ProjectId > 0)
                    {
                        project = await _projectService.GetProjectById(model.ProjectId);

                        if (project == null || project.ID <= 0)
                        {
                            throw new Exception("没有找到要保存的项目");
                        }
                    }
                    else
                    {
                        project = new Entity.Project();
                        //{
                        //    CreatedBy = UserHelper.GetUserID(HttpContext),
                        //    CreatedOn = DateTime.Now,
                        //};
                    }
                    //project.ActiveStatus = model.ActiveStatus;
                    project.ContractCode   = model.ContractCode;
                    project.EndTime        = model.EndDate;
                    project.FullName       = model.FullName;
                    project.Owner          = model.Owner;
                    project.ShortName      = model.ShortName;
                    project.SitePlace      = model.SitePlace;
                    project.StartTime      = model.BeginDate;
                    project.Status         = (int)model.State;
                    project.ContractAmount = model.ContractAmount == null ? 0 : model.ContractAmount.Value;

                    await _projectService.SaveProject(project);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("", ex.Message);
            }
            return(View(model));
        }
Пример #7
0
        public void InitializeView()
        {
            // init the project list view
            this.projectListView = new Views.ProjectListView();

            ObservableCollection <Entity.Project> projectList = new ObservableCollection <Entity.Project>();

            Entity.Project projectA = new Entity.Project("Projekt A");
            Entity.Project projectB = new Entity.Project("Projekt B");
            Entity.Project projectC = new Entity.Project("Projekt C");
            projectList.Add(projectA);
            projectList.Add(projectB);
            projectList.Add(projectC);

            this.ProjectListView.Projects     = projectList;
            this.ProjectListView.ItemInvoked += this.ProjectInvoked;

            this.ProjectView = new Views.ProjectView();

            this.LayoutView = new Views.LayoutView();
            this.View       = this.LayoutView;
        }
Пример #8
0
 public ItemInvokedEventArgs(Entity.Project project)
 {
     this.affectedProject = project;
 }
Пример #9
0
        public static async Task <string> Upload(Stream stream, ExcelMap map,
                                                 IEmployeeService employeeService = null,
                                                 IProjectService projectService   = null)
        {
            IWorkbook workbook = new XSSFWorkbook(stream);
            ISheet    sheet    = workbook.GetSheetAt(map.SheetIndex);

            if (sheet == null)
            {
                throw new Exception($"上传的文件没有索引为{map.SheetIndex}的工作表");
            }
            IDictionary <string, int> Indecies = new Dictionary <string, int>();
            int startRowIndex;

            if (map.WithHeader)
            {
                IRow header = sheet.GetRow(0);
                if (header == null)
                {
                    throw new Exception($"上传的文件第一行必须是符合格式的标题行");
                }
                foreach (var caption in header.Cells)
                {
                    Indecies.Add(caption.StringCellValue, caption.ColumnIndex);
                }
                startRowIndex = 1;
            }
            else
            {
                IRow firstRow = sheet.GetRow(0);
                if (firstRow == null)
                {
                    throw new Exception("上传文件没有数据,必须从第一行开始有数据");
                }
                for (var i = 0; i <= firstRow.LastCellNum; i++)
                {
                    Indecies.Add(i.ToString(), i);
                }
                startRowIndex = 0;
            }
            //由于现在仅支持项目和人员导入,因此直接使用一个布尔值来区别类型。
            var  projectType = typeof(Entity.Project);
            var  staffType   = typeof(Entity.Employee);
            bool isProject;

            if (map.IsTypeOf(projectType))
            {
                isProject = true;
            }
            else if (map.IsTypeOf(staffType))
            {
                isProject = false;
            }
            else
            {
                throw new Exception("not supported upload entity type");
            }

            int           total = 0, success = 0, failure = 0;
            StringBuilder messageBuilder = new StringBuilder();

            for (var rowIndex = startRowIndex; rowIndex <= sheet.LastRowNum; rowIndex++)
            {
                total++;
                IRow   data = sheet.GetRow(rowIndex);
                object entity;
                if (isProject)
                {
                    entity = new Entity.Project();
                }
                //{
                //    ActiveStatus = true,
                //    CreatedOn = DateTime.Now,
                //    CreatedBy = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL
                //};
                else
                {
                    entity = new Entity.Employee
                    {
                        ActiveStatus = true,
                        CreatedOn    = DateTime.Now,
                        CreatedBy    = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL,
                        InDate       = Cnf.CodeBase.Serialize.ValueHelper.DbDate_Null,
                        InDutyID     = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL,
                        InProjectID  = Cnf.CodeBase.Serialize.ValueHelper.DBKEY_NULL
                    }
                };

                try
                {
                    foreach (var propMap in map.Properties)
                    {
                        if (!Indecies.ContainsKey(propMap.ColumnIndex))
                        {
                            throw new Exception($"上传的文件无法定位到列索引[{propMap.ColumnIndex}]");
                        }
                        object cellValue = propMap.PropertyType switch
                        {
                            PropertyType.Boolean => data.GetCell(Indecies[propMap.ColumnIndex]).BooleanCellValue,
                            PropertyType.DateTime => data.GetCell(Indecies[propMap.ColumnIndex]).DateCellValue,
                            PropertyType.Int => Convert.ToInt32(data.GetCell(Indecies[propMap.ColumnIndex]).NumericCellValue),
                            PropertyType.Real => data.GetCell(Indecies[propMap.ColumnIndex]).NumericCellValue,
                            PropertyType.Text => data.GetCell(Indecies[propMap.ColumnIndex]).StringCellValue,
                            _ => throw new Exception("not supported property data type"),
                        };
                        PropertyInfo propertyInfo = isProject ?
                                                    projectType.GetProperty(propMap.PropertyName,
                                                                            BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) :
                                                    staffType.GetProperty(propMap.PropertyName,
                                                                          BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
                        if (propertyInfo == null)
                        {
                            throw new Exception($"Excel映射配置的属性{propMap.PropertyName}不是实体类的成员");
                        }
                        propertyInfo.SetValue(entity, cellValue);
                    }
                }
                catch (Exception ex)
                {
                    messageBuilder.AppendLine($"行{rowIndex}读文件错:{ex.Message}<br/>");
                    failure++;
                    continue;  //直接开始处理下一行。
                }
                //保存到数据库
                try
                {
                    if (isProject)
                    {
                        await projectService.SaveProject((Entity.Project) entity);
                    }
                    else
                    {
                        await employeeService.SaveEmployee((Entity.Employee) entity);
                    }
                    success++;
                }
                catch (Exception ex)
                {
                    messageBuilder.AppendLine($"行{rowIndex}写数据库错:{ex.Message}<br/>");
                    failure++;
                }
            }
            messageBuilder.AppendLine($"共处理了{total}行,导入{success}行,错误{failure}行");
            return(messageBuilder.ToString());
        }
Пример #10
0
        public async Task <ActionResult <ApiResult <int> > > Transfer([FromBody] TransferInfo transferInfo)
        {
            try
            {
                int      employeeId   = transferInfo.EmployeeId;
                int      projectId    = transferInfo.ProjectId;
                int      dutyId       = transferInfo.DutyId;
                int      userId       = transferInfo.UserId;
                DateTime transferDate = transferInfo.TransferDate == null ?
                                        DateTime.Today : transferInfo.TransferDate.Value;

                if (employeeId <= 0)
                {
                    return(Error <int>("员工ID不能为无效(小于或等于0)"));
                }
                if (projectId > 0 && dutyId <= 0)
                {
                    return(Error <int>("调入项目的同时必须分配职责"));
                }

                var employee = await DbHelper.FindEntity <Entity.Employee>(Connector, employeeId);

                if (employee == null || employee.ID <= 0)
                {
                    throw new Exception("人员不在库中");
                }

                Entity.Project project;
                Duty           duty;
                if (projectId > 0)
                {
                    project = await DbHelper.FindEntity <Entity.Project>(Connector, projectId);

                    if (project == null || project.ID <= 0)
                    {
                        throw new Exception("项目不在库中");
                    }
                    duty = await DbHelper.FindEntity <Reference>(Connector, dutyId);

                    if (duty == null || duty.DutyID <= 0)
                    {
                        throw new Exception("职责不在库中");
                    }
                }
                else
                {
                    project = null;
                    duty    = null;
                }

                if (employee.InProjectID > 0)
                {
                    Entity.Project outProject = await DbHelper.FindEntity <Entity.Project>(Connector, employee.InProjectID);

                    //添加调出日志
                    TransferOutLog outLog = new TransferOutLog()
                    {
                        ActiveStatus  = true,
                        CreatedBy     = userId,
                        CreatedOn     = DateTime.Now,
                        OutDate       = transferDate,
                        OutDutyID     = employee.InDutyID,
                        OutEmployeeID = employeeId,
                        OutProjectID  = employee.InProjectID,
                        EmployeeName  = employee.Name,
                        ProjectName   = string.IsNullOrEmpty(outProject.ShortName) ? outProject.FullName : outProject.ShortName,
                    };
                    if (employee.InDutyID > 0)
                    {
                        outLog.DutyName = (await DbHelper.FindEntity <Reference>(Connector, employee.InDutyID)).ReferenceValue;
                    }
                    await DbHelper.InsertEntity(Connector, outLog);
                }

                if (project == null)
                {
                    //将人员设置为自由, 无需任何调入日志
                    employee.InDate      = ValueHelper.DbDate_Null;
                    employee.InDutyID    = ValueHelper.DBKEY_NULL;
                    employee.InProjectID = ValueHelper.DBKEY_NULL;
                    employee.ProjectName = string.Empty;
                    employee.DutyName    = string.Empty;
                }
                else
                {
                    //添加调入日志
                    TransferInLog inLog = new TransferInLog()
                    {
                        ActiveStatus = true,
                        CreatedBy    = userId,
                        CreatedOn    = DateTime.Now,
                        InDate       = transferDate,
                        InDutyID     = dutyId,
                        InEmployeeID = employeeId,
                        InProjectID  = projectId,
                        EmployeeName = employee.Name,
                        ProjectName  = string.IsNullOrEmpty(project.ShortName) ? project.FullName : project.ShortName,
                        DutyName     = duty.Name
                    };
                    await DbHelper.InsertEntity(Connector, inLog);

                    //修改人员状态
                    employee.InDate      = transferDate;
                    employee.InDutyID    = dutyId;
                    employee.InProjectID = projectId;
                    employee.ProjectName = string.IsNullOrEmpty(project.ShortName) ? project.FullName : project.ShortName;
                    employee.DutyName    = duty.Name;
                }
                await DbHelper.UpdateEntity(Connector, employee);

                return(Success(0));
            }
            catch (Exception ex)
            {
                return(Error <int>(ex.Message));
            }
        }
Пример #11
0
 void InitializeData(Entity.Project project)
 {
     this.label1.Text = project.Name;
 }
Пример #12
0
 public void ShowProject(Entity.Project project)
 {
     this.ProjectView.Project = project;
     this.LayoutView.Content(this.ProjectView);
 }
Пример #13
0
 void ProjectInvoked(object sender, EventArgs e)
 {
     Views.ItemInvokedEventArgs eventArgs = e as Views.ItemInvokedEventArgs;
     Entity.Project             project   = eventArgs.affectedProject;
     this.ShowProject(project);
 }