コード例 #1
0
        public int InsertGoods(EntityGoods entity)
        {
            string SqlStr = "";

            SqlStr  = "insert into tc_goods";
            SqlStr += " values('" + entity.Goods_code.Trim() + "','" + entity.Goods_name.Trim() + "','" + entity.Goods_yxm.Trim();
            SqlStr += "','" + entity.Goods_reg_num.Trim() + "','" + entity.Goods_reg_mark.Trim() + "','" + entity.Goods_type.Trim();
            SqlStr += "','" + entity.Goods_maker.Trim() + "','" + entity.Goods_validity + "','" + entity.Goods_unit.Trim();
            SqlStr += "','" + entity.Goods_storemethod.Trim() + "','" + entity.Goods_appliance_code.Trim() + "','" + entity.Goods_batch_num.Trim() + "')";

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;

            ExcuteSql(sqlCommand);

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
コード例 #2
0
        public int UpdateGoods(EntityGoods entity)
        {
            string SqlStr = "";

            SqlStr  = "update tc_goods";
            SqlStr += " set goods_code = '" + entity.Goods_code.Trim() + "',goods_name='" + entity.Goods_name.Trim() + "',goods_yxm='" + entity.Goods_yxm.Trim();
            SqlStr += "',goods_reg_num='" + entity.Goods_reg_num.Trim() + "',goods_reg_mark='" + entity.Goods_reg_mark.Trim() + "',goods_type='" + entity.Goods_type.Trim();
            SqlStr += "',goods_maker='" + entity.Goods_maker.Trim() + "',goods_validity='" + entity.Goods_validity + "',goods_unit='" + entity.Goods_unit.Trim();
            SqlStr += "',goods_storemethod='" + entity.Goods_storemethod.Trim() + "',goods_appliance_code='" + entity.Goods_appliance_code.Trim() + "'";

            SqlStr += " where goods_code= '" + entity.Goods_code.Trim() + "' ";

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;

            ExcuteSql(sqlCommand);

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
コード例 #3
0
        //***********************************************************************
        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        ///    完成信息:李梓楠      2010/7/15 完成
        ///    更新信息:
        /// </history>
        //***********************************************************************
        private void btnCommit_Click(object sender, EventArgs e)
        {
            //判断有效期不能为空

            //判断产品名称不能为空
            if (txtGoods_name.Text.Trim() == string.Empty)
            {
                MessageBox.Show("产品名称不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_name.Focus();
                return;
            }
            if (txtGoods_appliance_code.Text.Trim() == string.Empty || txtGoods_appliance_code.Text == "双击选择器械分类...")
            {
                MessageBox.Show("器械分类不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_appliance_code.Focus();
                return;
            }
            //判断注册证号不能为空
            if (txtGoods_reg_num.Text.Trim() == string.Empty)
            {
                MessageBox.Show("注册证号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_reg_num.Focus();
                return;
            }

            //判断生产厂家不能为空
            if (txtGoods_maker.Text.Trim() == string.Empty || txtGoods_maker.Text == "双击选择生产厂家...")
            {
                MessageBox.Show("生产厂家不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_maker.Focus();
                return;
            }

            //判断规格型号不能为空
            if (txtGoods_type.Text.Trim() == string.Empty)
            {
                MessageBox.Show("规格型号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_type.Focus();
                return;
            }

            if (txtGoods_validity.Text.Trim() == string.Empty)
            {
                MessageBox.Show("有效期不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_validity.Focus();
                return;
            }

            if (int.Parse(txtGoods_validity.Text.Trim()) == 0)
            {
                MessageBox.Show("有效期不能为0!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_validity.Focus();
                return;
            }

            //判断储藏方法不能为空
            if (txtGoods_storemethod.Text.Trim() == string.Empty)
            {
                MessageBox.Show("储藏方法不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtGoods_storemethod.Focus();
                return;
            }
            //判断非法字符
            foreach (Control control in groupBox1.Controls)
            {
                if (control is TextBox)
                {
                    if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly)
                    {
                        MessageBox.Show("不可以输入非法字符,请重新输入!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        control.Focus();
                        return;
                    }
                }
            }
            EntityGoods entityGoods = new EntityGoods();

            try
            {
                result = -1;

                //如果是添加
                if (dataType == DataType.Insert)
                {
                    entityGoods.Goods_name           = txtGoods_name.Text;
                    entityGoods.Goods_yxm            = txtGoods_yxm.Text;
                    entityGoods.Goods_reg_num        = txtGoods_reg_num.Text;
                    entityGoods.Goods_reg_mark       = txtGoods_reg_mark.Text;
                    entityGoods.Goods_type           = txtGoods_type.Text;
                    entityGoods.Goods_maker          = txtMaker_code.Text;
                    entityGoods.Goods_validity       = Convert.ToInt32(txtGoods_validity.Text.Trim());
                    entityGoods.Goods_unit           = cb_goods_unit.SelectedValue.ToString();
                    entityGoods.Goods_storemethod    = txtGoods_storemethod.Text;
                    entityGoods.Goods_appliance_code = txtGoods_appliance_code.Text;

                    dataAccess = new DataAccess();
                    dataAccess.Open();

                    MakePrimaryKey primaryKey = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction);
                    entityGoods.Goods_code = primaryKey.MakeCode("产品");


                    GetData getData = new GetData(dataAccess.Connection);
                    result = getData.InsertGoods(entityGoods);

                    if (result == 0)
                    {
                        EntityTemp_storage entityTemp = new EntityTemp_storage();
                        entityTemp.Goods_code = entityGoods.Goods_code;
                        getData.InsertTemp_storageTable(entityTemp);
                    }
                }
                //如果是更新
                else if (dataType == DataType.Update)
                {
                    //给选中行赋值
                    countNum = dgv.SelectedRows[0].Index;

                    entityGoods.Goods_code           = txtGoods_code.Text;
                    entityGoods.Goods_name           = txtGoods_name.Text;
                    entityGoods.Goods_yxm            = txtGoods_yxm.Text;
                    entityGoods.Goods_reg_num        = txtGoods_reg_num.Text;
                    entityGoods.Goods_reg_mark       = txtGoods_reg_mark.Text;
                    entityGoods.Goods_type           = txtGoods_type.Text;
                    entityGoods.Goods_maker          = txtMaker_code.Text;
                    entityGoods.Goods_validity       = Convert.ToInt32(txtGoods_validity.Text.Trim());
                    entityGoods.Goods_unit           = cb_goods_unit.SelectedValue.ToString();
                    entityGoods.Goods_storemethod    = txtGoods_storemethod.Text;
                    entityGoods.Goods_appliance_code = txtGoods_appliance_code.Text;

                    dataAccess = new DataAccess();
                    dataAccess.Open();
                    dataAccess.BeginTransaction();

                    GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction);
                    //取得结果符
                    result = getData.UpdateGoods(entityGoods);
                    //提交事务
                    dataAccess.Commit();
                }
            }
            catch (Exception ex)
            {
                if (dataAccess.Transaction != null)
                {
                    //回滚
                    dataAccess.Rollback();
                }
                //提示错误
                MessageBox.Show("数据添加时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                throw ex;
            }
            finally
            {
                //关闭数据库连接
                dataAccess.Close();
            }
            if (result == 0)
            {
                MessageBox.Show("数据已经保存成功!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                BandingDgv();
            }
            else
            {
                MessageBox.Show("数据保存时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //设置按钮状态
            dataType = DataType.None;
            setButtonState();
        }