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

            SqlStr  = "update tc_archives set ";
            SqlStr += "customer_usecode = '" + entity.Customer_usecode.Trim() + "' ";
            SqlStr += ",customer_code = '" + entity.Customer_code.Trim() + "' ";
            SqlStr += ",customer_sex = '" + entity.Customer_sex.Trim() + "' ";
            SqlStr += ",customer_age = '" + entity.Customer_age.Trim() + "' ";

            SqlStr += " where archives_id= '" + entity.Archives_id + "' ";
            SqlCommand sqlCommand = new SqlCommand();

            sqlCommand.CommandText = SqlStr;

            ExcuteSql(sqlCommand);

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
Esempio n. 2
0
        public int InsertArchives(EntityArchives entityArchives)
        {
            string SqlStr = "";

            SqlStr  = "insert into tc_archives";
            SqlStr += " values('"
                      + entityArchives.Customer_usecode.Trim() + "','"
                      + entityArchives.Customer_code.Trim() + "','"
                      + entityArchives.Customer_sex.Trim() + "','"
                      + entityArchives.Customer_age.Trim() + "')";
            SqlCommand sqlCommand = new SqlCommand();

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

            return(Constants.SystemConfig.SERVER_SUCCESS);
        }
Esempio n. 3
0
        //***********************************************************************
        /// <summary>
        /// 保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <history>
        ///    完成信息:李梓楠      2010/11/8 完成
        ///    更新信息:
        /// </history>
        //***********************************************************************
        private void btnCommit_Click(object sender, EventArgs e)
        {
            //判断客户编号不能为空
            if (txtCustomer_usecode.Text.Trim() == string.Empty)
            {
                MessageBox.Show("客户编号不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtCustomer_usecode.Focus();
                return;
            }

            //判断客户名称不能为空
            if (txtCustomer_name.Text.Trim() == string.Empty)
            {
                MessageBox.Show("客户姓名不能为空!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtCustomer_name.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;
                    }
                }
            }
            EntityCustomer entityCustomer = new EntityCustomer();
            EntityArchives entityArchives = new EntityArchives();
            int            result1        = -1;

            try
            {
                result = -1;

                //如果是添加
                if (dataType == DataType.Insert)
                {
                    //向客户实体类添加数据
                    entityCustomer.Customer_name    = txtCustomer_name.Text;
                    entityCustomer.Customer_yxm     = txtCustomer_yxm.Text;
                    entityCustomer.Customer_tel     = txtCustomer_tel.Text;
                    entityCustomer.Customer_address = txtCustomer_address.Text;
                    //向档案实体类添加数据
                    entityArchives.Customer_age     = txtCustomer_age.Text;
                    entityArchives.Customer_usecode = txtCustomer_usecode.Text;
                    entityArchives.Customer_sex     = cbCustomer_sex.Text;

                    //添加标识, "1",固定为个人客户
                    entityCustomer.Customer_flag = "1";


                    dataAccess = new DataAccess();
                    dataAccess.Open();
                    GetData getData = new GetData(dataAccess.Connection);
                    if (getData.InsertIsOnly("tc_archives", "customer_usecode", txtCustomer_usecode.Text.Trim()))
                    {
                        MessageBox.Show("您输入的客户编号已经存在!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtCustomer_usecode.Focus();
                        return;
                    }


                    MakePrimaryKey primaryKey = new MakePrimaryKey(dataAccess.Connection, dataAccess.Transaction);
                    string         code       = primaryKey.MakeCode("客户");
                    entityCustomer.Customer_code = code;
                    entityArchives.Customer_code = code;


                    result  = getData.InsertCustomer(entityCustomer);
                    result1 = getData.InsertArchives(entityArchives);
                }
                //如果是更新
                else if (dataType == DataType.Update)
                {
                    //给选中行赋值
                    countNum = dgv.SelectedRows[0].Index;
                    entityCustomer.Customer_code    = dgv.SelectedRows[0].Cells["CUSTOMER_code"].Value.ToString();
                    entityCustomer.Customer_name    = txtCustomer_name.Text;
                    entityCustomer.Customer_yxm     = txtCustomer_yxm.Text;
                    entityCustomer.Customer_tel     = txtCustomer_tel.Text;
                    entityCustomer.Customer_address = txtCustomer_address.Text;


                    //添加标识, "1",固定为个人客户
                    entityCustomer.Customer_flag = "1";

                    //向档案实体类添加数据
                    entityArchives.Customer_age     = txtCustomer_age.Text;
                    entityArchives.Customer_usecode = txtCustomer_usecode.Text;
                    entityArchives.Customer_sex     = cbCustomer_sex.Text;
                    entityArchives.Customer_code    = entityCustomer.Customer_code;
                    entityArchives.Archives_id      = Convert.ToInt32(dgv.SelectedRows[0].Cells["Archives_id"].Value.ToString());

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

                    GetData getData = new GetData(dataAccess.Connection, dataAccess.Transaction);
                    //判断客户编号重复
                    if (getData.UpdateIsOnly("tc_archives", "Archives_id", entityArchives.Archives_id.ToString(), "customer_usecode", txtCustomer_usecode.Text.Trim()))
                    {
                        MessageBox.Show("您输入的客户编号已经存在!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txtCustomer_usecode.Focus();
                        return;
                    }
                    //取得结果符
                    result  = getData.UpdateCustomer(entityCustomer);
                    result1 = getData.UpdateArchives(entityArchives);
                    //提交事务
                    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 && result1 == 0)
            {
                MessageBox.Show("数据已经保存成功!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                BandingDgv();
            }
            else
            {
                MessageBox.Show("数据保存时发生错误,请检查数据库!", Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            //设置按钮状态
            dataType = DataType.None;
            setButtonState();
        }