Пример #1
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtmoney.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนจำนวนที่ต้องจ่าย  ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtmoney.Focus();
                return;
            }

            Orther newOrther = new Orther();
            newOrther.ID =0;
            Person _p = new Person();
            _p.psnCode = txtpsnCode.Text.Trim();
            newOrther.person =_p;
            newOrther.subject =txtsubject.Text.Trim();
            newOrther.amount = Convert.ToInt32(txtmoney.Text.Trim());

            int result = ortherService.CreateOrther(newOrther);
            if (result > -1)
            {
                Console.WriteLine("Insert Complete");
                lblresult.Visible = true;
                lblresult.Text = " บันทึกเรียบร้อย ";
                //MessageBox.Show("บันทึกข้อมูล เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                Console.WriteLine("Insert Not Complete");
                lblresult.Visible = true;
                lblresult.Text = " ไม่สามารถบันทึกข้อมูลได้";
                //MessageBox.Show("ไม่สามารถบันทึกข้อมูล เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Пример #2
0
        public int CreateOrther(Orther newOrther)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO tbOrther(psnCode,subject,amount)");
                sb.Append(" VALUES (@psnCode,@subject,@amount)");

                string sqlsave;
                sqlsave = sb.ToString();

                comm = new SqlCommand();
                comm.Connection = conn;
                comm.Transaction = tr;
                comm.CommandText = sqlsave;
                comm.Parameters.Clear();
                comm.Parameters.Add("@psnCode", SqlDbType.NVarChar).Value = newOrther.person.psnCode;
                comm.Parameters.Add("@subject", SqlDbType.NVarChar).Value = newOrther.subject;
                comm.Parameters.Add("@amount", SqlDbType.NVarChar).Value = newOrther.amount;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

            }
            catch (Exception ex)
            {
                tr.Rollback();
                conn.Close();
                return result;
                throw ex;

            }
            finally
            {
                conn.Close();
            }
            return result;
        }