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

            SqlStr  = "insert into tc_maintain";
            SqlStr += " values('"
                      + entity.Maintain_code.Trim() + "','"
                      + entity.Maintain_input_code.Trim() + "','"
                      + entity.Maintain_application.Trim() + "','"
                      + entity.Maintain_purpose.Trim() + "','"
                      + entity.Maintain_quality.Trim() + "','"
                      + entity.Maintain_test_items.Trim() + "','"
                      + entity.Maintain_characters.Trim() + "','"
                      + entity.Maintain_create_date + "')";

            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;
            try
            {
                ExcuteSql(sqlCommand);
            }
            catch (Exception ex)
            {
                return(Constants.SystemConfig.SERVER_ERROR);

                throw ex;
            }

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

            SqlStr = "update tc_maintain set ";

            SqlStr += "Maintain_code = '" + entity.Maintain_code.Trim() + "' ,";
            SqlStr += "Maintain_input_code = '" + entity.Maintain_input_code.Trim() + "', ";
            SqlStr += "Maintain_application = '" + entity.Maintain_application.Trim() + "' ,";
            SqlStr += "Maintain_purpose = '" + entity.Maintain_purpose.Trim() + "' ,";
            SqlStr += "Maintain_quality = '" + entity.Maintain_quality.Trim() + "' ,";
            SqlStr += "Maintain_test_items = '" + entity.Maintain_test_items.Trim() + "' ,";
            SqlStr += "Maintain_characters = '" + entity.Maintain_characters.Trim() + "' ,";
            SqlStr += "Maintain_create_date = '" + entity.Maintain_create_date + "' ";

            SqlStr += " where Maintain_code= '" + entity.Maintain_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/21 完成
        ///    更新信息:
        /// </history>
        //***********************************************************************
        private void btnCommit_Click(object sender, EventArgs e)
        {
            //判断入库编号不为空
            if (txtMaintain_input_code.Text.Trim() == string.Empty || txtMaintain_input_code.Text == "双击选择入库编号...")
            {
                MessageBox.Show("入库编号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtMaintain_input_code.Focus();
                return;
            }
            //判断时间有效性
            if (DateTime.Now.Date < dateMaintain_create_date.Value.Date)
            {
                MessageBox.Show("建档日期不可大于今天日期!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                dateMaintain_create_date.Focus();
                return;
            }
            if (inStorageDate > dateMaintain_create_date.Value.Date)
            {
                MessageBox.Show("建档日期不可小于入库日期!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                dateMaintain_create_date.Focus();
                return;
            }
            //判断非法字符
            foreach (Control control in groupBox2.Controls)
            {
                if (control is TextBox)
                {
                    if (Util.CheckRegex(control.Text.Trim()) && !((TextBox)control).ReadOnly)
                    {
                        MessageBox.Show("不可以输入非法字符,请重新输入!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        control.Focus();
                        return;
                    }
                }
            }
            EntityMaintain entity = new EntityMaintain();

            try
            {
                result = -1;

                //如果是添加
                if (dataType == DataType.Insert)
                {
                    entity.Maintain_input_code  = txtMaintain_input_code.Text;
                    entity.Maintain_application = txtMaintain_application.Text;
                    entity.Maintain_purpose     = txtMaintain_purpose.Text;
                    entity.Maintain_quality     = txtMaintain_quality.Text;
                    entity.Maintain_test_items  = txtMaintain_test_items.Text;
                    entity.Maintain_characters  = txtMaintain_characters.Text;
                    entity.Maintain_create_date = dateMaintain_create_date.Value.Date;

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

                    MakePrimaryKey primaryKey = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction);
                    entity.Maintain_code = primaryKey.MakeCode("养护记录");

                    GetData getData = new GetData(dataAccess.Connection);
                    result = getData.InsertMaintainTable(entity);

                    //处理操作标示
                    EntityInput_storage inputStorageEntity = new EntityInput_storage();
                    inputStorageEntity.OPERATE_TYPE = '1';
                    inputStorageEntity.INPUT_CODE   = txtMaintain_input_code.Text;

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

                    entity.Maintain_code        = dgv.SelectedRows[0].Cells["Maintain_code"].Value.ToString();
                    entity.Maintain_input_code  = txtMaintain_input_code.Text;
                    entity.Maintain_application = txtMaintain_application.Text;
                    entity.Maintain_purpose     = txtMaintain_purpose.Text;
                    entity.Maintain_quality     = txtMaintain_quality.Text;
                    entity.Maintain_test_items  = txtMaintain_test_items.Text;
                    entity.Maintain_characters  = txtMaintain_characters.Text;
                    entity.Maintain_create_date = dateMaintain_create_date.Value.Date;

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

                    GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction);
                    //取得结果符
                    result = getData.UpdateMaintainTable(entity);
                    //提交事务
                    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();

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