-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmProduct_New.cs
111 lines (95 loc) · 3.42 KB
/
frmProduct_New.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace GSTBilling
{
public partial class frmProduct_New : Form
{
Product productData;
OperationType opertationType;
public frmProduct_New(Product _productData = null)
{
InitializeComponent();
productData = _productData;
opertationType = OperationType.Edit;
if (_productData == null)
{
productData = new Product();
opertationType = OperationType.New;
}
}
private void frmProduct_New_Load(object sender, EventArgs e)
{
setAutoSuggestControl();
if (opertationType == OperationType.Edit)
{
LoadOldData();
}
}
public void setAutoSuggestControl()
{
txtCategoryName.SuggestCustomSource(ProductImplementation.Suggest_ProudctCategory());
txtProductName.SuggestCustomSource(ProductImplementation.Suggest_ProudctName());
}
public void LoadOldData()
{
dtpEntryDate.Value = productData.EntryDate;
txtCategoryName.Text = productData.CategoryName;
txtProductName.Text = productData.ProductName;
txtUnit.Text = productData.Unit;
txtHsnCode.Text = productData.HsnCode;
txtPurchaseRate.Value = (decimal)productData.PurchaseRate;
txtSalesRate.Value = (decimal)productData.SalesRate;
txtRemarks.Text = productData.Remarks;
}
private void btnSave_Click(object sender, EventArgs e)
{
// Get Data From Controls
productData.EntryDate = dtpEntryDate.Value;
productData.CategoryName = txtCategoryName.GetString();
productData.ProductName = txtProductName.GetString();
productData.Unit = txtUnit.GetString();
productData.HsnCode = txtHsnCode.GetString();
productData.PurchaseRate = txtPurchaseRate.GetDouble();
productData.SalesRate = txtSalesRate.GetDouble();
productData.Remarks = txtRemarks.GetString();
// Save
var resultValidation = productData.Save();
if (resultValidation.IsValid == false)
{
resultValidation.getError().ShowError();
return;
}
"Product Saved.".ShowInformation();
this.Close();
}
private void btnCancle_Click(object sender, EventArgs e)
{
this.Close();
}
private void txtProductName_Leave(object sender, EventArgs e)
{
if (txtProductName.GetString().Length == 0)
{
return;
}
if (ProductImplementation.FindByProductName(txtProductName.GetString(), productData.Id) != null)
{
"Duplicate Product Name!".ShowInformation();
txtProductName.Text = "";
txtProductName.Focus();
}
}
private void frmProduct_New_Enter(object sender, EventArgs e)
{
NumericUpDown control = sender as NumericUpDown;
control.Select(0, control.Text.Length);
}
}
}