Esempio n. 1
0
        public int InsertCounterRow(EntityCounter entity)
        {
            string SqlStr = "";

            SqlStr  = "insert into tc_counter";
            SqlStr += " values('" + entity.Counter_code.Trim() + "','" + entity.Counter_manager.Trim() + "','" + entity.Counter_type.Trim() + "')";

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;

            ExcuteSql(sqlCommand);

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
Esempio n. 2
0
        public int UpdateCounterTable(EntityCounter entity)
        {
            string SqlStr = "";

            SqlStr = "update tc_counter set ";

            SqlStr += "Counter_manager = '" + entity.Counter_manager.Trim() + "' ";

            SqlStr += ",Counter_type = '" + entity.Counter_type.Trim() + "' ";

            SqlStr += " where counter_code= '" + entity.Counter_code.Trim() + "' ";

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;

            ExcuteSql(sqlCommand);

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
        //***********************************************************************
        /// <summary>
        /// 确定按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        ///    完成信息:赵毅男      2010/07/13 完成
        ///    更新信息:
        /// </history>
        //***********************************************************************
        private void btnCommit_Click(object sender, EventArgs e)
        {
            foreach (Control control in groupBox2.Controls)
            {
                if (control is TextBox)
                {
                    if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly)
                    {
                        MessageBox.Show("不可以输入非法字符,请重新输入!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        control.Focus();
                        return;
                    }
                }
            }

            if (txtCode.Text.Trim() == string.Empty)
            {
                MessageBox.Show("货位编号不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtCode.Focus();
                return;
            }

            if (txtType.Text.Trim() == string.Empty)
            {
                MessageBox.Show("存货种类不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtType.Focus();
                return;
            }

            if (txtManager.Text.Trim() == "" || txtManager.Text.Trim() == "双击选择负责人...")
            {
                MessageBox.Show("货位负责人不能为空!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtManager.Focus();
                return;
            }

            try
            {
                result = -1;

                //如果是添加
                if (dataType == DataType.Insert)
                {
                    //取得实体类
                    counterEntity = new EntityCounter();

                    //赋值实体类
                    counterEntity.Counter_code    = txtCode.Text;
                    counterEntity.Counter_manager = txtManager.Text;
                    counterEntity.Counter_type    = txtType.Text;

                    //打开数据库连接
                    dataAccess = new DataAccess();
                    dataAccess.Open();

                    //取得操作类
                    GetData getData = new GetData(dataAccess.Connection);

                    if (getData.InsertIsOnly("TC_COUNTER", "Counter_code", txtCode.Text.Trim()))
                    {
                        MessageBox.Show("您输入的货位编号已经存在,请更改货位编号后再保存!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtCode.Focus();
                        return;
                    }

                    //取得结果符
                    result = getData.InsertCounterRow(counterEntity);

                    if (result == 0)
                    {
                        MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("操作添加时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }

                //如果是更新
                else if (dataType == DataType.Update)
                {
                    if (dgvCounter.SelectedRows != null && dgvCounter.SelectedRows.Count != 0)
                    {
                        countNum = dgvCounter.SelectedRows[0].Index;
                    }
                    //取得树体类
                    counterEntity = new EntityCounter();

                    //赋值实体类
                    counterEntity.Counter_code    = txtCode.Text;
                    counterEntity.Counter_manager = txtManager.Text;
                    counterEntity.Counter_type    = txtType.Text;

                    //打开数据库连接
                    dataAccess = new DataAccess();
                    dataAccess.Open();

                    //打开事务
                    dataAccess.BeginTransaction();

                    //取得操作类
                    GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction);


                    if (getData.UpdateIsOnly("TC_COUNTER", "Counter_code", counterEntity.Counter_code, "Counter_code", txtCode.Text.Trim()))
                    {
                        MessageBox.Show("您输入的货位编号已经存在,请更改货位编号后再保存!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtCode.Focus();
                        return;
                    }

                    //取得结果符
                    result = getData.UpdateCounterTable(counterEntity);

                    //提交事务
                    dataAccess.Commit();

                    if (result == 0)
                    {
                        MessageBox.Show("数据已经保存成功!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("操作修改时发生错误,请检查数据库!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                if (dataAccess.Transaction != null)
                {
                    //回滚
                    dataAccess.Rollback();
                }

                //提示错误
                MessageBox.Show("操作数据时发生错误,请检查数据库是否正常开启!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                //关闭数据库连接
                dataAccess.Close();
            }

            //设置按钮状态
            dataType = DataType.None;
            setButtonState();

            //重新加载画面
            BandingDgvCounter();
        }