private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(EmployeeName))
            {
                this.Close();
            }
            DomainOperate doo      = new DomainOperate("hncdi");
            List <string> accounts = new List <string>();

            accounts = doo.GetLoginIDByUserName(EmployeeName);
            if (!accounts.Any())
            {
                this.Close();
            }
            _listEmployees = new List <Employee>();

            foreach (string account in accounts)
            {
                Employee employee = new Employee
                {
                    Name        = EmployeeName,
                    AccountName = account,
                    Department  = doo.GetOuByLoginID(account)
                };
                _listEmployees.Add(employee);
            }
            LabelMessage.Content             = "域内存在多个姓名为 " + EmployeeName + " 的账号,请选择:";
            DataGridEmployeeList.ItemsSource = _listEmployees;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dataContext     = new DataClassesProjectClassifyDataContext();
            _listDepartment = new List <Department>();
            _domain         = new DomainOperate("HNCDI");
            _domain.GetOU();
            foreach (DataRow o in _domain.ArrayOU.Rows)
            {
                _listDepartment.Add(new Department {
                    Name = o["Text"].ToString(), Value = o["Value"].ToString()
                });
            }
            ListBoxDepartment.ItemsSource = _listDepartment;
            ProjectBase projectBase = dataContext.ProjectBase.FirstOrDefault(p => p.ProjectId.Equals(ProjectId));

            if (projectBase != null)
            {
                ProjectName.Text = projectBase.ProjectName.Trim();
            }
            //DataGridPrizes.ItemsSource = dataContext.Prizes.Where(p => p.ProjectID.Equals(ProjectId));
            _listPrizeClassify = new List <PrizeClassify>
            {
                new PrizeClassify {
                    PrizeClassifyName = "国家、部、省科技进步奖/管理成果奖"
                },
                new PrizeClassify {
                    PrizeClassifyName = "国家、部、省优秀项目奖"
                },
                new PrizeClassify {
                    PrizeClassifyName = "院优项目奖"
                },
                new PrizeClassify {
                    PrizeClassifyName = "专利奖励"
                },
                new PrizeClassify {
                    PrizeClassifyName = "论著奖励"
                }
            };
            ListBoxPrizeClassify.ItemsSource = _listPrizeClassify;
            TextBoxYear.Text = DateTime.Now.Year.ToString();
        }
        private void ListBoxDepartment_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ListBoxDepartment.SelectedItem == null)
            {
                ListBoxEmployee.Items.Clear();
                return;
            }
            _listEmployee = new List <Employee>();
            Department department = (Department)ListBoxDepartment.SelectedItem;

            _domain = new DomainOperate("HNCDI");
            _domain.GetUsersByOU(department.Name);
            foreach (DataRow emRow in _domain.ArrayUser.Rows)
            {
                _listEmployee.Add(new Employee {
                    AccountName = emRow["Value"].ToString(), Name = emRow["Text"].ToString()
                });
            }
            ListBoxEmployee.ItemsSource = _listEmployee;
            CheckEmpty();
        }
        /// <summary>
        /// 读取奖金数据
        /// </summary>
        private void ReadData()
        {
            var ws = _wb.Worksheets.FirstOrDefault();

            if (ws != null)
            {
                List <string> logins = new List <string>();
                _doo       = new DomainOperate("hncdi");
                _totalRows = ws.Rows().Count();
                int currentRow = 5;
                _listPrizeses = new List <Prizes>();
                while (currentRow <= _totalRows)
                {
                    var row = ws.Row(currentRow);
                    if (row.Cell(1).IsEmpty())
                    {
                        currentRow++;
                        continue;
                    }
                    string temp = row.Cell(1).GetString();
                    temp = temp.Replace(" ", "").Trim();
                    if (temp == "合计" || temp == "小计" || temp == "总计" || temp == "共计")
                    {
                        break;
                    }
                    //if (row.Cell(2).IsEmpty() && row.Cell(1).GetString().Contains("计")) break;
                    var dataRow    = row.RowUsed();
                    int totalCol   = dataRow.CellCount();
                    int currentCol = 1;
                    if (dataRow.Cell(currentCol).IsEmpty())
                    {
                        currentRow++;
                        continue;
                    }
                    string userName = dataRow.Cell(currentCol).GetString();
                    userName = userName.Replace(" ", "").Trim();
                    if (IsNumber(userName))
                    {
                        currentRow++;
                        continue;
                    }
                    GetUserAccount(userName, out logins);

                    if (!logins.Any())
                    {
                        CurrentEmployee = new Employee
                        {
                            Name        = userName,
                            AccountName = "",
                            Department  = _declareDepartment
                        };
                    }
                    else
                    {
                        if (logins.Count() > 1)
                        {
                            SelectPrizeEmployee selectPrizeEmployee = new SelectPrizeEmployee();
                            selectPrizeEmployee.EmployeeName = userName;
                            selectPrizeEmployee.ShowDialog();
                            CurrentEmployeeName        = selectPrizeEmployee.EmployeeName;
                            CurrentEmployeeAccountName = selectPrizeEmployee.SelectedAccountName;
                            CurrentEmployeeDepartment  = selectPrizeEmployee.SelectedDepartment;
                            if (string.IsNullOrWhiteSpace(CurrentEmployeeName))
                            {
                                CurrentEmployee = null;
                            }
                            else
                            {
                                CurrentEmployee = new Employee
                                {
                                    Name        = CurrentEmployeeName,
                                    AccountName = CurrentEmployeeAccountName,
                                    Department  = CurrentEmployeeDepartment
                                };
                            }
                        }
                        else
                        {
                            CurrentEmployee = new Employee
                            {
                                Name        = userName,
                                AccountName = logins[0],
                                Department  = _doo.GetOuByLoginID(logins[0])
                            };
                        }
                    }
                    if (CurrentEmployee == null)
                    {
                        currentRow++;
                        continue;
                    }
                    currentCol = 4;
                    while (currentCol <= totalCol)
                    {
                        if (string.IsNullOrWhiteSpace(_dictionaryProject[currentCol]) || dataRow.Cell(currentCol).IsEmpty())
                        {
                            currentCol++;
                            continue;
                        }
                        try
                        {
                            decimal prize = Convert.ToDecimal(dataRow.Cell(currentCol).Value);
                            if (prize <= 0.0M)
                            {
                                currentCol++;
                                continue;
                            }
                            if (currentCol > _lastCategoryColNo)
                            {
                                _dictionaryCategory.Add(currentCol, "");
                                _lastCategoryColNo++;
                            }
                            if (currentCol > _lastProjectColNo)
                            {
                                _dictionaryProject.Add(currentCol, _dictionaryProject[_lastProjectColNo]);
                                _lastProjectColNo++;
                            }
                            if (currentCol > _lastClassifyColNo)
                            {
                                _dictionaryPrizeClassify.Add(currentCol, _dictionaryPrizeClassify[_lastClassifyColNo]);
                                _lastClassifyColNo++;
                            }

                            Prizes prizes = new Prizes
                            {
                                Department        = CurrentEmployee.Department,
                                DeclareDepartment = _declareDepartment,
                                Name          = CurrentEmployee.Name,
                                AccountName   = CurrentEmployee.AccountName,
                                Project       = _dictionaryProject[currentCol],
                                PrizeClassify = _dictionaryPrizeClassify[currentCol],
                                AwardName     = _dictionaryCategory[currentCol],
                                Prize         = prize,
                                PayYear       = _year
                            };
                            //检查重复项
                            var pr =
                                dataContext.Prizes.FirstOrDefault(
                                    p =>
                                    p.Department.Equals(prizes.Department) &&
                                    //p.DeclareDepartment.Equals(prizes.DeclareDepartment) &&
                                    p.Name.Equals(prizes.Name) && p.AccountName.Equals(prizes.AccountName) &&
                                    p.Project.Equals(prizes.Project) && p.PrizeClassify.Equals(prizes.PrizeClassify) &&
                                    p.PayYear.Equals(prizes.PayYear) &&
                                    p.AwardName.Equals(prizes.AwardName));

                            if (pr != null)
                            {
                                if (pr.Prize != prizes.Prize)
                                {
                                    pr.Prize = prizes.Prize;
                                    dataContext.SubmitChanges();
                                }
                            }
                            else
                            {
                                dataContext.Prizes.InsertOnSubmit(prizes);
                                dataContext.SubmitChanges();
                            }
                            currentCol++;
                        }
                        catch (Exception error)
                        {
                            MessageBox.Show(error.Message + "当前行" + currentRow.ToString());
                            currentCol++;
                        }
                    }
                    currentRow++;
                }
            }
        }