Exemplo n.º 1
0
        public int CreatePenality(Penalty newPenalty)
        {
            int result = -1;
            try
            {
                conn = db.openConn();
                tr = conn.BeginTransaction();
                sb = new StringBuilder();
                sb.Remove(0, sb.Length);
                sb.Append("INSERT INTO tbPenalty(psnCode,penalDate,penalty,panaltynote)");
                sb.Append(" VALUES (@psnCode,@penalDate,@penalty,@panaltynote)");

                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 = newPenalty.psnCode;
                comm.Parameters.Add("@penalDate", SqlDbType.NVarChar).Value = newPenalty.penalDate;
                comm.Parameters.Add("@penalty", SqlDbType.NVarChar).Value = newPenalty.penalty;
                comm.Parameters.Add("@panaltynote", SqlDbType.NVarChar).Value = newPenalty.panaltynote;
                comm.ExecuteNonQuery();
                tr.Commit();

                result = 1;

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

            }
            finally
            {
                conn.Close();
            }
            return result;
        }
Exemplo n.º 2
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtpsnCode.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาเลือกพนักงานก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtpsnCode.Focus();
                return;
            }

            if (txtpenalty.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนค่าปรับ ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtpenalty.Focus();
                return;
            }

            Penalty newPenalty = new Penalty();

            newPenalty.psnCode = txtpsnCode.Text.Trim();
            string _date = String.Format("{0:dd/MM/yyyy}", DateTime.Now);
            newPenalty.penalDate = _date;
            newPenalty.penalty = txtpenalty.Text.Trim();
            newPenalty.panaltynote = txtpenatyNote.Text.Trim();

            int result = penaltyService.CreatePenality(newPenalty);

            if (result > -1)
            {
                Console.WriteLine("Insert Complete");
                lblresult.Visible = true;
                lblresult.Text = " บันทึกเรียบร้อย ";

            }
            else
            {
                Console.WriteLine("Insert Not Complete");
                lblresult.Visible = true;
                lblresult.Text = " ไม่สามารถบันทึกข้อมูลได้";

            }
        }