private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            bool hasEditing = false;
            bool hasChanged = false;

            for (int pos = 0; pos < planListViewModelList.Count; ++pos)
            {
                PlanListViewModel planListViewModel = planListViewModelList[pos];
                if (planListViewModel.IsEditing)
                {
                    hasEditing = true;
                }

                if (planListViewModel.IsChanged)
                {
                    hasChanged = true;
                }
            }

            if (hasEditing || hasChanged)
            {
                CustomMessage customMesage = new CustomMessage("放弃修改?", CustomMessage.MessageType.Confirm);
                customMesage.Closed += new EventHandler(CancelConfirm_Closed);
                customMesage.Show();
            }
            else
            {
                this.DialogResult = false;
            }
        }
        private void AddTabItem(string header, PlanListViewModel aPlanListViewModel)
        {
            if (string.IsNullOrEmpty(header) || null == aPlanListViewModel)
            {
                return;
            }

            var list = this.planListTabControl.Items.Where(w => ((TabItem)w).Header.ToString() == header);
            if (list.Count() > 0)
            {
                ((TabItem)list.First()).Visibility = Visibility.Visible;

                this.planListTabControl.SelectedItem = list.First();
            }
            else
            {
                TabItem tabItem = new TabItem();

                tabItem.Header = header;

                PlanListStatisticsDataGrid planListDataGrid = new PlanListStatisticsDataGrid(aPlanListViewModel, null != planExtraEntity);

                var tabContent = planListDataGrid as UserControl;

                tabItem.Content = tabContent;
                this.planListTabControl.Items.Add(tabItem);
                this.planListTabControl.SelectedItem = tabItem;
            }
        }
        private void AddTabItem(string header, PlanListViewModel aPlanListViewModel)
        {
            if (string.IsNullOrEmpty(header) || null == aPlanListViewModel)
            {
                return;
            }

            var list = this.planListTabControl.Items.Where(w => ((TabItem)w).Header.ToString() == header);

            if (list.Count() > 0)
            {
                ((TabItem)list.First()).Visibility = Visibility.Visible;

                this.planListTabControl.SelectedItem = list.First();
            }
            else
            {
                TabItem tabItem = new TabItem();

                tabItem.Header = header;

                PlanListStatisticsDataGrid planListDataGrid = new PlanListStatisticsDataGrid(aPlanListViewModel, null != planExtraEntity);

                var tabContent = planListDataGrid as UserControl;

                tabItem.Content = tabContent;
                this.planListTabControl.Items.Add(tabItem);
                this.planListTabControl.SelectedItem = tabItem;
            }
        }
 public PlanListPage(PlanListViewModel vm)
 {
     InitializeComponent();
     BindingContext         = vm;
     listView.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => {
         if (e.SelectedItem == null)
         {
             return;
         }
         ((ListView)sender).SelectedItem = null;
     };
 }
Beispiel #5
0
        public PlanListTraceDataGrid(PlanListViewModel aPlanListViewModel, bool aRemove)
        {
            InitializeComponent();

            this.DataContext       = aPlanListViewModel;
            this.planListViewModel = aPlanListViewModel;
            plansDataGrid.SetValue(Canvas.ZIndexProperty, 3);
            filterExpander.SetValue(Canvas.ZIndexProperty, 1);

            this.showFinishedCheckBox.IsChecked   = true;
            this.showUnfinishedCheckBox.IsChecked = true;

            if (aRemove)
            {
                string projectNameColumn       = "项目名称";
                string manufactureNumberColumn = "生产令号";
                string versionIDColumn         = "版本号";
                for (int pos = plansDataGrid.Columns.Count - 1; pos >= 0; --pos)
                {
                    string currentColumn = plansDataGrid.Columns[pos].Header as string;
                    if (projectNameColumn == currentColumn ||
                        manufactureNumberColumn == currentColumn ||
                        versionIDColumn == currentColumn)
                    {
                        plansDataGrid.Columns.Remove(plansDataGrid.Columns[pos]);
                    }
                }
                this.plansDataGrid.ItemsSource = this.planListViewModel.FilterPlanList;

                this.programNameLabel.Visibility         = Visibility.Collapsed;
                this.programNameTextBox.Visibility       = Visibility.Collapsed;
                this.manufactureNameLabel.Visibility     = Visibility.Collapsed;
                this.manufactureNumberTextBox.Visibility = Visibility.Collapsed;
            }
            else
            {
                PagedCollectionView view = new PagedCollectionView(this.planListViewModel.FilterPlanList);
                view.GroupDescriptions.Add(new PropertyGroupDescription("ProjectName"));
                this.plansDataGrid.ItemsSource = view;
                try
                {
                    foreach (CollectionViewGroup group in view.Groups)
                    {
                        plansDataGrid.CollapseRowGroup(group, true);
                    }
                }
                catch (Exception ex)
                {
                    // Could not collapse group.
                    MessageBox.Show(ex.Message);
                }
            }
        }
        public PlanListTraceDataGrid(PlanListViewModel aPlanListViewModel, bool aRemove)
        {
            InitializeComponent();

            this.DataContext = aPlanListViewModel;
            this.planListViewModel = aPlanListViewModel;
            plansDataGrid.SetValue(Canvas.ZIndexProperty, 3);
            filterExpander.SetValue(Canvas.ZIndexProperty, 1);

            this.showFinishedCheckBox.IsChecked = true;
            this.showUnfinishedCheckBox.IsChecked = true;

            if (aRemove)
            {
                string projectNameColumn = "项目名称";
                string manufactureNumberColumn = "生产令号";
                string versionIDColumn = "版本号";
                for (int pos = plansDataGrid.Columns.Count - 1; pos >= 0; --pos)
                {
                    string currentColumn = plansDataGrid.Columns[pos].Header as string;
                    if (projectNameColumn == currentColumn
                        || manufactureNumberColumn == currentColumn
                        || versionIDColumn == currentColumn)
                    {
                        plansDataGrid.Columns.Remove(plansDataGrid.Columns[pos]);
                    }
                }
                this.plansDataGrid.ItemsSource = this.planListViewModel.FilterPlanList;

                this.programNameLabel.Visibility = Visibility.Collapsed;
                this.programNameTextBox.Visibility = Visibility.Collapsed;
                this.manufactureNameLabel.Visibility = Visibility.Collapsed;
                this.manufactureNumberTextBox.Visibility = Visibility.Collapsed;
            }
            else
            {
                PagedCollectionView view = new PagedCollectionView(this.planListViewModel.FilterPlanList);
                view.GroupDescriptions.Add(new PropertyGroupDescription("ProjectName"));
                this.plansDataGrid.ItemsSource = view;
                try
                {
                    foreach (CollectionViewGroup group in view.Groups)
                    {
                        plansDataGrid.CollapseRowGroup(group, true);
                    }
                }
                catch (Exception ex)
                {
                    // Could not collapse group.
                    MessageBox.Show(ex.Message);
                }
            }
        }
        public PlanListEditWindow(string aTitle, string aOKContent, string aVersionId,
                                  ObservableCollection <PlanListViewModel> aPlanListViewModelList, PlanExtraEntity aPlanExtraEntity)
        {
            InitializeComponent();

            this.Title                 = aTitle;
            this.VersionId             = aVersionId;
            this.OKButton.Content      = aOKContent;
            this.planListViewModelList = aPlanListViewModelList;
            this.planExtraEntity       = aPlanExtraEntity;

            for (int pos = 0; pos < planListViewModelList.Count; ++pos)
            {
                PlanListViewModel planListViewModel = planListViewModelList[pos];
                AddTabItem(planListViewModel.Title, planListViewModel);
            }
        }
        private void EditingConfirm_Closed(object sender, EventArgs e)
        {
            CustomMessage customMesage = sender as CustomMessage;

            if (customMesage.DialogResult == true)
            {
                for (int pos = 0; pos < planListViewModelList.Count; ++pos)
                {
                    PlanListViewModel planListViewModel = planListViewModelList[pos];
                    if (planListViewModel.IsEditing)
                    {
                        planListViewModelList[pos].OnOKCommand();
                    }
                }
                this.DialogResult = true;
            }
        }
 public MainPage()
 {
     InitializeComponent();
     RateAppCommand = new Command(RateApp);
     BindingContext = this;
     CurrentPurchasesStackLayout   = CurrentStack;
     CompletedPurchasesStackLayout = CompletetCurrentStack;
     HistoryStackLayout            = HistoryStack;
     PlanStackLayout      = PlanStack;
     PhotoStackLayout     = PhotoStack;
     SettingsStackLayout  = SettingsStack;
     GroupStackLayout     = GroupStack;
     NameLabel.FontFamily = Device.RuntimePlatform == Device.Android ? "jakobextractt.ttf#JacobExtraCTT" : "Assets/jakobextractt.ttf#JacobExtraCTT";//убрать в XAML
     activePurchases      = new PurchaseListViewModel(this);
     plan     = new PlanListViewModel(this);
     history  = new HistoryListViewModel(this);
     settings = new SettingsViewModel(this);
     groups   = new GroupListViewModel(this);
 }
        public PlanListStatisticsWindow(string aTitle, PlanListViewModel aPlanListViewModel, PlanExtraEntity aPlanExtraEntity)
        {
            InitializeComponent();
            this.Title             = aTitle;
            this.planListViewModel = aPlanListViewModel;
            this.planExtraEntity   = aPlanExtraEntity;

            if (null == aPlanExtraEntity)
            {
                this.planListTabControl.Margin = new Thickness(2, 2, 2, 40);
                this.planListTabControl.SetValue(Canvas.ZIndexProperty, 3);
                this.planExtraGrid.SetValue(Canvas.ZIndexProperty, 1);
            }
            else
            {
                this.planExtraGrid.DataContext = planExtraEntity;
            }

            AddTabItem(planListViewModel.Title, planListViewModel);
        }
        public PlanListStatisticsWindow(string aTitle, PlanListViewModel aPlanListViewModel, PlanExtraEntity aPlanExtraEntity)
        {
            InitializeComponent();
            this.Title = aTitle;
            this.planListViewModel = aPlanListViewModel;
            this.planExtraEntity = aPlanExtraEntity;

            if (null == aPlanExtraEntity)
            {
                this.planListTabControl.Margin = new Thickness(2, 2, 2, 40);
                this.planListTabControl.SetValue(Canvas.ZIndexProperty, 3);
                this.planExtraGrid.SetValue(Canvas.ZIndexProperty, 1);
            }
            else
            {
                this.planExtraGrid.DataContext = planExtraEntity;
            }

            AddTabItem(planListViewModel.Title, planListViewModel);
        }
 public PlanListEvaluateDataGrid(PlanListViewModel aPlanListViewModel, bool aRemove)
 {
     InitializeComponent();
     if (aRemove)
     {
         string projectNameColumn       = "项目名称";
         string manufactureNumberColumn = "生产令号";
         string versionIDColumn         = "版本号";
         for (int pos = plansDataGrid.Columns.Count - 1; pos >= 0; --pos)
         {
             string currentColumn = plansDataGrid.Columns[pos].Header as string;
             if (projectNameColumn == currentColumn ||
                 manufactureNumberColumn == currentColumn ||
                 versionIDColumn == currentColumn)
             {
                 plansDataGrid.Columns.Remove(plansDataGrid.Columns[pos]);
             }
         }
     }
     this.planListViewModel = aPlanListViewModel;
     this.DataContext       = this.planListViewModel;
 }
Beispiel #13
0
        public PlanListEditDataGrid(PlanListViewModel aPlanListViewModel)
        {
            InitializeComponent();
            this.DataContext = aPlanListViewModel;

            if (1 != aPlanListViewModel.ColumnModelIndex)
            {
                string removeColumn = "计划下订单时间";
                foreach (DataGridColumn column in plansDataGrid.Columns)
                {
                    if (removeColumn == column.Header as string)
                    {
                        plansDataGrid.Columns.Remove(column);
                        break;
                    }
                }
            }

            if (0 == aPlanListViewModel.ColumnModelIndex ||
                2 == aPlanListViewModel.ColumnModelIndex)
            {
                orderDateLable.Visibility  = Visibility.Collapsed;
                OrderDatePicker.Visibility = Visibility.Collapsed;
            }

            if (1 == aPlanListViewModel.ColumnModelIndex ||
                2 == aPlanListViewModel.ColumnModelIndex)
            {
                targetDateLable.Content     = "计划到货时间";
                accomplishDateLable.Content = "实际到货时间";
            }

            if (aPlanListViewModel.IsReadOnly)
            {
                this.plansDataGrid.Margin = new Thickness(0, 0, 0, 0);
                this.plansDataGrid.SetValue(Canvas.ZIndexProperty, 3);
                this.selectedPlanGrid.SetValue(Canvas.ZIndexProperty, 1);
            }
        }
 public PlanListEvaluateDataGrid(PlanListViewModel aPlanListViewModel, bool aRemove)
 {
     InitializeComponent();
     if (aRemove)
     {
         string projectNameColumn = "项目名称";
         string manufactureNumberColumn = "生产令号";
         string versionIDColumn = "版本号";
         for (int pos = plansDataGrid.Columns.Count - 1; pos >= 0; --pos)
         {
             string currentColumn = plansDataGrid.Columns[pos].Header as string;
             if (projectNameColumn == currentColumn
                 || manufactureNumberColumn == currentColumn
                 || versionIDColumn == currentColumn)
             {
                 plansDataGrid.Columns.Remove(plansDataGrid.Columns[pos]);
             }
         }
     }
     this.planListViewModel = aPlanListViewModel;
     this.DataContext = this.planListViewModel;
 }
 public PlanListStatisticsDataGrid(PlanListViewModel aPlanListViewModel, bool aRemove)
 {
     InitializeComponent();
     if (aRemove)
     {
         string projectNameColumn       = "项目名称";
         string manufactureNumberColumn = "生产令号";
         string versionIDColumn         = "版本号";
         for (int pos = plansDataGrid.Columns.Count - 1; pos >= 0; --pos)
         {
             string currentColumn = plansDataGrid.Columns[pos].Header as string;
             if (projectNameColumn == currentColumn ||
                 manufactureNumberColumn == currentColumn ||
                 versionIDColumn == currentColumn)
             {
                 plansDataGrid.Columns.Remove(plansDataGrid.Columns[pos]);
             }
         }
     }
     this.planListViewModel = aPlanListViewModel;
     this.DataContext       = this.planListViewModel;
     plansDataGrid.SetValue(Canvas.ZIndexProperty, 3);
     filterExpander.SetValue(Canvas.ZIndexProperty, 1);
 }
 public PlanListStatisticsDataGrid(PlanListViewModel aPlanListViewModel, bool aRemove)
 {
     InitializeComponent();
     if (aRemove)
     {
         string projectNameColumn = "项目名称";
         string manufactureNumberColumn = "生产令号";
         string versionIDColumn = "版本号";
         for (int pos = plansDataGrid.Columns.Count - 1; pos >= 0; --pos )
         {
             string currentColumn = plansDataGrid.Columns[pos].Header as string;
             if (projectNameColumn == currentColumn
                 || manufactureNumberColumn == currentColumn
                 || versionIDColumn == currentColumn)
             {
                 plansDataGrid.Columns.Remove(plansDataGrid.Columns[pos]);
             }
         }
     }
     this.planListViewModel = aPlanListViewModel;
     this.DataContext = this.planListViewModel;
     plansDataGrid.SetValue(Canvas.ZIndexProperty, 3);
     filterExpander.SetValue(Canvas.ZIndexProperty, 1);
 }
        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 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;
        }
        private void OnViewAllPlanCommand()
        {
            IsBusy = true;

            ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
            foreach (ProjectEntity item in ProjectList)
            {
                if (null == item.PlanVersionID
                || null == item.ManufactureNumber
                || string.Empty == item.PlanVersionID
                || string.Empty == item.ManufactureNumber)
                {
                    continue;
                }

                GetPorjectPlanList(item, ref planList);
            }

            if (planList.Count > 0)
            {
                PlanListViewModel planListViewModel = new PlanListViewModel("所有项目计划", planList, 0, departmentIdNameDictionary);
                planListViewModel.IsReadOnly = true;
                PlanExtraEntity planExtraEntity = null;

                PlanListStatisticsWindow planListStatisticsWindow = new PlanListStatisticsWindow("查询计划", planListViewModel, planExtraEntity);
                planListStatisticsWindow.Show();
            }

            IsBusy = false;
        }
        void HistoryListWindow_Closed(object sender, EventArgs e)
        {
            PlanListHistoryWindow planListWindow = sender as PlanListHistoryWindow;
            if (planListWindow.DialogResult == true)
            {
                if (null == planListWindow.projectEntity || String.IsNullOrEmpty(planListWindow.SelectVersionId))
                {
                    Message.ErrorMessage("无效计划版本");
                }
                else
                {
                    Dictionary<string, ObservableCollection<PlanEntity>> planListDictionary = new Dictionary<string, ObservableCollection<PlanEntity>>();
                    Dictionary<string, int> moduleIndexDictionary = new Dictionary<string, int>();
                    if (GetPorjectPlanList(planListWindow.projectEntity, planListWindow.SelectVersionId, false, ref planListDictionary, ref moduleIndexDictionary))
                    {
                        if (planListDictionary.Count > 0)
                        {
                            ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                            foreach (KeyValuePair<string, ObservableCollection<PlanEntity>> kv in planListDictionary)
                            {
                                PlanListViewModel planListViewModel = new PlanListViewModel(kv.Key,
                                                                            planListDictionary[kv.Key],
                                                                            moduleIndexDictionary[kv.Key],
                                                                            departmentIdNameDictionary);
                                planListViewModel.IsReadOnly = true;
                                planListViewModelList.Add(planListViewModel);
                            }

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

                            string title = "历史计划" + planListWindow.projectEntity.ProjectName + " "
                                            + planListWindow.projectEntity.ManufactureNumber.TrimEnd() + " "
                                            + planListWindow.SelectVersionId + " "
                                            + "(红色(超过计划时间);品红(接近计划时间);绿色(按时完成);紫色(超时完成);灰色(无状态))";

                            PlanListHistoryWindow planListHistoryWindow = new PlanListHistoryWindow(title, planListViewModelList,
                                                                                planExtraEntity, this,
                                                                                planListWindow.projectEntity,
                                                                                planListWindow.SelectVersionId);
                            planListHistoryWindow.Closed += new EventHandler(HistoryListWindow_Closed);
                            planListHistoryWindow.Show();
                        }
                    }
                    else
                    {
                        string errorMessage = "无相关数据(生产令号:" +
                                                planListWindow.projectEntity.ManufactureNumber.TrimEnd() +
                                                ",版本号" +
                                                planListWindow.SelectVersionId
                                                + ")";
                        Message.ErrorMessage(errorMessage);
                    }
                }
            }
        }
        private void ViewSingle()
        {
            Dictionary<string, ObservableCollection<PlanEntity>> planListDictionary = new Dictionary<string, ObservableCollection<PlanEntity>>();
            Dictionary<string, int> moduleIndexDictionary = new Dictionary<string, int>();
            if (GetPorjectPlanList(SelectProjectEntity, SelectProjectEntity.PlanVersionID, true, ref planListDictionary, ref moduleIndexDictionary))
            {
                if (planListDictionary.Count > 0)
                {
                    ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                    foreach (KeyValuePair<string, ObservableCollection<PlanEntity>> kv in planListDictionary)
                    {
                        PlanListViewModel planListViewModel = new PlanListViewModel(kv.Key,
                                                                    planListDictionary[kv.Key],
                                                                    moduleIndexDictionary[kv.Key],
                                                                    departmentIdNameDictionary);
                        planListViewModel.IsReadOnly = true;
                        planListViewModelList.Add(planListViewModel);
                    }

                    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;
                    }

                    string title = "跟踪计划" + SelectProjectEntity.ProjectName + " "
                                    + SelectProjectEntity.ManufactureNumber + " "
                                    + SelectProjectEntity.PlanVersionID + " "
                                    + "(红色(超过计划时间);品红(接近计划时间);绿色(按时完成);紫色(超时完成);灰色(无状态))";

                    PlanListTraceWindow planListWindow = new PlanListTraceWindow(title, planListViewModelList,
                                                                        planExtraEntity, this);
                    planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                    planListWindow.Show();
                }
            }
            else
            {
                string errorMessage = "无相关数据(生产令号:" +
                                        SelectProjectEntity.ManufactureNumber.TrimEnd() +
                                        ",版本号" +
                                        SelectProjectEntity.PlanVersionID
                                        + ")";
                Message.ErrorMessage(errorMessage);
            }
        }
        private void ViewMulti()
        {
            Dictionary<string, ObservableCollection<PlanEntity>> planListDictionary = new Dictionary<string, ObservableCollection<PlanEntity>>();
            Dictionary<string, int> moduleIndexDictionary = new Dictionary<string, int>();

            foreach (ProjectEntity item in SelectedProjectList)
            {
                if (null == item.PlanVersionID
                || null == item.ManufactureNumber
                || string.Empty == item.PlanVersionID
                || string.Empty == item.ManufactureNumber)
                {
                    continue;
                }

                GetPorjectPlanList(item, item.PlanVersionID, true, ref planListDictionary, ref moduleIndexDictionary);
            }

            if (planListDictionary.Count > 0)
            {
                ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                foreach (KeyValuePair<string, ObservableCollection<PlanEntity>> kv in planListDictionary)
                {
                    PlanListViewModel planListViewModel = new PlanListViewModel(kv.Key,
                                                                planListDictionary[kv.Key],
                                                                moduleIndexDictionary[kv.Key],
                                                                departmentIdNameDictionary);
                    planListViewModel.IsReadOnly = true;
                    planListViewModelList.Add(planListViewModel);
                }

                PlanListTraceWindow planListWindow = new PlanListTraceWindow("跟踪计划(说明:红色(超过计划时间);品红(接近计划时间);绿色(按时完成);紫色(超时完成);灰色(无状态))",
                    planListViewModelList, null, this);
                planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                planListWindow.Show();
            }
        }
        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 OnViewSinglePlanCommand()
        {
            IsBusy = true;

            if (null == SelectProjectEntity.PlanVersionID
                || null == SelectProjectEntity.ManufactureNumber
                || string.Empty == SelectProjectEntity.PlanVersionID
                || string.Empty == SelectProjectEntity.ManufactureNumber)
            {
                Message.ErrorMessage("生产令号或版本号无效");
            }
            else
            {
                ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                if (GetPorjectPlanList(SelectProjectEntity, ref planList))
                {
                    if (planList.Count > 0)
                    {
                        string title = SelectProjectEntity.ProjectName + " " + SelectProjectEntity.ManufactureNumber.TrimEnd() + " " + SelectProjectEntity.PlanVersionID;
                        PlanListViewModel planListViewModel = new PlanListViewModel(title, planList, 0, departmentIdNameDictionary);
                        planListViewModel.IsReadOnly = true;
                        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;
                        }

                        PlanListStatisticsWindow planListStatisticsWindow = new PlanListStatisticsWindow("查询计划", planListViewModel, planExtraEntity);
                        planListStatisticsWindow.Show();
                    }
                }
                else
                {
                    string errorMessage = "无相关数据(生产令号:" +
                                            SelectProjectEntity.ManufactureNumber.TrimEnd() +
                                            ",版本号" +
                                            SelectProjectEntity.PlanVersionID
                                            + ")";
                    Message.ErrorMessage(errorMessage);
                }
            }

            IsBusy = false;
        }
        private void OnImportAndChangeCommand()
        {
            IsBusy = true;
            //             string newVersionId = SelectProjectEntity.PlanVersionID;
            //             if (!GetNewVersionId(SelectProjectEntity.ManufactureNumber, ref newVersionId))
            //             {
            //                 Message.ErrorMessage("生成新版本号失败");
            //                 IsBusy = false;
            //                 return;
            //             }

            OpenFileDialog oFile = new OpenFileDialog();
            // .xls filter specified to select only .xls file.
            oFile.Filter = "Excel (*.xls)|*.xls";

            if (oFile.ShowDialog() == true)
            {
                ObservableCollection<PlanListViewModel> planListViewModelList = new ObservableCollection<PlanListViewModel>();
                string excelVersionId = string.Empty;
                string errorMessage = string.Empty;
                string lastVersionId = string.Empty;
                string getFileId = string.Empty;
                string getRequirement = string.Empty;
                PlanExtraEntity planExtraEntity = null;
                importErrorList.Clear();

                try
                {
                    FileStream fs = oFile.File.OpenRead();
                    Workbook book = Workbook.Open(fs);
                    for (int loop = 0; loop < book.Worksheets.Count; ++loop)
                    {
                        if ("设计完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "设计节点";
                        }
                        else if ("采购完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "采购节点";
                        }
                        else if ("生产完成节点" == book.Worksheets[loop].Name)
                        {
                            book.Worksheets[loop].Name = "生产节点";
                        }
                        int firstValueRow = -1;
                        string getManufactureName = string.Empty;
                        int modelIndex = -1;
                        Dictionary<string, int> matchedColumnDictionary = new Dictionary<string, int>();
                        if (-1 == (modelIndex = ExcelSheetValidation(book.Worksheets[loop], ref firstValueRow,  ref getManufactureName,
                                                                    ref excelVersionId, ref getFileId, ref getRequirement, ref matchedColumnDictionary)))
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "格式与模板不匹配;\r\n";
                            continue;
                        }

                        if (string.Empty == excelVersionId)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "解析版本号失败;\r\n";
                            continue;
                        }

                        if (string.Empty != lastVersionId && excelVersionId != lastVersionId)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "版本号与上页不一致;\r\n";
                            continue;
                        }

                        if (SelectProjectEntity.ManufactureNumber.TrimEnd() != getManufactureName)
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "生产令号不正确;\r\n";
                            continue;
                        }

                        var lResult = from c in planManagerDomainContext.plans
                                      where c.version_id == excelVersionId
                                      && c.manufacture_number == getManufactureName
                                      select c;
                        if (0 != lResult.Count())
                        {
                            errorMessage += book.Worksheets[loop].Name;
                            errorMessage += "版本号重复;\r\n";
                            continue;
                        }
                        lastVersionId = excelVersionId;

                        ObservableCollection<int> sequenceIdList = new ObservableCollection<int>();
                        ObservableCollection<PlanEntity> planList = new ObservableCollection<PlanEntity>();
                        string lastComponentName = string.Empty;
                        foreach (KeyValuePair<int, Row> rowPair in book.Worksheets[loop].Cells.Rows)
                        {
                            try
                            {
                                if (rowPair.Key < firstValueRow
                                    || CellToPlanExtraEntity(rowPair.Value, getManufactureName, getFileId, getRequirement, ref planExtraEntity)
                                    || rowPair.Value.LastColIndex < 1)
                                {
                                    //不允许穿插
                                    continue;
                                }
                            }
                            catch (Exception e)
                            {
                                //empty line
                                continue;
                            }

                            PlanEntity planEntity = ExcelRowToPlanEntity(book.Worksheets[loop].Name, rowPair.Key, rowPair.Value, matchedColumnDictionary, ref lastComponentName);
                            if (null != planEntity)
                            {
                                while (sequenceIdList.Contains(planEntity.SequenceId))
                                {
                                    planEntity.SequenceId++;
                                }
                                sequenceIdList.Add(planEntity.SequenceId);

                                planEntity.VersionId = excelVersionId;
                                planEntity.ManufactureNumber = getManufactureName;
                                planEntity.SheetName = book.Worksheets[loop].Name;
                                planList.Add(planEntity);
                            }
                        }

                        if (planList.Count > 0)
                        {
                            PlanListViewModel planListViewModel = new PlanListViewModel(book.Worksheets[loop].Name, planList,
                                                                      modelIndex, departmentIdNameDictionary);
                            planListViewModel.IsReadOnly = false;
                            planListViewModelList.Add(planListViewModel);
                        }
                    }

                    if (string.Empty == errorMessage && 0 == planListViewModelList.Count)
                    {
                        errorMessage = "无效文件 " + oFile.File.Name + "\r\n";
                    }
                    else
                    {
                        foreach (string value in importErrorList)
                        {
                            errorMessage += (value + "\r\n");
                        }
                        importErrorList.Clear();
                    }
                }
                catch (Exception e)
                {
                    errorMessage = e.Message;
                }

                if (planListViewModelList.Count > 0)
                {
                    string title = "大量修改(";
                    title += SelectProjectEntity.ProjectName;
                    title += " ";
                    title += SelectProjectEntity.ManufactureNumber;
                    title += " ";
                    title += excelVersionId;
                    title += ")";
                    if (null != planExtraEntity)
                    {
                        planExtraEntity.VersionId = excelVersionId;
                    }
                    PlanListEditWindow planListWindow = new PlanListEditWindow(title, "修改", excelVersionId, planListViewModelList, planExtraEntity);
                    planListWindow.ManufactureNumber = SelectProjectEntity.ManufactureNumber;
                    planListWindow.Closed += new EventHandler(PlanListWindow_Closed);
                    planListWindow.Show();

                    if (string.Empty != errorMessage)
                    {
                        Message.InfoMessage(errorMessage);
                    }
                }
                else
                {
                    Message.ErrorMessage(errorMessage);
                }
            }
            IsBusy = false;
        }