Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using BookShop.Forms;
  11. using BookShop.Data;
  12. using System.Drawing.Drawing2D;
  13.  
  14. namespace BookShop.UserControls
  15. {
  16. public partial class UC_Sales : UserControl
  17. {
  18. private Business bs = new Business();
  19. book book = new book();
  20. public static float amount = 0;
  21.  
  22. public UC_Sales()
  23. {
  24. InitializeComponent();
  25. }
  26.  
  27. private void panel5_Paint(object sender, PaintEventArgs e)
  28. {
  29.  
  30. }
  31.  
  32. private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  33. {
  34.  
  35. }
  36.  
  37. private void button7_Click(object sender, EventArgs e)
  38. {
  39. if (listView1.Items.Count == 0)
  40. {
  41. MessageBox.Show("Add books to cart please!");
  42. }
  43. else
  44. {
  45. using (Form_FinishOrder uf = new Form_FinishOrder())
  46. {
  47. uf.ShowDialog();
  48. }
  49. }
  50.  
  51.  
  52. }
  53.  
  54. private void button8_Click(object sender, EventArgs e)
  55. {
  56. if (string.IsNullOrWhiteSpace(textBox1.Text))
  57. {
  58. MessageBox.Show("Barcode can't be null or whitespace");
  59. return;
  60. }
  61.  
  62. int parsedValue;
  63. if (!int.TryParse(textBox1.Text, out parsedValue))
  64. {
  65. MessageBox.Show("This is a number only field");
  66. return;
  67. }
  68.  
  69. int barcodeText = int.Parse(textBox1.Text);
  70.  
  71. button1.Enabled = false;
  72. if (barcodeText > 0 && barcodeText <= bs.GetAllBarcodesCount())
  73. {
  74. book = bs.GetBookByBarcode(int.Parse(textBox1.Text));
  75. textBox2.Text = book.Book1;
  76. textBox3.Text = book.Author;
  77. textBox4.Text = book.Price.ToString("N2");
  78. textBox5.Text = book.Publisher;
  79. button1.Enabled = true;
  80. }
  81.  
  82. else
  83. {
  84. MessageBox.Show("Barcode is invalid, try another one.");
  85. }
  86. }
  87.  
  88. private void button1_Click(object sender, EventArgs e)
  89. {
  90. if (string.IsNullOrWhiteSpace(textBox1.Text))
  91. {
  92. MessageBox.Show("Firstly type barcode.");
  93. button1.Enabled = false;
  94. }
  95.  
  96. else
  97. {
  98.  
  99. string[] row = { textBox2.Text, "1", textBox4.Text };
  100. var listViewItem = new ListViewItem(row);
  101. if (listView1.FindItemWithText(textBox2.Text) != null)
  102. {
  103. amount = 0;
  104. listView1.FindItemWithText(textBox2.Text).SubItems[1].Text = int.Parse(listView1.FindItemWithText(textBox2.Text).SubItems[1].Text) + 1 + "";
  105. CalculateAmount();
  106. }
  107. else
  108. {
  109. listView1.Items.Add(listViewItem);
  110. CalculateAmount();
  111. }
  112. }
  113. }
  114.  
  115. private void UC_Sales_Load(object sender, EventArgs e)
  116. {
  117. listView1.FullRowSelect = true;
  118. amount = 0;
  119. }
  120.  
  121. private void textBox1_TextChanged(object sender, EventArgs e)
  122. {
  123. textBox2.Clear();
  124. textBox3.Clear();
  125. textBox4.Clear();
  126. textBox5.Clear();
  127. button1.Enabled = false;
  128. }
  129.  
  130. private void button3_Click(object sender, EventArgs e)
  131. {
  132. if (listView1.SelectedItems.Count > 0)
  133. {
  134. ListViewItem item = listView1.SelectedItems[0];
  135. amount = 0;
  136. item.SubItems[1].Text = int.Parse(item.SubItems[1].Text) + 1 + "";
  137. CalculateAmount();
  138. }
  139. else
  140. {
  141. MessageBox.Show("Select row...");
  142. }
  143.  
  144. }
  145. private void button2_Click(object sender, EventArgs e)
  146. {
  147. if (listView1.SelectedItems.Count > 0)
  148. {
  149. ListViewItem item = listView1.SelectedItems[0];
  150. amount = 0;
  151.  
  152. if(int.Parse(item.SubItems[1].Text) > 1) { item.SubItems[1].Text = int.Parse(item.SubItems[1].Text) - 1 + ""; CalculateAmount(); }//PETUK
  153. else
  154. {
  155. MessageBox.Show("Amount can't be less than 1");
  156. item.SubItems[1].Text = 1 + "";
  157. }
  158. }
  159. else
  160. {
  161. MessageBox.Show("Select row...");
  162. }
  163. }
  164.  
  165. private void button4_Click(object sender, EventArgs e)
  166. {
  167. if (listView1.SelectedItems.Count > 0)
  168. {
  169. ListViewItem item = listView1.SelectedItems[0];
  170. item.Remove();
  171. label3.Text = "0.00 $";
  172. }
  173. else
  174. {
  175. MessageBox.Show("Select row...");
  176. }
  177. }
  178.  
  179. private void button6_Click(object sender, EventArgs e)
  180. {
  181. DialogResult result = MessageBox.Show("Your cart will be lost", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Error);
  182. if (result == DialogResult.Yes)
  183. {
  184. listView1.Items.Clear();
  185. }
  186. else if(result == DialogResult.No)
  187. {
  188. return;
  189. }
  190. else
  191. {
  192. return;
  193. }
  194.  
  195. }
  196.  
  197. public void CalculateAmount()
  198. {
  199.  
  200. for (int i = 0; i < listView1.Items.Count; i++)
  201. {
  202. amount += float.Parse(listView1.Items[i].SubItems[2].Text) * float.Parse(listView1.Items[i].SubItems[1].Text);
  203.  
  204. }
  205. label3.Text = amount.ToString("N2") + " $";
  206.  
  207. }
  208. public float amountValue
  209. {
  210. get
  211. {
  212. return amount;
  213. }
  214. }
  215. }
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement