Пример #1
0
		private void toolItem_Modify_Click(object sender, EventArgs e) {
			ToolStripButton cButton = sender as ToolStripButton;
			int iIndex = int.Parse(cButton.Tag as string);

			string sExchange = null;
			string sDataSource = null;
			Product cProduct = null;
			AbstractProductProperty cProperty = null;
			switch (iIndex) {
				case 1:  //新增
					frmCreateProduct frmCreateProduct = new frmCreateProduct();
					DialogResult cResult = frmCreateProduct.ShowDialog();
					if (cResult == DialogResult.OK) {
						sDataSource = frmCreateProduct.DataSource;
						sExchange = frmCreateProduct.ExchangeName;
						cProduct = frmCreateProduct.Product;
						cProperty = frmCreateProduct.Property;

						ESymbolCategory cCategory = cProduct.Category;
						RefreshCategoryNode(sExchange, cCategory);     //更新樹狀結構
						RefreshSymbolCategorys(sExchange, cCategory);  //更新表格
					}
					break;
				case 2:  //修改
				case 3:  //刪除
					if (dataGrid.SelectedDataRows.Length > 0) {
						object oData = dataGrid.SelectedDataRows[0];
						if (oData != null) {
							_ProductInfo cProductInfo = oData as _ProductInfo;

							string sSymbolId = cProductInfo.ProductId;
							sExchange = cProductInfo.ExchangeName;
							sDataSource = cProductInfo.DataSource;
							sDataSource = (sDataSource.Length == 0) ? null : sDataSource;
							AbstractExchange cExchange = ProductManager.Manager.GetExchange(sExchange);
							cProduct = cExchange.GetProduct(sSymbolId);

							if (iIndex == 2) {  //修改動作
								cProperty = cExchange.GetProperty(sSymbolId, sDataSource);
							} else {  //刪除動作
								bool bDeleteProperty = sDataSource != null;
								if (!bDeleteProperty) {
									DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_001, __sMessageHeader_001, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
									bDeleteProperty |= cDeleteResult == DialogResult.Yes;
								}

								if (bDeleteProperty) {
									DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_002, __sMessageHeader_002, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
									if (cDeleteResult == DialogResult.Yes) {
										cExchange.RemoveProperty(sSymbolId, sDataSource);  //要先移除屬性設定(因為屬性會從 Product 結構取得商品資訊, 所以要先移除屬性設定)
									}

									if (sDataSource == null) {  //如果資料報價來源是 null 才可以移除商品(如果為 null 會詢問使用者是否要刪除)
										cExchange.RemoveProduct(sSymbolId);
									}

									ESymbolCategory cCategory = cProduct.Category;
									RefreshCategoryNode(sExchange, cCategory);     //更新樹狀結構
									RefreshSymbolCategorys(sExchange, cCategory);  //更新表格
								}
								return;
							}
						}
					}
					break;
			}

			if (cProduct != null && cProperty != null) {
				frmProductPropertySettings frmProductPropertySettings = new frmProductPropertySettings();
				frmProductPropertySettings.SetParameters(sExchange, sDataSource, cProduct, cProperty.Clone());
				DialogResult cResult = frmProductPropertySettings.ShowDialog();
				if (cResult == DialogResult.OK) {
					string sExchangeName = __cSelectedNode.Parent.Text;
					ESymbolCategory cCategory = (ESymbolCategory) __cSelectedNode.Tag;

					RefreshSymbolCategorys(sExchangeName, cCategory);  //更新表格
				}
			}
		}
Пример #2
0
        private void toolItem_Modify_Click(object sender, EventArgs e)
        {
            ToolStripButton cButton = sender as ToolStripButton;
            int             iIndex  = int.Parse(cButton.Tag as string);

            string  sExchange   = null;
            string  sDataSource = null;
            Product cProduct    = null;
            AbstractProductProperty cProperty = null;

            switch (iIndex)
            {
            case 1:                      //新增
                frmCreateProduct frmCreateProduct = new frmCreateProduct();
                DialogResult     cResult          = frmCreateProduct.ShowDialog();
                if (cResult == DialogResult.OK)
                {
                    sDataSource = frmCreateProduct.DataSource;
                    sExchange   = frmCreateProduct.ExchangeName;
                    cProduct    = frmCreateProduct.Product;
                    cProperty   = frmCreateProduct.Property;

                    ESymbolCategory cCategory = cProduct.Category;
                    RefreshCategoryNode(sExchange, cCategory);                                 //更新樹狀結構
                    RefreshSymbolCategorys(sExchange, cCategory);                              //更新表格
                }
                break;

            case 2:                      //修改
            case 3:                      //刪除
                if (dataGrid.SelectedDataRows.Length > 0)
                {
                    object oData = dataGrid.SelectedDataRows[0];
                    if (oData != null)
                    {
                        _ProductInfo cProductInfo = oData as _ProductInfo;

                        string sSymbolId = cProductInfo.ProductId;
                        sExchange   = cProductInfo.ExchangeName;
                        sDataSource = cProductInfo.DataSource;
                        sDataSource = (sDataSource.Length == 0) ? null : sDataSource;
                        AbstractExchange cExchange = ProductManager.Manager.GetExchange(sExchange);
                        cProduct = cExchange.GetProduct(sSymbolId);

                        if (iIndex == 2)                                    //修改動作
                        {
                            cProperty = cExchange.GetProperty(sSymbolId, sDataSource);
                        }
                        else                                      //刪除動作
                        {
                            bool bDeleteProperty = sDataSource != null;
                            if (!bDeleteProperty)
                            {
                                DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_001, __sMessageHeader_001, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                bDeleteProperty |= cDeleteResult == DialogResult.Yes;
                            }

                            if (bDeleteProperty)
                            {
                                DialogResult cDeleteResult = MessageBox.Show(__sMessageContent_002, __sMessageHeader_002, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                                if (cDeleteResult == DialogResult.Yes)
                                {
                                    cExchange.RemoveProperty(sSymbolId, sDataSource);                                              //要先移除屬性設定(因為屬性會從 Product 結構取得商品資訊, 所以要先移除屬性設定)
                                }

                                if (sDataSource == null)                                            //如果資料報價來源是 null 才可以移除商品(如果為 null 會詢問使用者是否要刪除)
                                {
                                    cExchange.RemoveProduct(sSymbolId);
                                }

                                ESymbolCategory cCategory = cProduct.Category;
                                RefreshCategoryNode(sExchange, cCategory);                                             //更新樹狀結構
                                RefreshSymbolCategorys(sExchange, cCategory);                                          //更新表格
                            }
                            return;
                        }
                    }
                }
                break;
            }

            if (cProduct != null && cProperty != null)
            {
                frmProductPropertySettings frmProductPropertySettings = new frmProductPropertySettings();
                frmProductPropertySettings.SetParameters(sExchange, sDataSource, cProduct, cProperty.Clone());
                DialogResult cResult = frmProductPropertySettings.ShowDialog();
                if (cResult == DialogResult.OK)
                {
                    string          sExchangeName = __cSelectedNode.Parent.Text;
                    ESymbolCategory cCategory     = (ESymbolCategory)__cSelectedNode.Tag;

                    RefreshSymbolCategorys(sExchangeName, cCategory);                      //更新表格
                }
            }
        }