Advertisement
Ang377ou

processpayment

Mar 23rd, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Data.SqlClient;
  10. using System.Text.RegularExpressions;
  11.  
  12. namespace Parkinglotmanagementsystem
  13. {
  14. public partial class b : Form
  15. {
  16. public b()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21. private bool isNotEmpty()
  22. {
  23. bool flag = true;
  24. //return (cbtype.Text != string.Empty && txtplate.Text != string.Empty &&
  25. // txtTimeIn.Text != string.Empty && txtpayment.Text != string.Empty);
  26. if (cbtype.Text != string.Empty && txtplate.Text != string.Empty &&
  27. txtTimeIn.Text != string.Empty && txtpayment.Text != string.Empty)
  28. {
  29. flag = true;
  30. }
  31. else
  32. {
  33. flag = false;
  34. }
  35. return flag;
  36. }
  37.  
  38. private void Clear()
  39. {
  40. txtticket.Text = p.Generate_TicketNo();
  41. Load_Datas();
  42. txtplate.Clear();
  43. cbtype.Text = string.Empty;
  44. txtplate.Clear();
  45. txtTimeIn.Clear();
  46. txtTimeOut.Clear();
  47. txtconsume.Clear();
  48. txtpayment.Clear();
  49. txtcash.Clear();
  50. txtchange.Clear();
  51. cbtype.Focus();
  52. }
  53.  
  54. private void btnadd_Click(object sender, EventArgs e)
  55. {
  56. //insert..
  57. if (plate())
  58. {
  59. if (isNotEmpty())
  60. {
  61. p.Insert(txtticket.Text, cbtype.Text, txtplate.Text, txtTimeIn.Text, txtTimeOut.Text, txtconsume.Text,
  62. txtpayment.Text, txtcash.Text, txtchange.Text);
  63. MessageBox.Show("Successfully added", string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
  64. Clear();
  65. }
  66. }
  67. else
  68. {
  69. MessageBox.Show("The plate number must contain 3 Uppercase and 3 numeric!");
  70. }
  71. }
  72.  
  73. Payments p = new Payments(clsDbconnection.Connect());
  74. private void txtticket_KeyDown(object sender, KeyEventArgs e)
  75. {
  76. if (e.KeyValue == 13)
  77. {
  78. //
  79. }
  80. }
  81.  
  82. private void Load_Datas()
  83. {
  84. lvipayment.Items.Clear();
  85. DataTable dt = p.Load_Datas();
  86. for (int i = 0; i < dt.Rows.Count; i++)
  87. {
  88. lvipayment.Items.Add(new ListViewItem(new string[]
  89. {
  90. DateTime.Parse(dt.Rows[i]["Date"].ToString()).ToShortDateString(),
  91. dt.Rows[i]["TicketID"].ToString(),
  92. dt.Rows[i]["VehicleType"].ToString(),
  93. dt.Rows[i]["Platenumber"].ToString(),
  94. dt.Rows[i]["Timein"].ToString(),
  95. dt.Rows[i]["Timeout"].ToString(),
  96. dt.Rows[i]["HoursConsumed"].ToString(),
  97. dt.Rows[i]["TotalPayment"].ToString(),
  98. dt.Rows[i]["Cash"].ToString(),
  99. dt.Rows[i]["Change"].ToString()
  100. }));
  101. }
  102. }
  103.  
  104. private void Form1_Load(object sender, EventArgs e)
  105. {
  106. CheckForIllegalCrossThreadCalls = false;
  107. txtticket.Text = p.Generate_TicketNo();
  108. Load_Datas();
  109. timer1.Interval = 1000;
  110. timer1.Enabled = true;
  111. timer1.Start();
  112. }
  113. private bool plate()
  114. {
  115. bool flag = true;
  116. if (Regex.IsMatch(txtplate.Text, @"^(?=.*[A-Z])(?=.*\d).{6,6}$"))
  117. {
  118. flag = true;
  119. }
  120. else
  121. {
  122. flag = false;
  123. }
  124. return flag;
  125. }
  126.  
  127. private void timer1_Tick(object sender, EventArgs e)
  128. {
  129. txtTimeIn.Text = DateTime.Now.ToShortTimeString();
  130. }
  131.  
  132.  
  133.  
  134. private void btnclear_Click(object sender, EventArgs e)
  135. {
  136. //update...
  137. p.Update(txtticket.Text, txtTimeOut.Text, txtconsume.Text, txtpayment.Text, txtcash.Text, txtchange.Text);
  138. MessageBox.Show("Successfully paid");
  139. Clear();
  140. timer1.Enabled = true;
  141. timer1.Start();
  142. }
  143.  
  144. private void cbtype_SelectedIndexChanged(object sender, EventArgs e)
  145. {
  146. switch (cbtype.Text)
  147. {
  148. case "Truck":
  149. {
  150. txtpayment.Text = "0.00";
  151. txtTimeOut.Text = "0";
  152. }
  153. break;
  154. case "Jeep":
  155. {
  156. txtpayment.Text = "0.00";
  157. txtTimeOut.Text = "0";
  158. }
  159. break;
  160. case "Car":
  161. {
  162. txtpayment.Text = "0.00";
  163. txtTimeOut.Text = "0";
  164. }
  165. break;
  166. default:
  167. {
  168. txtpayment.Text = "0.00";
  169. txtTimeOut.Text = "0";
  170. }
  171. break;
  172. }
  173. }
  174.  
  175. private void txtcash_TextChanged(object sender, EventArgs e)
  176. {
  177. try
  178. {
  179. if (txtcash.Text.Length > 0 && !txtcash.Text.Equals("0") && double.Parse(txtcash.Text) >= double.Parse(txtpayment.Text))
  180. {
  181. txtchange.Text = double.Parse(txtcash.Text) >= double.Parse(txtpayment.Text) ?
  182. (double.Parse(txtcash.Text) - double.Parse(txtpayment.Text)).ToString() : "0";
  183. txtchange.Text = double.Parse(txtchange.Text) < 0 ? "0" : txtchange.Text;
  184. btnupdate.Enabled = true;
  185. }
  186. else
  187. {
  188. btnupdate.Enabled = false;
  189. }
  190. }
  191. catch {
  192. btnupdate.Enabled = false; }
  193. }
  194.  
  195. private void txtsearch_TextChanged(object sender, EventArgs e)
  196. {
  197. if (txtsearch.Text.Length > 0)
  198. {
  199. lvipayment.Items.Clear();
  200. DataTable dt = p.Load_Details(txtsearch.Text);
  201. if (dt.Rows.Count > 0)
  202. {
  203. for (int i = 0; i < dt.Rows.Count; i++)
  204. {
  205. lvipayment.Items.Add(new ListViewItem(new string[]
  206. {
  207. DateTime.Parse(dt.Rows[i]["Date"].ToString()).ToShortDateString(),
  208. dt.Rows[i]["TicketID"].ToString(),
  209. dt.Rows[i]["VehicleType"].ToString(),
  210. dt.Rows[i]["Platenumber"].ToString(),
  211. dt.Rows[i]["Timein"].ToString(),
  212. dt.Rows[i]["Timeout"].ToString(),
  213. dt.Rows[i]["HoursConsumed"].ToString(),
  214. dt.Rows[i]["TotalPayment"].ToString(),
  215. dt.Rows[i]["Cash"].ToString(),
  216. dt.Rows[i]["Change"].ToString()
  217. }));
  218. }
  219. }
  220. else
  221. {
  222. MessageBox.Show("No result found");
  223. }
  224.  
  225. }
  226. }
  227.  
  228. private void txtsearch_KeyDown(object sender, KeyEventArgs e)
  229. {
  230.  
  231. if (e.KeyValue.Equals(13))
  232. {
  233. timer1.Enabled = false;
  234. timer1.Stop();
  235.  
  236. DataTable dt = p.Search_Load_Details(txtsearch.Text);
  237. for (int i = 0; i < dt.Rows.Count; i++)
  238. {
  239. txtticket.Text = dt.Rows[i]["TicketID"].ToString();
  240. cbtype.Text = dt.Rows[i]["VehicleType"].ToString();
  241. txtplate.Text = dt.Rows[i]["Platenumber"].ToString();
  242. txtTimeOut.Text = DateTime.Now.ToShortTimeString();
  243. txtTimeIn.Text = dt.Rows[i]["Timein"].ToString();
  244. string hour = DateTime.Parse(DateTime.Now.ToShortTimeString()).Subtract(DateTime.Parse(txtTimeIn.Text)).TotalHours.ToString();
  245. string[] time = hour.Split(new char[] { '.' });
  246. txtconsume.Text = int.Parse(time[1].Substring(0,1)) > 4 ? (int.Parse(time[0]) + 1).ToString() :
  247. int.Parse(time[0]).Equals(0) ? "1" : time[0];
  248. txtpayment.Text = (int.Parse(txtconsume.Text) * 30).ToString();
  249. btnadd.Enabled = false;
  250. }
  251. }
  252. }
  253.  
  254. private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  255. {
  256. switch (comboBox1.Text)
  257. {
  258. case "All":
  259. {
  260. lvipayment.Items.Clear();
  261. DataTable dt = p.Load_All_Datas();
  262. for (int i = 0; i < dt.Rows.Count; i++)
  263. {
  264. lvipayment.Items.Add(new ListViewItem(new string[]
  265. {
  266. DateTime.Parse(dt.Rows[i]["Date"].ToString()).ToShortDateString(),
  267. dt.Rows[i]["TicketID"].ToString(),
  268. dt.Rows[i]["VehicleType"].ToString(),
  269. dt.Rows[i]["Platenumber"].ToString(),
  270. dt.Rows[i]["Timein"].ToString(),
  271. dt.Rows[i]["Timeout"].ToString(),
  272. dt.Rows[i]["HoursConsumed"].ToString(),
  273. dt.Rows[i]["TotalPayment"].ToString(),
  274. dt.Rows[i]["Cash"].ToString(),
  275. dt.Rows[i]["Change"].ToString()
  276. }));
  277. }
  278. }
  279. break;
  280. case "Unpaid":
  281. {
  282. lvipayment.Items.Clear();
  283. DataTable dt = p.Load_Datas_Unpaid();
  284. for (int i = 0; i < dt.Rows.Count; i++)
  285. {
  286. lvipayment.Items.Add(new ListViewItem(new string[]
  287. {
  288. DateTime.Parse(dt.Rows[i]["Date"].ToString()).ToShortDateString(),
  289. dt.Rows[i]["TicketID"].ToString(),
  290. dt.Rows[i]["VehicleType"].ToString(),
  291. dt.Rows[i]["Platenumber"].ToString(),
  292. dt.Rows[i]["Timein"].ToString(),
  293. dt.Rows[i]["Timeout"].ToString(),
  294. dt.Rows[i]["HoursConsumed"].ToString(),
  295. dt.Rows[i]["TotalPayment"].ToString(),
  296. dt.Rows[i]["Cash"].ToString(),
  297. dt.Rows[i]["Change"].ToString()
  298. }));
  299. }
  300. }
  301. break;
  302. default:
  303. {
  304. lvipayment.Items.Clear();
  305. DataTable dt = p.Load_Datas_Paid();
  306. for (int i = 0; i < dt.Rows.Count; i++)
  307. {
  308. lvipayment.Items.Add(new ListViewItem(new string[]
  309. {
  310. DateTime.Parse(dt.Rows[i]["Date"].ToString()).ToShortDateString(),
  311. dt.Rows[i]["TicketID"].ToString(),
  312. dt.Rows[i]["VehicleType"].ToString(),
  313. dt.Rows[i]["Platenumber"].ToString(),
  314. dt.Rows[i]["Timein"].ToString(),
  315. dt.Rows[i]["Timeout"].ToString(),
  316. dt.Rows[i]["HoursConsumed"].ToString(),
  317. dt.Rows[i]["TotalPayment"].ToString(),
  318. dt.Rows[i]["Cash"].ToString(),
  319. dt.Rows[i]["Change"].ToString()
  320. }));
  321. }
  322. }
  323. break;
  324. }
  325. }
  326. }
  327. }
  328. class
  329. using System;
  330. using System.Collections.Generic;
  331. using System.Linq;
  332. using System.Text;
  333. using System.Data;
  334. using System.Data.SqlClient;
  335.  
  336. namespace Parkinglotmanagementsystem
  337. {
  338. class Payments
  339. {
  340. private SqlConnection connect;
  341. private int count;
  342. private SqlCommand cmd;
  343. private SqlDataAdapter da;
  344. private DataSet ds;
  345. private DataTable dt;
  346. public Payments(SqlConnection con)
  347. {
  348. connect = con;
  349. }
  350.  
  351. public string Generate_TicketNo()
  352. {
  353. if (connect.State == ConnectionState.Closed)
  354. {
  355. connect.Open();
  356. }
  357. cmd = new SqlCommand("select count(*) from tblpayment",connect);
  358. count = (int)cmd.ExecuteScalar();
  359. connect.Close();
  360.  
  361. da = new SqlDataAdapter("select TOP 1 * from tblpayment order by TicketID desc", connect);
  362. ds = new DataSet();
  363. da.Fill(ds, "tblpayment");
  364. dt = new DataTable ();
  365. dt = ds.Tables[0];
  366. string last_id = string.Empty;
  367. for (int i = 0; i < dt.Rows.Count; i++)
  368. {
  369. last_id = dt.Rows[i]["TicketID"].ToString().Remove(0,4);
  370. }
  371. return count.Equals(0) ? "T" + DateTime.Now.Year.ToString().Substring(2, 2) + "-" +
  372. (count + 1).ToString().PadLeft(4, '0') :
  373. "T" + DateTime.Now.Year.ToString().Substring(2, 2) + "-" +
  374. (int.Parse(last_id) + 1).ToString().PadLeft(4, '0');
  375. }
  376.  
  377. public void Insert(string ticketID, string vehicleType, string plateNo,
  378. string timeIN, string timeOut, string hoursConsumed,
  379. string totalPayment, string cash, string change)
  380. {
  381. if (connect.State == ConnectionState.Closed)
  382. {
  383. connect.Open();
  384. }
  385. cmd = new SqlCommand("insert into tblpayment values(@TicketID,@VehicleType,@Platenumber,@Timein," +
  386. "@Timeout,@HoursConsumed,@TotalPayment,@Cash,@Change,@Date,'Unpaid')",connect);
  387. cmd.Parameters.AddWithValue("@TicketID", ticketID);
  388. cmd.Parameters.AddWithValue("@VehicleType", vehicleType);
  389. cmd.Parameters.AddWithValue("@Platenumber", plateNo);
  390. cmd.Parameters.AddWithValue("@Timein", timeIN);
  391. cmd.Parameters.AddWithValue("@Timeout", timeOut);
  392. cmd.Parameters.AddWithValue("@HoursConsumed", hoursConsumed);
  393. cmd.Parameters.AddWithValue("@TotalPayment", totalPayment);
  394. cmd.Parameters.AddWithValue("@Cash", cash);
  395. cmd.Parameters.AddWithValue("@Change", change);
  396. cmd.Parameters.AddWithValue("@Date", DateTime.Now);
  397. cmd.ExecuteNonQuery();
  398. connect.Close();
  399. }
  400.  
  401. public void Update(string ticketID,string timeOut, string hoursConsumed,
  402. string totalPayment, string cash, string change)
  403. {
  404. if (connect.State == ConnectionState.Closed)
  405. {
  406. connect.Open();
  407. }
  408. cmd = new SqlCommand("update tblpayment set Timeout =@Timeout, HoursConsumed = @HoursConsumed, " +
  409. "TotalPayment = @TotalPayment,Cash = @Cash,Change = @Change,Status = 'Paid' where TicketID = @TicketID", connect);//values(@TicketID
  410. cmd.Parameters.AddWithValue("@TicketID", ticketID);
  411. cmd.Parameters.AddWithValue("@Timeout", timeOut);
  412. cmd.Parameters.AddWithValue("@HoursConsumed", hoursConsumed);
  413. cmd.Parameters.AddWithValue("@TotalPayment", totalPayment);
  414. cmd.Parameters.AddWithValue("@Cash", cash);
  415. cmd.Parameters.AddWithValue("@Change", change);
  416. cmd.ExecuteNonQuery();
  417. connect.Close();
  418. }
  419.  
  420. public DataTable Load_Datas()
  421. {
  422. da = new SqlDataAdapter("select * from tblpayment where Status = 'Unpaid'",connect);
  423. ds = new DataSet();
  424. da.Fill(ds);
  425. return ds.Tables[0];
  426. }
  427.  
  428. public DataTable Load_Datas_Unpaid()
  429. {
  430. da = new SqlDataAdapter("select * from tblpayment where Status = 'Unpaid'", connect);
  431. ds = new DataSet();
  432. da.Fill(ds);
  433. return ds.Tables[0];
  434. }
  435.  
  436. public DataTable Load_Datas_Paid()
  437. {
  438. da = new SqlDataAdapter("select * from tblpayment where Status = 'Paid'", connect);
  439. ds = new DataSet();
  440. da.Fill(ds);
  441. return ds.Tables[0];
  442. }
  443.  
  444.  
  445. public DataTable Load_All_Datas()
  446. {
  447. da = new SqlDataAdapter("select * from tblpayment", connect);
  448. ds = new DataSet();
  449. da.Fill(ds);
  450. return ds.Tables[0];
  451. }
  452.  
  453. public DataTable Load_Details(string ticket_id)
  454. {
  455. if (ticket_id.Contains("'"))
  456. {
  457. ticket_id = ticket_id.Replace("'", string.Empty);
  458. }
  459. da = new SqlDataAdapter("select * from tblpayment where TicketID like '" + ticket_id + "%' or " +
  460. "VehicleType like '@id%' and Status = 'Unpaid'", connect);
  461. da.SelectCommand.Parameters.AddWithValue("@id", ticket_id);
  462. ds = new DataSet();
  463. da.Fill(ds);
  464. return ds.Tables[0];
  465. }
  466.  
  467.  
  468. public DataTable Search_Load_Details(string ticket_id)
  469. {
  470. da = new SqlDataAdapter("select * from tblpayment where TicketID = @ticket_id and Status = 'Unpaid'", connect);
  471. da.SelectCommand.Parameters.AddWithValue("@ticket_id", ticket_id);
  472. ds = new DataSet();
  473. da.Fill(ds,"tblpayment");
  474. return ds.Tables[0];
  475. }
  476. //
  477. }
  478. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement