private void btnAdd_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtItemName.Text))
            {
                return;
            }

            decimal tmpValue;
            if (!decimal.TryParse(txtItemCost.Text, out tmpValue))
            {
                MessageBox.Show("ItemCost must be number");
                return;
            }
            if (AddCostCalculateItemEvent != null)
            {
                NewCostItemEventArgs args = new NewCostItemEventArgs();

                args.CostItem.ItemName = txtItemName.Text;
                args.CostItem.ItemCategory = (CostItemCategory)Enum.Parse(typeof(CostItemCategory), cboItemCategory.SelectedItem.ToString(), false);
                args.CostItem.ItemType = (CostItemType)Enum.Parse(typeof(CostItemType), cboItemType.SelectedItem.ToString(), false);
                args.CostItem.ItemCost = tmpValue;
                args.CostItem.ItemRemark = txtItemRemark.Text;

                AddCostCalculateItemEvent(this, args);

                txtItemName.Clear();
            }
            if (!chkKeepShow.Checked)
            {
                this.Close();
            }
        }
Beispiel #2
0
        private void f_AddCostCalculateItemEvent(object sender, NewCostItemEventArgs e)
        {
            //检测项目名称是否和已经存在的重名
            foreach (var item in CurrentCalculateSheet.CostItemList)
            {
                if (item.ItemName==e.CostItem.ItemName)
                {
                    MessageBox.Show("ItemName must be different from those already exist");
                    return;
                }
            }

            CurrentCalculateSheet.CostItemList.Add(e.CostItem);
            ReLoadDgv();
        }