private bool GetPorjectPlanList(ProjectEntity item, string aPlanVersionId, bool aIsSetable,
            ref Dictionary<string, ObservableCollection<PlanEntity>> aPlanListDictionary, 
            ref Dictionary<string, int> aModuleIndexDictionary)
        {
            bool rturnValue = false;
            IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans
                                             where c.manufacture_number == item.ManufactureNumber.TrimEnd()
                                                && c.version_id == aPlanVersionId
                                             select c.sheet_name;
            if (sheetNames.Count() > 0)
            {
                ObservableCollection<string> differentSheets = new ObservableCollection<string>();
                foreach(string originalValue in sheetNames)
                {
                    if (null == originalValue)
                    {
                        continue;
                    }
                    string value = originalValue;

                    if ("设计完成节点" == value)
                    {
                        value = "设计节点";
                    }
                    else if ("采购完成节点" == value)
                    {
                        value = "采购节点";
                    }
                    else if ("生产完成节点" == value)
                    {
                        value = "生产节点";
                    }

                    if (differentSheets.Contains(value))
                    {
                        continue;
                    }

                    differentSheets.Add(value);

                    IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans
                                                      where c.manufacture_number == item.ManufactureNumber.TrimEnd()
                                                        && c.version_id == aPlanVersionId
                                                        && c.sheet_name == originalValue
                                                      select c;
                    if (selectedPlans.Count() > 0)
                    {
                        if(!aModuleIndexDictionary.Keys.Contains(value))
                        {
                            aModuleIndexDictionary.Add(value, 0);
                        }

                        if (!aPlanListDictionary.Keys.Contains(value))
                        {
                            aPlanListDictionary.Add(value, new ObservableCollection<PlanEntity>());
                        }

                        if (selectedPlans.First().order_date.HasValue)
                        {
                            aModuleIndexDictionary[value] = 1;
                        }

                        ObservableCollection<PlanEntity> planList = aPlanListDictionary[value];
                        foreach (plan planItem in selectedPlans)
                        {
                            PlanEntity planEntity = new PlanEntity();
                            planEntity.Plan = planItem;
                            string getDepartmentName = string.Empty;
                            planEntity.Update();
                            planEntity.ProjectName = item.ProjectName;
                            planEntity.PlanRemindDay = ("设计节点" == planItem.sheet_name) ? item.RemindDayDesign :
                                (("采购节点" == planItem.sheet_name) ? item.RemindDayPurchase : item.RemindDayProduce);
                            planEntity.IsSetable = aIsSetable;
                            if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName))
                            {
                                planEntity.DepartmentName = getDepartmentName;
                            }
                            planList.Add(planEntity);
                        }
                    }
                }

                rturnValue = true;
            }
            return rturnValue;
        }
        private void LoadOperationPlanCompleted(LoadOperation<plan> aLoadOperation)
        {
            planRemindList.Clear();
            App app = Application.Current as App;
            planRemindList = new ObservableCollection<PlanEntity>();
            if (null != app.UserInfo)
            {
                string userName = app.UserInfo.UserName;

                IEnumerable<string> project_responsibles_MN =
                                                      from c in productDomainContext.project_responsibles
                                                      where c.responsible_persionName == app.UserInfo.UserName
                                                      || (app.UserInfo.IsManager ? c.department_id == app.UserInfo.DepartmentID : false)
                                                      select c.manufacture_number;

                if (0 != project_responsibles_MN.Count())
                {
                    foreach (string itemMN in project_responsibles_MN)
                    {
                        IEnumerable<project> projects =
                                                      from c in planManagerDomainContext.projects
                                                      where c.manufacture_number == itemMN
                                                      select c;
                        if (0 == projects.Count())
                        {
                            continue;
                        }

                        project projectInfo = projects.First<project>();
                        if (string.IsNullOrEmpty(projectInfo.plan_version_id)
                            || (projectInfo.isdelete.HasValue && projectInfo.isdelete.Value))
                        {
                            continue;
                        }
                        ProjectEntity projectDetail = new ProjectEntity();
                        projectDetail.Project = projectInfo;
                        projectDetail.Update();

                        UserRemindEntity lUserRemindEntity;
                        if (UserRemindEntityDicationary.TryGetValue(projectDetail.ManufactureNumber, out lUserRemindEntity))
                        {
                            projectDetail.UserRemindEntity = lUserRemindEntity;
                        }

                        IEnumerable<string> respUserName = from c in productDomainContext.project_responsibles
                                                           where c.manufacture_number == itemMN && c.department_id == app.UserInfo.DepartmentID
                                                           select c.responsible_persionName;

                        String respUserNameString = respUserName.First();

                        IEnumerable<plan> plans;
                        if (app.UserInfo.DepartmentID != 1000)
                        {
                            plans = from c in planManagerDomainContext.plans
                                    where c.manufacture_number == itemMN && c.department_id == app.UserInfo.DepartmentID
                                              && c.version_id == projectInfo.plan_version_id
                                    select c;
                        }
                        else
                        {
                            plans = from c in planManagerDomainContext.plans
                                    where c.manufacture_number == itemMN && c.version_id == projectInfo.plan_version_id
                                    select c;
                        }
                        //IEnumerable<plan> plans = from c in planManagerDomainContext.plans
                        //                          where c.manufacture_number == itemMN && c.department_id == app.UserInfo.DepartmentID
                        //                                    && c.version_id == projectInfo.plan_version_id
                        //                          select c;
                        foreach (plan planItem in plans)
                        {
                            if (planItem.accomplish_date.HasValue)
                            {
                                continue;
                            }

                            int remindDay = ("设计节点" == planItem.sheet_name) ? projectDetail.RemindDayDesign :
                                (("采购节点" == planItem.sheet_name) ? projectDetail.RemindDayPurchase : projectDetail.RemindDayProduce);

                            Nullable<DateTime> targetDateTime = planItem.target_date_adjustment2.HasValue ? planItem.target_date_adjustment2.Value :
                                                (planItem.target_date_adjustment1.HasValue ? planItem.target_date_adjustment1.Value : planItem.target_date);

                            if (!targetDateTime.HasValue)
                            {
                                continue;
                            }

                            DateTime currentDateTime = DateTime.Now;
                            TimeSpan difference = targetDateTime.Value - currentDateTime;

                            if (difference.Days > remindDay)
                            {
                                continue;
                            }

                            PlanEntity planEntity = new PlanEntity();
                            planEntity.Plan = planItem;
                            planEntity.Update();
                            planEntity.Plan = null;
                            planEntity.PlanRemindDay = remindDay;
                            planEntity.ProjectName = projectInfo.project_name;
                            planEntity.TargetDate = targetDateTime.Value;
                            planEntity.RespUserName = respUserNameString;
                            string getDepartmentName;
                            if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName))
                            {
                                planEntity.DepartmentName = getDepartmentName;
                            }
                            planRemindList.Add(planEntity);
                        }
                    }
                }
            }
            UpdateChanged("planRemindList");
            IsBusy = false;
        }
        private void OnExportPlanCommand()
        {
            IsBusy = true;

            if (null == SelectProjectEntity.PlanVersionID
                || null == SelectProjectEntity.ManufactureNumber
                || string.Empty == SelectProjectEntity.PlanVersionID
                || string.Empty == SelectProjectEntity.ManufactureNumber)
            {
                Message.ErrorMessage("生产令号或版本号无效");
            }
            else
            {
                IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans
                                                 where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                    && c.version_id == SelectProjectEntity.PlanVersionID
                                                 select c.sheet_name;
                if (sheetNames.Count() > 0)
                {
                    ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                    ObservableCollection<string> differentSheets = new ObservableCollection<string>();
                    foreach (string value in sheetNames)
                    {
                        if (null == value || differentSheets.Contains(value))
                        {
                            continue;
                        }
                        differentSheets.Add(value);
                        IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans
                                                          where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                            && c.version_id == SelectProjectEntity.PlanVersionID
                                                            && c.sheet_name == value
                                                          select c;
                        ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                        bool hasOrderDate = false;
                        foreach (plan item in selectedPlans)
                        {
                            PlanEntity planEntity = new PlanEntity();
                            planEntity.Plan = item;
                            if (item.order_date.HasValue)
                            {
                                hasOrderDate = true;
                            }
                            string getDepartmentName = string.Empty;
                            planEntity.Update();
                            planEntity.ProjectName = SelectProjectEntity.ProjectName;
                            if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName))
                            {
                                planEntity.DepartmentName = getDepartmentName;
                            }
                            planList.Add(planEntity);
                        }
                        if (planList.Count > 0)
                        {
                            int modelIndex = -1;
                            if ("采购节点" == planList[0].SheetName)
                            {
                                if (hasOrderDate)
                                {
                                    modelIndex = 1;
                                }
                                else
                                {
                                    modelIndex = 2;
                                }
                            }
                            else
                            {
                                modelIndex = 0;
                            }

                            PlanListViewModel planListViewModel = new PlanListViewModel(value, planList,
                                                                        modelIndex, departmentIdNameDictionary);
                            planListViewModel.IsReadOnly = true;
                            planListViewModelList.Add(planListViewModel);
                        }
                    }
                    if (planListViewModelList.Count > 0)
                    {
                        PlanExtraEntity planExtraEntity = null;
                        IEnumerable<plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras
                                                              where c.version_id == SelectProjectEntity.PlanVersionID
                                                              && c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                              select c;
                        if (0 != plan_extras.Count())
                        {
                            planExtraEntity = new PlanExtraEntity();
                            planExtraEntity.PlanExtra = plan_extras.First<plan_extra>();
                            planExtraEntity.Update();
                            planExtraEntity.PlanExtra = null;
                        }
                        PlanListEditWindow planListWindow = new PlanListEditWindow("计划导出", "导出", SelectProjectEntity.PlanVersionID,
                                                                                planListViewModelList, planExtraEntity);
                        planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber;
                        planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                        planListWindow.Show();
                    }
                }
                else
                {
                    string errorMessage = "无相关数据(生产令号:" +
                                            SelectProjectEntity.ManufactureNumber.TrimEnd() +
                                            ",版本号" +
                                            SelectProjectEntity.PlanVersionID
                                            + ")";
                    Message.ErrorMessage(errorMessage);
                }
            }

            IsBusy = false;
        }
        private void OnEvaluateSingleCommand()
        {
            IsBusy = true;
            if (null == SelectProjectEntity.PlanVersionID
                || null == SelectProjectEntity.ManufactureNumber
                || string.Empty == SelectProjectEntity.PlanVersionID
                || string.Empty == SelectProjectEntity.ManufactureNumber)
            {
                Message.ErrorMessage("生产令号或版本号无效");
            }
            else
            {
                IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans
                                                 where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                    && c.version_id == SelectProjectEntity.PlanVersionID
                                                 select c.sheet_name;
                if (sheetNames.Count() > 0)
                {
                    ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                    Dictionary<string, int> accomplishRateDictionary = new Dictionary<string, int>();
                    foreach (string value in sheetNames)
                    {
                        if (null == value || accomplishRateDictionary.ContainsKey(value))
                        {
                            continue;
                        }
                        IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans
                                                          where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                            && c.version_id == SelectProjectEntity.PlanVersionID
                                                            && c.sheet_name == value
                                                          select c;
                        decimal totalValue = 0;
                        decimal accomplishValue = 0;
                        ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                        bool hasOrderDate = false;
                        foreach (plan item in selectedPlans)
                        {
                            if (item.weight.HasValue)
                            {
                                totalValue += item.weight.Value;
                                if (item.accomplish_date.HasValue && item.score.HasValue)
                                {
                                    accomplishValue += item.score.Value;
                                }
                            }

                            PlanEntity planEntity = new PlanEntity();
                            planEntity.Plan = item;
                            if (item.order_date.HasValue)
                            {
                                hasOrderDate = true;
                            }
                            string getDepartmentName = string.Empty;
                            planEntity.Update();
                            planEntity.Plan = null;
                            planEntity.ProjectName = SelectProjectEntity.ProjectName;
                            if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName))
                            {
                                planEntity.DepartmentName = getDepartmentName;
                            }
                            planList.Add(planEntity);
                        }

                        decimal resultValue = (0 == totalValue) ? 0 : accomplishValue / totalValue;
                        int resultInt = Convert.ToInt16(Convert.ToDouble(resultValue) * 100);
                        accomplishRateDictionary.Add(value, resultInt);

                        if (planList.Count > 0)
                        {
                            int modelIndex = -1;
                            if ("采购节点" == planList[0].SheetName)
                            {
                                if (hasOrderDate)
                                {
                                    modelIndex = 1;
                                }
                                else
                                {
                                    modelIndex = 2;
                                }
                            }
                            else
                            {
                                modelIndex = 0;
                            }

                            PlanListViewModel planListViewModel = new PlanListViewModel(value, planList,
                                                                    modelIndex, departmentIdNameDictionary);
                            planListViewModel.IsReadOnly = false;
                            planListViewModelList.Add(planListViewModel);
                        }
                    }
                    if (accomplishRateDictionary.Count > 0)
                    {
                        string title = "计划考核(";
                        title += SelectProjectEntity.ProjectName;
                        title += " ";
                        title += SelectProjectEntity.ManufactureNumber;
                        title += ")";

                        PlanExtraEntity planExtraEntity = null;
                        IEnumerable<plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras
                                                              where c.version_id == SelectProjectEntity.PlanVersionID
                                                              && c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                              select c;
                        if (0 != plan_extras.Count())
                        {
                            planExtraEntity = new PlanExtraEntity();
                            planExtraEntity.PlanExtra = plan_extras.First<plan_extra>();
                            planExtraEntity.Update();
                            planExtraEntity.PlanExtra = null;
                        }

                        PlanListEvaluateWindow planEvaluateResultWindow = new PlanListEvaluateWindow(title, planListViewModelList,
                                                                                accomplishRateDictionary, planExtraEntity);
                        planEvaluateResultWindow.Closed += new EventHandler(PlanListWindow_Closed);
                        planEvaluateResultWindow.Show();
                    }
                }
                else
                {
                    string errorMessage = "无相关数据(生产令号:" +
                                            SelectProjectEntity.ManufactureNumber.TrimEnd() +
                                            ",版本号" +
                                            SelectProjectEntity.PlanVersionID
                                            + ")";
                    Message.ErrorMessage(errorMessage);
                }
            }
            IsBusy = false;
        }
        private bool GetPorjectPlanList(ProjectEntity item, ref ObservableCollection<PlanEntity> planList)
        {
            bool rturnValue = false;
            IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans
                                             where c.manufacture_number == item.ManufactureNumber
                                                && c.version_id == item.PlanVersionID
                                             select c.sheet_name;
            if (sheetNames.Count() > 0)
            {
                ObservableCollection<string> differentSheets = new ObservableCollection<string>();
                foreach (string value in sheetNames)
                {
                    if (null == value || differentSheets.Contains(value))
                    {
                        continue;
                    }
                    differentSheets.Add(value);
                    IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans
                                                      where c.manufacture_number == item.ManufactureNumber
                                                        && c.version_id == item.PlanVersionID
                                                        && c.sheet_name == value
                                                      select c;
                    foreach (plan planItem in selectedPlans)
                    {
                        PlanEntity planEntity = new PlanEntity();
                        planEntity.Plan = planItem;
                        string getDepartmentName = string.Empty;
                        planEntity.Update();
                        planEntity.ProjectName = item.ProjectName;
                        if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName))
                        {
                            planEntity.DepartmentName = getDepartmentName;
                        }
                        planList.Add(planEntity);
                    }
                }

                rturnValue = true;
            }
            return rturnValue;
        }
        private PlanEntity ExcelRowToPlanEntity(string aSheetName, int aRowNumber, Row aExcelRow, Dictionary<string, int> aMatchedColumnDictionary,
                            ref string aLastComponentName)
        {
            do
            {
                PlanEntity planEntity = new PlanEntity();
                int getValue = 0;
                {
                    Cell cell = Cell.EmptyCell;
                    if (!aMatchedColumnDictionary.TryGetValue("序号", out getValue)
                        || -1 == getValue
                        || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                    {
                        string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效序号" ;
                        importErrorList.Add(lError);
                        break;
                    }
                    planEntity.SequenceId = Convert.ToInt32(cell.StringValue);
                }

                int taskDescriptionColumn = -1;
                {
                    Cell cell = Cell.EmptyCell;
                    if (aMatchedColumnDictionary.TryGetValue("任务描述", out taskDescriptionColumn)
                        && -1 != taskDescriptionColumn
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(taskDescriptionColumn)))
                    {
                        planEntity.TaskDescription = cell.StringValue;
                    }
                }

                {
                    Cell cell1 = Cell.EmptyCell;
                    Cell cell2 = Cell.EmptyCell;
                    if ((!aMatchedColumnDictionary.TryGetValue("部件", out getValue)
                         || -1 == getValue
                         || (Cell.EmptyCell == (cell1 = aExcelRow.GetCell(getValue))
                             & Cell.EmptyCell == (cell2 = aExcelRow.GetCell(getValue + 1))))
                        && string.Empty == aLastComponentName)
                    {
                        string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效部件";
                        importErrorList.Add(lError);
                        break;
                    }

                    if (Cell.EmptyCell != cell1)
                    {
                        planEntity.ComponentName = cell1.StringValue;
                    }

                    if (getValue + 1 != taskDescriptionColumn && Cell.EmptyCell != cell2)
                    {
                        planEntity.ComponentName += cell2.StringValue;
                    }

                    if (null == planEntity.ComponentName)
                    {
                        planEntity.ComponentName = string.Empty;
                    }

                    if (string.Empty == planEntity.ComponentName)
                    {
                        planEntity.ComponentName = aLastComponentName;
                    }
                    else
                    {
                        aLastComponentName = planEntity.ComponentName;
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (!aMatchedColumnDictionary.TryGetValue("权重(分值)", out getValue)
                        || -1 == getValue
                        || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                    {
                        string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效权重";
                        importErrorList.Add(lError);
                        break;
                    }
                    planEntity.Weight = Convert.ToDecimal(cell.StringValue);
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (aMatchedColumnDictionary.TryGetValue("实际得分", out getValue)
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue)
                    {
                        try
                        {
                            planEntity.Score = Convert.ToDecimal(cell.StringValue);
                        }
                        catch(FormatException e )
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (!aMatchedColumnDictionary.TryGetValue("计划完成时间", out getValue)
                        || -1 == getValue
                        || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                    {
                        if (!aMatchedColumnDictionary.TryGetValue("计划到货时间", out getValue)
                            || -1 == getValue
                            || Cell.EmptyCell == (cell = aExcelRow.GetCell(getValue)))
                        {
                            string lError = aSheetName + " " + Convert.ToString(aRowNumber + 1) + "行 无效计划时间";
                            importErrorList.Add(lError);
                            break;
                        }
                    }
                    try
                    {
                        planEntity.TargetDate = cell.DateTimeValue;
                    }
                    catch (FormatException e)
                    {
                        //ignore exception
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("计划第一次调整", out getValue)
                         || aMatchedColumnDictionary.TryGetValue("第一次调整", out getValue))
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue)
                    {
                        try
                        {
                            planEntity.TargetDateAdjustment1 = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("计划第二次调整", out getValue)
                         || aMatchedColumnDictionary.TryGetValue("第二次调整", out getValue))
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue)
                    {
                        try
                        {
                            planEntity.TargetDateAdjustment2 = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("实际完成时间", out getValue)
                            && -1 != getValue
                            && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                            && String.Empty != cell.StringValue)
                        || (aMatchedColumnDictionary.TryGetValue("实际到货时间", out getValue)
                            && -1 != getValue
                            && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                            && String.Empty != cell.StringValue))
                    {
                        try
                        {
                            planEntity.AccomplishDate = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    int getDepartmentId = -1;
                    if (aMatchedColumnDictionary.TryGetValue("责任单位", out getValue)
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                        && String.Empty != cell.StringValue
                        && departmentNameIdDictionary.TryGetValue(cell.StringValue, out getDepartmentId))
                    {
                        planEntity.DepartmentId = getDepartmentId;
                        planEntity.DepartmentName = cell.StringValue;
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if (aMatchedColumnDictionary.TryGetValue("备注", out getValue)
                        && -1 != getValue
                        && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue)))
                    {
                        planEntity.Remark = cell.StringValue;
                    }
                }

                {
                    Cell cell = Cell.EmptyCell;
                    if ((aMatchedColumnDictionary.TryGetValue("计划下订单时间", out getValue)
                            && -1 != getValue
                            && Cell.EmptyCell != (cell = aExcelRow.GetCell(getValue))
                            && String.Empty != cell.StringValue))
                    {
                        try
                        {
                            planEntity.OrderDate = cell.DateTimeValue;
                        }
                        catch (FormatException e)
                        {
                            //ignore exception
                        }
                    }
                }

                return planEntity;
            } while (false);
            return null;
        }
        private void OnSmallChangeCommand()
        {
            IsBusy = true;

            if (null == SelectProjectEntity.PlanVersionID
                || null == SelectProjectEntity.ManufactureNumber
                || string.Empty == SelectProjectEntity.PlanVersionID
                || string.Empty == SelectProjectEntity.ManufactureNumber)
            {
                Message.ErrorMessage("生产令号或版本号无效");
            }
            else
            {
                string newVersionId = SelectProjectEntity.PlanVersionID;
            //                 if (!GetNewVersionId(SelectProjectEntity.ManufactureNumber, ref newVersionId))
            //                 {
            //                     Message.ErrorMessage("生成新版本号失败");
            //                     IsBusy = false;
            //                     return;
            //                 }

                IEnumerable<string> sheetNames = from c in planManagerDomainContext.plans
                                                 where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                    && c.version_id == SelectProjectEntity.PlanVersionID
                                                select c.sheet_name;
                if (sheetNames.Count() > 0)
                {
                    ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                    ObservableCollection<string> differentSheets = new ObservableCollection<string>();
                    foreach (string originalValue in sheetNames)
                    {
                        if (null == originalValue)
                        {
                            continue;
                        }
                        string value = originalValue;

                        if ("设计完成节点" == value)
                        {
                            value = "设计节点";
                        }
                        else if ("采购完成节点" == value)
                        {
                            value = "采购节点";
                        }
                        else if ("生产完成节点" == value)
                        {
                            value = "生产节点";
                        }

                        if (differentSheets.Contains(value))
                        {
                            continue;
                        }
                        differentSheets.Add(value);
                        IEnumerable<plan> selectedPlans = from c in planManagerDomainContext.plans
                                                  where c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                    && c.version_id == SelectProjectEntity.PlanVersionID
                                                    && c.sheet_name == originalValue orderby c.sequence_id
                                                  select c;
                        ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                        bool hasOrderDate = false;
                        for (int pos = 0; pos < selectedPlans.Count<plan>(); ++pos)
                        {
                            plan item = selectedPlans.ElementAt(pos); ;
                            PlanEntity planEntity = new PlanEntity();
                            planEntity.Plan = item;
                            if (item.order_date.HasValue)
                            {
                                hasOrderDate = true;
                            }
                            string getDepartmentName = string.Empty;
                            planEntity.Update();
             //                           planEntity.Plan = null;
             //                           planEntity.VersionId = newVersionId;
                            planEntity.ProjectName = SelectProjectEntity.ProjectName;
                            if (departmentIdNameDictionary.TryGetValue(planEntity.DepartmentId, out getDepartmentName))
                            {
                                planEntity.DepartmentName = getDepartmentName;
                            }
                            planList.Add(planEntity);
                        }
                        if (planList.Count > 0)
                        {
                            int modelIndex = -1;
                            if ("采购节点" == planList[0].SheetName)
                            {
                                if (hasOrderDate)
                                {
                                    modelIndex = 1;
                                }
                                else
                                {
                                    modelIndex = 2;
                                }
                            }
                            else
                            {
                                modelIndex = 0;
                            }

                            PlanListViewModel planListViewModel = new PlanListViewModel(value, planList,
                                                                    modelIndex, departmentIdNameDictionary);
                            planListViewModel.IsChanged = false;
                            planListViewModel.IsReadOnly = false;
                            planListViewModelList.Add(planListViewModel);
                        }
                    }
                    if (planListViewModelList.Count > 0)
                    {
                        string title = "少量修改(";
                        title += SelectProjectEntity.ProjectName;
                        title += " ";
                        title += SelectProjectEntity.ManufactureNumber.TrimEnd();
                        title += " ";
                        title += newVersionId;
                        title += ")";
                        PlanExtraEntity planExtraEntity = null;
                        IEnumerable<plan_extra> plan_extras = from c in planManagerDomainContext.plan_extras
                                                              where c.version_id == SelectProjectEntity.PlanVersionID
                                                                && c.manufacture_number == SelectProjectEntity.ManufactureNumber.TrimEnd()
                                                                select c;
                        if (0 != plan_extras.Count())
                        {
                            planExtraEntity = new PlanExtraEntity();
                            planExtraEntity.PlanExtra = plan_extras.First<plan_extra>();
                            planExtraEntity.Update();
            //                             planExtraEntity.VersionId = newVersionId;
            //                             planExtraEntity.PlanExtra = null;
                        }
                        PlanListEditWindow planListWindow = new PlanListEditWindow(title, "修改", newVersionId, planListViewModelList, planExtraEntity);
                        planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber;
                        planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                        planListWindow.Show();
                    }
                }
                else
                {
                    string errorMessage = "无相关数据(生产令号:" +
                                            SelectProjectEntity.ManufactureNumber.TrimEnd() +
                                            ",版本号" +
                                            SelectProjectEntity.PlanVersionID
                                            + ")" + "\r\n"; ;
                    Message.ErrorMessage(errorMessage);
                }
            }

            IsBusy = false;
        }