private void frmReamMoneyPrint_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; ReamMoney reamMoney = new ReamMoney(); reamMoney = reamMoneyService.getReamMoneyByID(rid); List<ReamMoneyReport> reamMoneyReports = new List<ReamMoneyReport>(); ReamMoneyReport reamMoneyReport = new ReamMoneyReport(); Person p = new Person(); p = personService.getPersonBypsnCode(reamMoney.person.psnCode); reamMoneyReport.fullName = p.psnPreFix + " " + p.psnName + " " + p.psnLastName; reamMoneyReport.amount =Convert.ToString(reamMoney.amount); reamMoneyReport.reamDate = reamMoney.reamdate; reamMoneyReports.Add(reamMoneyReport); ReportDocument rp = new ReportDocument(); string path = Application.StartupPath + @"\report\rptReamMoney.rpt"; rp.Load(path); rp.SetDataSource(reamMoneyReports); PV.ReportSource = rp; }
public int CreateReamMoney(ReamMoney newReamMoney) { int result = -1; try { conn = db.openConn(); tr = conn.BeginTransaction(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append("INSERT INTO tbReamMoney(RID,psnCode,amount,reamdate)"); sb.Append(" VALUES (@RID,@psnCode,@amount,@reamdate)"); string sqlsave; sqlsave = sb.ToString(); comm = new SqlCommand(); comm.Connection = conn; comm.Transaction = tr; comm.CommandText = sqlsave; comm.Parameters.Clear(); comm.Parameters.Add("@RID", SqlDbType.NVarChar).Value = newReamMoney.ID; comm.Parameters.Add("@psnCode", SqlDbType.NVarChar).Value = newReamMoney.person.psnCode; comm.Parameters.Add("@amount", SqlDbType.NVarChar).Value = newReamMoney.amount; comm.Parameters.Add("@reamdate", SqlDbType.NVarChar).Value = newReamMoney.reamdate; comm.ExecuteNonQuery(); tr.Commit(); result = 1; } catch (Exception ex) { tr.Rollback(); conn.Close(); return result; throw ex; } finally { conn.Close(); } return result; }
private void cmdSave_Click(object sender, EventArgs e) { if (txtamount.Text.Trim() == "") { MessageBox.Show("กรุณาป้อนจำนวนที่เบิกก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtamount.Focus(); return; } ReamMoney newReamMoney = new ReamMoney(); int _year = Convert.ToInt32(DateTime.Now.Year.ToString("0000")); _rid = DateTime.Now.Day.ToString("00") + "" + DateTime.Now.Month.ToString("00") + "" + _year.ToString() + DateTime.Now.ToShortTimeString(); newReamMoney.ID = _rid; Person p = new Person(); p = personService.getPersonBypsnCode(txtpsnCode.Text.Trim()); newReamMoney.person = p; newReamMoney.amount = Convert.ToInt32(txtamount.Text.Trim()); int year = Convert.ToInt32(dtpreamdate.Value.Year.ToString("0000")); string _dNow = dtpreamdate.Value.Day.ToString("00") + "/" + dtpreamdate.Value.Month.ToString("00") + "/" + (year+543); newReamMoney.reamdate = _dNow; int result = reamMoneyService.CreateReamMoney(newReamMoney); if (result > -1) { Console.WriteLine("Insert Complete"); lblresult.Visible = true; lblresult.Text = " บันทึกเรียบร้อย "; } else { Console.WriteLine("Insert Not Complete"); lblresult.Visible = true; lblresult.Text = " ไม่สามารถบันทึกข้อมูลได้"; } }
public ReamMoney getReamMoneyByID(string _rid) { ReamMoney reamMoney = null; try { conn = db.openConn(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append(" SELECT ID,RID,psnCode,amount,reamdate FROM tbReamMoney "); sb.Append(" WHERE RID='" + _rid + "'"); string sql; sql = sb.ToString(); comm = new SqlCommand(); comm.CommandText = sql; comm.CommandType = CommandType.Text; comm.Connection = conn; dr = comm.ExecuteReader(); if (dr.HasRows) { DataTable dt = new DataTable(); dt.Load(dr); foreach (DataRow drw in dt.Rows) { reamMoney = new ReamMoney(); reamMoney.ID =drw["RID"].ToString(); Person p = new Person(); p.psnCode = drw["psnCode"].ToString(); reamMoney.person = p; reamMoney.amount =Convert.ToInt32(drw["amount"].ToString()); reamMoney.reamdate = drw["reamdate"].ToString(); } } dr.Close(); } catch (Exception ex) { dr.Close(); conn.Close(); return null; throw ex; } finally { conn.Close(); } return reamMoney; }