コード例 #1
0
        private void sbtnAdd_Click(object sender, System.EventArgs e)
        {
            CMSMData.CMSMStruct.GoodsStruct gs = new CMSMData.CMSMStruct.GoodsStruct();
            err             = null;
            gs.strGoodsType = this.cmbGoodsType.Text.Trim();
            if (!cs.ChkGoodsIDDup(txtGoodsID.Text.Trim(), out err))
            {
                gs.strGoodsID = txtGoodsID.Text.Trim();
            }
            else
            {
                MessageBox.Show("该编号已经存在,请重新输入!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                if (err != null)
                {
                    clog.WriteLine(err);
                }
                txtGoodsID.Focus();
                return;
            }

            if (txtGoodsName.Text.Trim() == "")
            {
                MessageBox.Show("商品名称不能为空!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else if (!cs.ChkGoodsNameDup(txtGoodsName.Text.Trim(), out err))
            {
                gs.strGoodsName = txtGoodsName.Text.Trim();
            }
            else
            {
                MessageBox.Show("该商品名称已经存在,请重新输入!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                if (err != null)
                {
                    clog.WriteLine(err);
                }
                txtGoodsName.Focus();
                return;
            }

            if (txtPrice.Text.Trim() == "")
            {
                MessageBox.Show("商品单价不能为空!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                gs.dPrice = Double.Parse(txtPrice.Text.Trim());
            }

            if (txtIgValue.Text.Trim() == "" || txtIgValue.Text.Trim() == "0" || int.Parse(txtIgValue.Text.Trim()) < -1)
            {
                MessageBox.Show("兑换分值不正确!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                return;
            }
            else
            {
                gs.iIgValue = int.Parse(txtIgValue.Text.Trim());
            }

            gs.strSpell    = txtSpell.Text.Trim().ToLower();
            gs.strComments = txtComments.Text.Trim();

            err = null;
            cs.InsertGoods(gs, out err);
            if (err != null)
            {
                MessageBox.Show("添加商品信息失败,请重试!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                clog.WriteLine(err);
            }
            else
            {
                MessageBox.Show("添加商品信息成功!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                err = null;
                SysInitial.CreatDS(out err);
                if (err != null)
                {
                    MessageBox.Show("系统出错,将自动关闭,稍后请重新登录系统!", "系统提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                    Application.Exit();
                }
                this.ClearText();
                txtIgValue.Text = "-1";
                this.DgBind();
            }
        }