Button7
How do I use Button7
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: Form1.cs
Copy
393 public void Button7_Click(System.Object sender, System.EventArgs e)
394 {
395 dsgrade = gradeclass.DataModule.updtedata();
396 }
File name: frmCustomerOrders.cs
Copy
28 private void Button7_Click(object sender, EventArgs e)
29 {
30 if (DataGridView3.DataSource == null)
31 {
32 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
33 return;
34 }
35 int rowsTotal = 0;
36 int colsTotal = 0;
37 int I = 0;
38 int j = 0;
39 int iC = 0;
40 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
41 Excel.Application xlApp = new Excel.Application();
42
43 try
44 {
45 Excel.Workbook excelBook = xlApp.Workbooks.Add();
46 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
47 xlApp.Visible = true;
48
49 rowsTotal = DataGridView3.RowCount;
50 colsTotal = DataGridView3.Columns.Count - 1;
51 var _with1 = excelWorksheet;
52 _with1.Cells.Select();
53 _with1.Cells.Delete();
54 for (iC = 0; iC <= colsTotal; iC++)
55 {
56 _with1.Cells[1, iC + 1].Value = DataGridView3.Columns[iC].HeaderText;
57 }
58 for (I = 0; I <= rowsTotal - 1; I++)
59 {
60 for (j = 0; j <= colsTotal; j++)
61 {
62 _with1.Cells[I + 2, j + 1].value = DataGridView3.Rows[I].Cells[j].Value;
63 }
64 }
65 _with1.Rows["1:1"].Font.FontStyle = "Bold";
66 _with1.Rows["1:1"].Font.Size = 12;
67
68 _with1.Cells.Columns.AutoFit();
69 _with1.Cells.Select();
70 _with1.Cells.EntireColumn.AutoFit();
71 _with1.Cells[1, 1].Select();
72 }
73 catch (Exception ex)
74 {
75 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
76 }
77 finally
78 {
79 //RELEASE ALLOACTED RESOURCES
80 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
81 xlApp = null;
82 }
83 }
File name: frmOrder.cs
Copy
230 private void Button7_Click(object sender, EventArgs e)
231 {
232 try
233 {
234 if (txtCustomerID.Text == "")
235 {
236 MessageBox.Show("Please retrieve Customer ID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
237 txtCustomerID.Focus();
238 return;
239 }
240
241 if (txtProductName.Text=="")
242 {
243 MessageBox.Show("Please retrieve product name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
244 return;
245 }
246 if (txtSaleQty.Text=="")
247 {
248 MessageBox.Show("Please enter no. of sale quantity", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
249 txtSaleQty.Focus();
250 return;
251 }
252 int SaleQty = Convert.ToInt32(txtSaleQty.Text);
253 if (SaleQty == 0)
254 {
255 MessageBox.Show("no. of sale quantity can not be zero", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
256 txtSaleQty.Focus();
257 return;
258 }
259
260 if (ListView1.Items.Count==0)
261 {
262
263 ListViewItem lst = new ListViewItem();
264 lst.SubItems.Add(txtProductID.Text);
265 lst.SubItems.Add(txtProductName.Text);
266 lst.SubItems.Add(txtPrice.Text);
267 lst.SubItems.Add(txtSaleQty.Text);
268 lst.SubItems.Add(txtTotalAmount.Text);
269 ListView1.Items.Add(lst);
270 txtSubTotal.Text = subtot().ToString();
271
272 Calculate();
273 txtProductName.Text = "";
274 txtProductID.Text = "";
275 txtPrice.Text = "";
276 txtAvailableQty.Text = "";
277 txtSaleQty.Text = "";
278 txtTotalAmount.Text = "";
279 txtProduct.Text = "";
280 return;
281 }
282
283 for (int j = 0; j <= ListView1.Items.Count - 1; j++)
284 {
285 if (ListView1.Items[j].SubItems[1].Text == txtProductID.Text)
286 {
287 ListView1.Items[j].SubItems[1].Text = txtProductID.Text;
288 ListView1.Items[j].SubItems[2].Text = txtProductName.Text;
289 ListView1.Items[j].SubItems[3].Text = txtPrice.Text;
290 ListView1.Items[j].SubItems[4].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[4].Text) + Convert.ToInt32(txtSaleQty.Text)).ToString();
291 ListView1.Items[j].SubItems[5].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[5].Text) + Convert.ToInt32(txtTotalAmount.Text)).ToString();
292 txtSubTotal.Text = subtot().ToString();
293 Calculate();
294 txtProductName.Text = "";
295 txtProductID.Text = "";
296 txtPrice.Text = "";
297 txtAvailableQty.Text = "";
298 txtSaleQty.Text = "";
299 txtTotalAmount.Text = "";
300 return;
301
302 }
303 }
304
305 ListViewItem lst1 = new ListViewItem();
306
307 lst1.SubItems.Add(txtProductID.Text);
308 lst1.SubItems.Add(txtProductName.Text);
309 lst1.SubItems.Add(txtPrice.Text);
310 lst1.SubItems.Add(txtSaleQty.Text);
311 lst1.SubItems.Add(txtTotalAmount.Text);
312 ListView1.Items.Add(lst1);
313 txtSubTotal.Text = subtot().ToString();
314 Calculate();
315 txtProductName.Text = "";
316 txtProductID.Text = "";
317 txtPrice.Text = "";
318 txtAvailableQty.Text = "";
319 txtSaleQty.Text = "";
320 txtTotalAmount.Text = "";
321 return;
322 }
323 catch (Exception ex)
324 {
325 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
326 }
327 }
File name: frmOrder.cs
Copy
465 private void Reset()
466 {
467 txtInvoiceNo.Text = "";
468 cmbStatus.Text = "";
469 cmbPaymentType.Text = "";
470 dtpInvoiceDate.Text = DateTime.Today.ToString();
471 txtCustomerID.Text = "";
472 txtCustomerName.Text = "";
473 txtProductName.Text = "";
474 txtProductID.Text = "";
475 txtPrice.Text = "";
476 txtAvailableQty.Text = "";
477 txtSaleQty.Text = "";
478 txtTotalAmount.Text = "";
479 ListView1.Items.Clear();
480 txtDiscountAmount.Text = "";
481 txtDiscountPer.Text = "";
482
483 txtSubTotal.Text = "";
484 txtTaxPer.Text = "";
485 txtTaxAmt.Text = "";
486 txtTotal.Text = "";
487 txtTotalPayment.Text = "";
488 txtPaymentDue.Text = "";
489 txtProduct.Text = "";
490 txtRemarks.Text = "";
491 Save.Enabled = true;
492 Delete.Enabled = false;
493 btnUpdate.Enabled = false;
494 btnRemove.Enabled = false;
495 btnPrint.Enabled = false;
496 ListView1.Enabled = true;
497 Button7.Enabled = true;
498
499 }
File name: frmPlaceOrders.cs
Copy
241 private void Button7_Click(object sender, EventArgs e)
242 {
243 try
244 {
245 if (txtCustomerID.Text == "")
246 {
247 MessageBox.Show("Please retrieve Customer ID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
248 txtCustomerID.Focus();
249 return;
250 }
251
252 if (txtProductName.Text=="")
253 {
254 MessageBox.Show("Please retrieve product name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
255 return;
256 }
257 if (txtSaleQty.Text=="")
258 {
259 MessageBox.Show("Please enter no. of buy quantity", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
260 txtSaleQty.Focus();
261 return;
262 }
263 int SaleQty = Convert.ToInt32(txtSaleQty.Text);
264 if (SaleQty == 0)
265 {
266 MessageBox.Show("no. of sale quantity can not be zero", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
267 txtSaleQty.Focus();
268 return;
269 }
270
271 if (ListView1.Items.Count==0)
272 {
273
274 ListViewItem lst = new ListViewItem();
275 lst.SubItems.Add(txtProductID.Text);
276 lst.SubItems.Add(txtProductName.Text);
277 lst.SubItems.Add(txtPrice.Text);
278 lst.SubItems.Add(txtSaleQty.Text);
279 lst.SubItems.Add(txtTotalAmount.Text);
280 ListView1.Items.Add(lst);
281 txtSubTotal.Text = subtot().ToString();
282
283 Calculate();
284 txtProductName.Text = "";
285 txtProductID.Text = "";
286 txtPrice.Text = "";
287 txtAvailableQty.Text = "";
288 txtSaleQty.Text = "";
289 txtTotalAmount.Text = "";
290 txtProduct.Text = "";
291 return;
292 }
293
294 for (int j = 0; j <= ListView1.Items.Count - 1; j++)
295 {
296 if (ListView1.Items[j].SubItems[1].Text == txtProductID.Text)
297 {
298 ListView1.Items[j].SubItems[1].Text = txtProductID.Text;
299 ListView1.Items[j].SubItems[2].Text = txtProductName.Text;
300 ListView1.Items[j].SubItems[3].Text = txtPrice.Text;
301 ListView1.Items[j].SubItems[4].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[4].Text) + Convert.ToInt32(txtSaleQty.Text)).ToString();
302 ListView1.Items[j].SubItems[5].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[5].Text) + Convert.ToInt32(txtTotalAmount.Text)).ToString();
303 txtSubTotal.Text = subtot().ToString();
304 Calculate();
305 txtProductName.Text = "";
306 txtProductID.Text = "";
307 txtPrice.Text = "";
308 txtAvailableQty.Text = "";
309 txtSaleQty.Text = "";
310 txtTotalAmount.Text = "";
311 return;
312
313 }
314 }
315
316 ListViewItem lst1 = new ListViewItem();
317
318 lst1.SubItems.Add(txtProductID.Text);
319 lst1.SubItems.Add(txtProductName.Text);
320 lst1.SubItems.Add(txtPrice.Text);
321 lst1.SubItems.Add(txtSaleQty.Text);
322 lst1.SubItems.Add(txtTotalAmount.Text);
323 ListView1.Items.Add(lst1);
324 txtSubTotal.Text = subtot().ToString();
325 Calculate();
326 txtProductName.Text = "";
327 txtProductID.Text = "";
328 txtPrice.Text = "";
329 txtAvailableQty.Text = "";
330 txtSaleQty.Text = "";
331 txtTotalAmount.Text = "";
332 return;
333 }
334 catch (Exception ex)
335 {
336 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
337 }
338 }
File name: frmPlaceOrders.cs
Copy
476 private void Reset()
477 {
478 txtInvoiceNo.Text = "";
479 cmbPaymentType.Text = "";
480 dtpInvoiceDate.Text = DateTime.Today.ToString();
481 txtCustomerID.Text = "";
482 txtCustomerName.Text = "";
483 txtProductName.Text = "";
484 txtProductID.Text = "";
485 txtPrice.Text = "";
486 txtAvailableQty.Text = "";
487 txtSaleQty.Text = "";
488 txtTotalAmount.Text = "";
489 ListView1.Items.Clear();
490 txtDiscountAmount.Text = "";
491 txtDiscountPer.Text = "";
492
493 txtSubTotal.Text = "";
494 txtTaxPer.Text = "";
495 txtTaxAmt.Text = "";
496 txtTotal.Text = "";
497 txtTotalPayment.Text = "";
498 txtPaymentDue.Text = "";
499 txtProduct.Text = "";
500 Save.Enabled = true;
501 btnRemove.Enabled = false;
502 btnPrint.Enabled = false;
503 ListView1.Enabled = true;
504 Button7.Enabled = true;
505
506 }
File name: frmSales.cs
Copy
231 private void Button7_Click(object sender, EventArgs e)
232 {
233 try
234 {
235 if (txtCustomerID.Text == "")
236 {
237 MessageBox.Show("Please retrieve Customer ID", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
238 txtCustomerID.Focus();
239 return;
240 }
241
242 if (txtProductName.Text=="")
243 {
244 MessageBox.Show("Please retrieve product name", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
245 return;
246 }
247 if (txtSaleQty.Text=="")
248 {
249 MessageBox.Show("Please enter no. of sale quantity", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
250 txtSaleQty.Focus();
251 return;
252 }
253 int SaleQty = Convert.ToInt32(txtSaleQty.Text);
254 if (SaleQty == 0)
255 {
256 MessageBox.Show("no. of sale quantity can not be zero", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
257 txtSaleQty.Focus();
258 return;
259 }
260
261 if (ListView1.Items.Count==0)
262 {
263
264 ListViewItem lst = new ListViewItem();
265 lst.SubItems.Add(txtProductID.Text);
266 lst.SubItems.Add(txtProductName.Text);
267 lst.SubItems.Add(txtPrice.Text);
268 lst.SubItems.Add(txtSaleQty.Text);
269 lst.SubItems.Add(txtTotalAmount.Text);
270 ListView1.Items.Add(lst);
271 txtSubTotal.Text = subtot().ToString();
272
273 Calculate();
274 txtProductName.Text = "";
275 txtProductID.Text = "";
276 txtPrice.Text = "";
277 txtAvailableQty.Text = "";
278 txtSaleQty.Text = "";
279 txtTotalAmount.Text = "";
280 txtProduct.Text = "";
281 return;
282 }
283
284 for (int j = 0; j <= ListView1.Items.Count - 1; j++)
285 {
286 if (ListView1.Items[j].SubItems[1].Text == txtProductID.Text)
287 {
288 ListView1.Items[j].SubItems[1].Text = txtProductID.Text;
289 ListView1.Items[j].SubItems[2].Text = txtProductName.Text;
290 ListView1.Items[j].SubItems[3].Text = txtPrice.Text;
291 ListView1.Items[j].SubItems[4].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[4].Text) + Convert.ToInt32(txtSaleQty.Text)).ToString();
292 ListView1.Items[j].SubItems[5].Text = (Convert.ToInt32(ListView1.Items[j].SubItems[5].Text) + Convert.ToInt32(txtTotalAmount.Text)).ToString();
293 txtSubTotal.Text = subtot().ToString();
294 Calculate();
295 txtProductName.Text = "";
296 txtProductID.Text = "";
297 txtPrice.Text = "";
298 txtAvailableQty.Text = "";
299 txtSaleQty.Text = "";
300 txtTotalAmount.Text = "";
301 return;
302
303 }
304 }
305
306 ListViewItem lst1 = new ListViewItem();
307
308 lst1.SubItems.Add(txtProductID.Text);
309 lst1.SubItems.Add(txtProductName.Text);
310 lst1.SubItems.Add(txtPrice.Text);
311 lst1.SubItems.Add(txtSaleQty.Text);
312 lst1.SubItems.Add(txtTotalAmount.Text);
313 ListView1.Items.Add(lst1);
314 txtSubTotal.Text = subtot().ToString();
315 Calculate();
316 txtProductName.Text = "";
317 txtProductID.Text = "";
318 txtPrice.Text = "";
319 txtAvailableQty.Text = "";
320 txtSaleQty.Text = "";
321 txtTotalAmount.Text = "";
322 return;
323 }
324 catch (Exception ex)
325 {
326 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
327 }
328 }
File name: frmSales.cs
Copy
466 private void Reset()
467 {
468 txtInvoiceNo.Text = "";
469 cmbStatus.Text = "";
470 cmbPaymentType.Text = "";
471 dtpInvoiceDate.Text = DateTime.Today.ToString();
472 txtCustomerID.Text = "";
473 txtCustomerName.Text = "";
474 txtProductName.Text = "";
475 txtProductID.Text = "";
476 txtPrice.Text = "";
477 txtAvailableQty.Text = "";
478 txtSaleQty.Text = "";
479 txtTotalAmount.Text = "";
480 ListView1.Items.Clear();
481 txtDiscountAmount.Text = "";
482 txtDiscountPer.Text = "";
483
484 txtSubTotal.Text = "";
485 txtTaxPer.Text = "";
486 txtTaxAmt.Text = "";
487 txtTotal.Text = "";
488 txtTotalPayment.Text = "";
489 txtPaymentDue.Text = "";
490 txtProduct.Text = "";
491 txtRemarks.Text = "";
492 Save.Enabled = true;
493 Delete.Enabled = false;
494 btnUpdate.Enabled = false;
495 btnRemove.Enabled = false;
496 btnPrint.Enabled = false;
497 ListView1.Enabled = true;
498 Button7.Enabled = true;
499
500 }
File name: frmSalesRecord1.cs
Copy
149 private void Button7_Click(object sender, EventArgs e)
150 {
151 if (DataGridView3.DataSource == null)
152 {
153 MessageBox.Show("Sorry nothing to export into excel sheet..", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
154 return;
155 }
156 int rowsTotal = 0;
157 int colsTotal = 0;
158 int I = 0;
159 int j = 0;
160 int iC = 0;
161 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
162 Excel.Application xlApp = new Excel.Application();
163
164 try
165 {
166 Excel.Workbook excelBook = xlApp.Workbooks.Add();
167 Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelBook.Worksheets[1];
168 xlApp.Visible = true;
169
170 rowsTotal = DataGridView3.RowCount;
171 colsTotal = DataGridView3.Columns.Count - 1;
172 var _with1 = excelWorksheet;
173 _with1.Cells.Select();
174 _with1.Cells.Delete();
175 for (iC = 0; iC <= colsTotal; iC++)
176 {
177 _with1.Cells[1, iC + 1].Value = DataGridView3.Columns[iC].HeaderText;
178 }
179 for (I = 0; I <= rowsTotal - 1; I++)
180 {
181 for (j = 0; j <= colsTotal; j++)
182 {
183 _with1.Cells[I + 2, j + 1].value = DataGridView3.Rows[I].Cells[j].Value;
184 }
185 }
186 _with1.Rows["1:1"].Font.FontStyle = "Bold";
187 _with1.Rows["1:1"].Font.Size = 12;
188
189 _with1.Cells.Columns.AutoFit();
190 _with1.Cells.Select();
191 _with1.Cells.EntireColumn.AutoFit();
192 _with1.Cells[1, 1].Select();
193 }
194 catch (Exception ex)
195 {
196 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
197 }
198 finally
199 {
200 //RELEASE ALLOACTED RESOURCES
201 System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
202 xlApp = null;
203 }
204 }
File name: frmSalesRecord1.cs
Copy
386 private void DataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
387 {
388 try
389 {
390 DataGridViewRow dr = DataGridView1.SelectedRows[0];
391 this.Hide();
392 frmSales frmSales = new frmSales();
393 // or simply use column name instead of index
394 // dr.Cells["id"].Value.ToString();
395 frmSales.Show();
396 frmSales.txtInvoiceNo.Text = dr.Cells[0].Value.ToString();
397 frmSales.dtpInvoiceDate.Text = dr.Cells[1].Value.ToString();
398 frmSales.txtCustomerID.Text = dr.Cells[2].Value.ToString();
399 frmSales.txtCustomerName.Text = dr.Cells[3].Value.ToString();
400 frmSales.txtSubTotal.Text = dr.Cells[4].Value.ToString();
401 frmSales.txtTaxPer.Text = dr.Cells[5].Value.ToString();
402 frmSales.txtTaxAmt.Text = dr.Cells[6].Value.ToString();
403 frmSales.txtDiscountPer.Text = dr.Cells[7].Value.ToString();
404 frmSales.txtDiscountAmount.Text = dr.Cells[8].Value.ToString();
405 frmSales.txtTotal.Text = dr.Cells[9].Value.ToString();
406 frmSales.txtTotalPayment.Text = dr.Cells[10].Value.ToString();
407 frmSales.txtPaymentDue.Text = dr.Cells[11].Value.ToString();
408 frmSales.cmbPaymentType .Text = dr.Cells[12].Value.ToString();
409 frmSales.cmbStatus.Text = dr.Cells[13].Value.ToString();
410 frmSales.txtRemarks.Text = dr.Cells[14].Value.ToString();
411 frmSales.btnUpdate.Enabled = true;
412 frmSales.Delete.Enabled = true;
413 frmSales.btnPrint.Enabled = true;
414 frmSales.Save.Enabled = false;
415 frmSales.lblUser.Text = lblUser.Text;
416 frmSales.lblUserType.Text = lblUserType.Text;
417 con = new SqlConnection(cs.DBConn);
418 con.Open();
419 cmd = new SqlCommand("SELECT Product.ProductID,ProductSold.Productname,ProductSold.Price,ProductSold.Quantity,ProductSold.TotalAmount from Invoice_Info,ProductSold,Product where Invoice_info.InvoiceNo=ProductSold.InvoiceNo and Product.ProductID=ProductSold.ProductID and invoice_Info.InvoiceNo='" + dr.Cells[0].Value.ToString() + "'", con);
420 rdr = cmd.ExecuteReader();
421 while (rdr.Read()==true)
422 {
423 ListViewItem lst = new ListViewItem();
424 lst.SubItems.Add(rdr[0].ToString().Trim());
425 lst.SubItems.Add(rdr[1].ToString().Trim());
426 lst.SubItems.Add(rdr[2].ToString().Trim());
427 lst.SubItems.Add(rdr[3].ToString().Trim());
428 lst.SubItems.Add(rdr[4].ToString().Trim());
429 frmSales.ListView1.Items.Add(lst);
430 }
431 frmSales.ListView1.Enabled = false;
432 frmSales.Button7.Enabled = false;
433 }
434 catch (Exception ex)
435 {
436 MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
437 }
438 }
Download file with original file name:Button7
Button7 133 lượt xem
Gõ tìm kiếm nhanh...