Example #1
0
        private void btnSave_Click(object sender, System.EventArgs e)
        {
            if (cboxCatg.SelectedIndex == -1)
            {
                return;
            }
            chngFlag = false;
            Goods goods = new Goods();
            int   exCnt = 0;

            goods.GName     = txtGName.Text.Trim();
            goods.Abbr      = txtAbbr.Text.Trim();
            goods.Remark    = txtRemark.Text.Trim();
            goods.Specs     = txtSpecs.Text.Trim();
            goods.SubCatgID = StringUtil.Obj2Short(cboxCatg.SelectedValue);
            goods.ShelfLife = txtShelfLife.Text.Trim() + cboxShelfLife.SelectedValue.ToString();
            string gId = txtGId.Text.Trim();

            if (rbtnInvalid.Checked)
            {
                goods.St = ST.INVALID;
            }
            if (rbtnValid.Checked)
            {
                goods.St = ST.VALID;
            }

            if (!StringUtil.isEmpty(gId))
            {
                goods.GID__PK = int.Parse(gId);
                exCnt         = manager.Update(goods);
            }
            else
            {
                int supplierId = StringUtil.Obj2Int(cboxSupplier.SelectedValue);
                if (supplierId != 0)
                {
                    exCnt = manager.Save(goods, supplierId);
                }
                else
                {
                    exCnt = manager.Save(goods, null);
                }
            }

            if (exCnt > 0)
            {
                chngFlag = true;
                MainForm.Info("保存成功!");
                if (!StringUtil.isEmpty(gId))
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    txtGName.Text     = string.Empty;
                    txtAbbr.Text      = string.Empty;
                    txtRemark.Text    = string.Empty;
                    txtSpecs.Text     = string.Empty;
                    txtShelfLife.Text = string.Empty;
                }
            }
            else
            {
                MainForm.Warn("保存失败!");
            }
        }