public ChangeManufactureNumberWindowViewModel(ChildWindow aChildWindow, ProductEntity aProductEntity)
        {
            childWindow = aChildWindow;
            ProductEntity = aProductEntity;
            Title = "修改产品 " + ProductEntity.ProductName + " 生产令号:" + ProductEntity.ManufactureNumber;

            ManufactureNumberList = new ObservableCollection<String>();
            foreach (KeyValuePair<String,ProjectEntity> ProjectEntityPair in ProductEntity.ProjectEntityDictionary)
            {
                ManufactureNumberList.Add(ProjectEntityPair.Key);
            }

            OnOK = new DelegateCommand(OnOKCommand);
            OnCancel = new DelegateCommand(OnCancelCommand);
        }
        private SystemManageDomainContext SystemManageDomainContext; //; = new SystemManageDomainContext();

        #endregion Fields

        #region Constructors

        public ProductPartTimeWindowViewModel(ChildWindow aChildWindow, ProductEntity aProductEntity)
        {
            childWindow = aChildWindow;
            ProductEntity = aProductEntity;
            productPartTimeWindowState = ProductPartTimeWindowState.NO;
            ProductPartTimeEntityList = new ObservableCollection<ProductPartTimeEntity>();
            ProductPartTypeEntityList = new ObservableCollection<ProductPartTypeEntity>();
            ProductPartTypeDictionary = new Dictionary<int, ProductPartTypeEntity>();

            Title = "产品 " + ProductEntity.ProductID + " : " + ProductEntity.ProductName + " 阶段";

            OnQuit = new DelegateCommand(OnQuitCommand, CanQuitCommand);
            OnAdd = new DelegateCommand(OnAddCommand, CanAddCommand);
            OnModify = new DelegateCommand(OnModifyCommand, CanModifyCommand);
            OnSave = new DelegateCommand(OnSaveCommand, CanSaveCommand);
            OnCancel = new DelegateCommand(OnCancelCommand, CanCancelCommand);

            IsNotAddorModify = true;
            LoadData();
        }
        public ProductWindowViewModel(ChildWindow aChildWindow, ObservableCollection<ProductTypeEntity> aProductTypeEntityList, /*ObservableCollection<UserEntity> aUserEntityList,*/ ProductWindowType aProductWindowType, ProductEntity aProductEntity)
        {
            childWindow = aChildWindow;
            ProductEntity = aProductEntity;
            productWindowType = aProductWindowType;
            //UserEntityList = aUserEntityList;
            ProductTypeEntityList = aProductTypeEntityList;

            //App app = Application.Current as App;
            //CanSetOutputNumber = app.UserInfo.GetUerRight(2010600);

            if (productWindowType == ProductWindowType.ADD)
            {
                IsAdd = true;
            }
            else
            {
                IsAdd = false;
            }

            if (productWindowType == ProductWindowType.View)
            {
                IsView = true;
            }
            else
            {
                IsView = false;
            }

            if (!String.IsNullOrWhiteSpace(ProductEntity.ManufactureNumber))
            {
                Title = "生产令号:" + ProductEntity.ManufactureNumber;
            }
            OnOK = new DelegateCommand(OnOKCommand);
            OnCancel = new DelegateCommand(OnCancelCommand);
        }
        private void LoadOperationProductCompleted(LoadOperation<ProductManager.Web.Model.product> aLoadOperation)
        {
            ProductEntityList.Clear();
            foreach (ProductManager.Web.Model.product product in aLoadOperation.Entities)
            {
                ProductEntity productEntity = new ProductEntity();
                productEntity.Product = product;
                productEntity.Update();

                ProjectEntity lProjectEntityTemp;
                if (ProjectEntityDictionary.TryGetValue(productEntity.ManufactureNumber, out lProjectEntityTemp))
                {
                    productEntity.ProjectName = lProjectEntityTemp.ProjectName;
                }

                if (ProjectNameSearch != null && ProjectNameSearch.Length > 0)
                {
                    if (!productEntity.ProjectName.Contains(ProjectNameSearch))
                    {
                        continue;
                    }
                }

                ProductEntityList.Add(productEntity);
            }
            IsBusy = false;
        }
        private void OnImportCommand()
        {
            OpenFileDialog lOpenFile = new OpenFileDialog();
            lOpenFile.Filter = "Excel (*.xls)|*.xls";
            Dictionary<String, int> lHeaderDictionary = new Dictionary<String, int>();

            if (lOpenFile.ShowDialog() == true)
            {
                ProductEntityList.Clear();

                try
                {
                    FileStream fs = lOpenFile.File.OpenRead();
                    Workbook book = Workbook.Open(fs);

                    foreach (KeyValuePair<int, Row> rowPair in book.Worksheets[0].Cells.Rows)
                    {
                        if (rowPair.Key == 0)
                        {
                            try
                            {
                                foreach (KeyValuePair<int, Cell> cellPair in rowPair.Value)
                                {
                                    lHeaderDictionary.Add(cellPair.Value.StringValue, cellPair.Key);
                                }
                            }
                            catch (System.Exception ex)
                            {
                                Message.ErrorMessage("表头重复或超出范围!");
                                break;
                            }
                            continue;
                        }

                        ProductEntity lProductEntity = new ProductEntity();
                        lProductEntity.Product = new ProductManager.Web.Model.product();
                        lProductEntity.ProductEntityDictionary = ProductEntityDictionary;
                        lProductEntity.ProjectEntityDictionary = ProjectEntityDictionary;
                        //lProductEntity.ProductPartTypeEntityDictionary = ProductTypeEntityDictionary;

                        int lManufactureNumberColumn = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("生产令号", out lManufactureNumberColumn)
                                && -1 != lManufactureNumberColumn
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lManufactureNumberColumn)))
                            {
                                lProductEntity.ManufactureNumber = cell.StringValue;
                                ProjectEntity projectEntityTemp;
                                if (!ProjectEntityDictionary.TryGetValue(lProductEntity.ManufactureNumber, out projectEntityTemp))
                                {
                                    NotifyWindow lNotifyWindow = new NotifyWindow("错误","第 " + rowPair.Key.ToString() + "行 系统中没有生产令号:" + lProductEntity.ManufactureNumber);
                                    lNotifyWindow.Show();
                                    return;
                                }
                            }
                            else
                            {
                                NotifyWindow lNotifyWindow = new NotifyWindow("错误", "第 " + rowPair.Key.ToString() + "行 系统中没有生产令号:" + lProductEntity.ManufactureNumber);
                                lNotifyWindow.Show();
                                return;
                            }
                        }

                        int lProjectNameColumn = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("序列号", out lProjectNameColumn)
                                && -1 != lProjectNameColumn
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lProjectNameColumn)))
                            {
                                lProductEntity.ProductID = cell.StringValue;

                                ProductEntity lProductEntityTemp;
                                if (ProductEntityDictionary.TryGetValue(lProductEntity.ProductID, out lProductEntityTemp))
                                {
                                    NotifyWindow lNotifyWindow = new NotifyWindow("错误","第 " + rowPair.Key.ToString() + "行 序列号重复:" + lProductEntity.ProductID);
                                    lNotifyWindow.Show();
                                    return;
                                }
                                if (CurrentProductEntityDicationary.TryGetValue(lProductEntity.ProductID, out lProductEntityTemp))
                                {
                                    NotifyWindow lNotifyWindow = new NotifyWindow("错误", "第 " + rowPair.Key.ToString() + "行 序列号重复:" + lProductEntity.ProductID);
                                    lNotifyWindow.Show();
                                    return;
                                }
                            }
                        }

                        int lModelNumberColumn = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("产品类型", out lModelNumberColumn)
                                && -1 != lModelNumberColumn
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lModelNumberColumn)))
                            {
                                lProductEntity.ProductTypeString = cell.StringValue;

                                int lId;
                                if (ProductTypeIDDictionary.TryGetValue(lProductEntity.ProductTypeString, out lId))
                                {
                                    lProductEntity.ProductTypeID = lId;
                                }
                                else
                                {
                                    NotifyWindow lNotifyWindow = new NotifyWindow("错误", "第 " + rowPair.Key.ToString() + "行 系统中无该产品类型:" + lProductEntity.ProductTypeString);
                                    lNotifyWindow.Show();
                                    return;
                                }
                            }
                        }

                        int lRemarkColumn = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("名称", out lRemarkColumn)
                                && -1 != lRemarkColumn
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lRemarkColumn)))
                            {
                                lProductEntity.ProductName = cell.StringValue;
                            }
                        }

                        int lInputTimeColume = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("编制日期", out lInputTimeColume)
                                && -1 != lInputTimeColume
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lInputTimeColume)))
                            {
                                lProductEntity.ProductIDCreateData = cell.DateTimeValue;
                            }
                        }

                        int lOutputNumberColume = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("出厂编号", out lOutputNumberColume)
                                && -1 != lOutputNumberColume
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lOutputNumberColume)))
                            {
                                lProductEntity.ProductOutputNumber = cell.StringValue;
                            }
                        }

                        int lNote1 = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("备注1", out lNote1)
                                && -1 != lNote1
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lNote1)))
                            {
                                lProductEntity.ProductDescript1 = cell.StringValue;
                            }
                        }

                        int lNote2 = -1;
                        {
                            Cell cell = Cell.EmptyCell;
                            if (lHeaderDictionary.TryGetValue("备注1", out lNote2)
                                && -1 != lNote2
                                && Cell.EmptyCell != (cell = rowPair.Value.GetCell(lNote2)))
                            {
                                lProductEntity.ProductDescript2 = cell.StringValue;
                            }
                        }

                        lProductEntity.DUpdate();
                        ProductEntityList.Add(lProductEntity);
                        CurrentProductEntityDicationary.Add(lProductEntity.ProductID, lProductEntity);
                        //ProductContext.projects.Add(lProjectEntity.Project);
                    }

                }
                catch (System.Exception ex)
                {
                    Message.ErrorMessage(ex.Message);
                }
            }
        }
 public ProductPartTimeWindow(ProductEntity aProductEntity)
 {
     InitializeComponent();
     this.DataContext = new ProductPartTimeWindowViewModel(this, aProductEntity);
 }
 private void OnAddProductCommand()
 {
     AddProductEntity = new ProductEntity();
     AddProductEntity.ProjectEntityDictionary = ProjectEntityDictionary;
     AddProductEntity.ManufactureNumber = SelectProjectEntity.ManufactureNumber;
     AddProductEntity.ProductIDCreateData = DateTime.Now;
     AddProductEntity.ProductTypeID = 1;
     AddProductEntity.Product = new ProductManager.Web.Model.product();
     AddProductEntity.ProductEntityDictionary = ProductEntityDictionary;
     ProductWindow productWindow = new ProductWindow(ProductWindowType.ADD, ProductTypeEntityList, AddProductEntity);
     productWindow.Closed += AddProductClosed;
     productWindow.Show();
 }
        void loadOperationProductDictionary_Completed(object sender, EventArgs e)
        {
            ProductEntityDictionary.Clear();

            LoadOperation loadOperation = sender as LoadOperation;
            foreach (ProductManager.Web.Model.product product in loadOperation.Entities)
            {
                ProductEntity productEntity = new ProductEntity();
                productEntity.Product = product;
                productEntity.Update();
                ProductEntityDictionary.Add(productEntity.ProductID, productEntity);
            }

            LoadOperation<ProductManager.Web.Model.product_part_type> loadOperationProductPartType =
               SystemManageDomainContext.Load<ProductManager.Web.Model.product_part_type>(SystemManageDomainContext.GetProduct_part_typeQuery());
            loadOperationProductPartType.Completed += loadOperationPartTimeType_Completed;
        }
        private void LoadOperationProductCompleted(LoadOperation<ProductManager.Web.Model.product> aLoadOperation)
        {
            ProductEntityList.Clear();
            foreach (ProductManager.Web.Model.product product in aLoadOperation.Entities)
            {
                ProductEntity productEntity = new ProductEntity();
                productEntity.Product = product;
                productEntity.ProjectEntityDictionary = ProjectEntityDictionary;
                productEntity.ProductPartTypeEntityDictionary = ProductPartTypeDictionary;
                productEntity.Update();

                productEntity.ProductEntityDictionary = ProductEntityDictionary;
                ProductTypeEntity lProductTypeEntity;
                if (ProductTypeEntityDictionary.TryGetValue(productEntity.ProductTypeID, out lProductTypeEntity))
                {
                    productEntity.ProductTypeString = lProductTypeEntity.ProductTypeName;
                }

                ProductEntityList.Add(productEntity);
            }
            if (aLoadOperation.TotalEntityCount != -1)
            {
                this.productView.SetTotalItemCount(aLoadOperation.TotalEntityCount);
            }
            UpdateChanged("ProductEntityList");
            this.IsBusy = false;
        }
 public ChangeProductManufactureNumberWindow(ProductEntity aProductEntity)
 {
     InitializeComponent();
     this.DataContext = new ChangeManufactureNumberWindowViewModel(this, aProductEntity);
 }
 public ProductWindow(ProductWindowType aProductWindowType, ObservableCollection<ProductTypeEntity> aProductTypeEntityList, ProductEntity aProductEntity)
 {
     InitializeComponent();
     this.DataContext = new ProductWindowViewModel(this, aProductTypeEntityList, aProductWindowType, aProductEntity);
 }