-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmStockIn.cs
145 lines (126 loc) · 5.17 KB
/
frmStockIn.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
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;
using System.Data.SqlClient;
namespace pos_and_inventory_csharp
{
public partial class frmStockIn : Form
{
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
DBConnection dbcon = new DBConnection();
SqlDataReader dr;
public frmStockIn()
{
InitializeComponent();
cn = new SqlConnection(dbcon.MyConnection());
}
private void pictureBox1_Click(object sender, EventArgs e)
{
this.Dispose();
}
private void LoadStockInHistory()
{
int i = 0;
dataGridView1.Rows.Clear();
cn.Open();
cm = new SqlCommand("select * from vwStockin where cast(sdate as date) between '" + date1.Value.ToShortDateString() + "' and '" + date2.Value.ToShortDateString() + "' and status like 'Done' ", cn);
dr = cm.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add(i, dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), DateTime.Parse(dr[5].ToString()).ToShortDateString(), dr[6].ToString());
}
dr.Close();
//cn.Close();
}
public void Clear()
{
txtBy.Clear();
txtRefNo.Clear();
dt1.Value = DateTime.Now;
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string colName = dataGridView2.Columns[e.ColumnIndex].Name;
if (colName == "colDelete")
{
if (MessageBox.Show("Remove this item? ", "Remove Item", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
cn.Open();
cm = new SqlCommand("delete from tblstockin where id = '" + dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString() + "'" , cn);
cm.ExecuteNonQuery();
cn.Close();
MessageBox.Show("Item has been Successfully Removed.", "Removed Item", MessageBoxButtons.OK, MessageBoxIcon.Information);
LoadStockIn();
}
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
public void LoadStockIn()
{
int i = 0;
dataGridView2.Rows.Clear();
cn.Open();
cm = new SqlCommand("select * from vwStockin where refno like '" + txtRefNo.Text + "' and status like 'Pending' ", cn);
dr = cm.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView2.Rows.Add(i , dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString(), dr[6].ToString());
}
dr.Close();
cn.Close();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
frmSearchProductStockin frm = new frmSearchProductStockin(this);
frm.LoadProduct();
frm.ShowDialog();
}
private void btnSave_Click(object sender, EventArgs e)
{
try
{
if (dataGridView2.Rows.Count > 0)
{
if (MessageBox.Show("Are you sure you want to save this records?", "Save Records", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
for (int i = -0; i < dataGridView2.Rows.Count; i++)
{
// update tblproduct qty
cn.Open();
cm = new SqlCommand("update tblproduct set qty = qty + " + int.Parse(dataGridView2.Rows[i].Cells[5].Value.ToString()) + " where pcdoe like '" + dataGridView2.Rows[i].Cells[3].Value.ToString() + "'", cn);
cm.ExecuteNonQuery();
cn.Close();
// update tblstockin qty
cn.Open();
cm = new SqlCommand("update tblstockin set qty = qty + " + int.Parse(dataGridView2.Rows[i].Cells[5].Value.ToString()) + ", status = 'Done' where id like '" + dataGridView2.Rows[i].Cells[1].Value.ToString() + "'", cn);
cm.ExecuteNonQuery();
cn.Close();
}
Clear();
LoadStockIn();
}
}
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private void btnLoad_Click(object sender, EventArgs e)
{
LoadStockInHistory();
}
}
}