-
Notifications
You must be signed in to change notification settings - Fork 1
/
FrmProductExtraInfo.cs
132 lines (123 loc) · 5.63 KB
/
FrmProductExtraInfo.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
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 MySql.Data.MySqlClient;
namespace BaharNarenjERP
{
public partial class FrmProductExtraInfo : Form
{
private readonly DataTable _dt = new DataTable();
private readonly MySqlDataAdapter _da = new MySqlDataAdapter();
private readonly BindingSource _bs = new BindingSource();
private readonly string _baseQuery =
$@"SELECT pc.ConstraintName AS `آپشن`, idt.TextileCode AS `کد پارچه`, t.TextileName AS `نام پارچه` FROM invoicedetailtextile idt INNER JOIN productconstraint pc ON idt.ConstraintId=pc.ConstraintId INNER JOIN textiles t ON idt.TextileCode=t.TextileCode WHERE idt.detId={
AppProperties.SenderObject2}";
public FrmProductExtraInfo()
{
InitializeComponent();
}
private void FrmProductExtraInfo_Load(object sender, EventArgs e)
{
try
{
LblProduct.Text =
DAC.ComboBoxReturn("productName", "products", "productId", AppProperties.PrCode).ToString();
DAC.ListBoxFill("productconstraint", "ConstraintName", "ConstraintId", "ConstraintId", LstOptions,
"IsTextile=1");
DAC.ListBoxFill("textiles", "TextileName", "QualityCode", "TextileCode", LstOptionValues);
BLL.DataIfC.DataBind(DgvCurrentOptions, _dt, _da, _bs, _baseQuery);
DgvSetUp();
StLblInfo.Text = DgvCurrentOptions.Rows.Count - 1 + @" ردیف";
}
catch (Exception exception)
{
StLblInfo.Text = @"خطا در ارتباط با پایگاه داده";
BLL.LogWriter(exception.ToString());
}
}
private void button3_Click(object sender, EventArgs e)
{
Close();
}
private void DgvSetUp()
{
try
{
DgvCurrentOptions.Columns[0].ReadOnly = true;
//DgvTextile.Columns[0].Frozen = true;
DgvCurrentOptions.Columns[0].Resizable = DataGridViewTriState.False;
DgvCurrentOptions.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DgvCurrentOptions.Columns[1].ReadOnly = true;
//DgvTextile.Columns[1].Frozen = true;
DgvCurrentOptions.Columns[1].Resizable = DataGridViewTriState.True;
DgvCurrentOptions.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
//DgvTextile.Columns[1].FillWeight = 300.0f;
DgvCurrentOptions.Columns[2].ReadOnly = true;
//DgvTextile.Columns[1].Frozen = true;
DgvCurrentOptions.Columns[2].Resizable = DataGridViewTriState.True;
DgvCurrentOptions.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
finally
{
DgvCurrentOptions.AlternatingRowsDefaultCellStyle.BackColor = Color.Cornsilk;
}
}
private void TxtTxCode_TextChanged(object sender, EventArgs e)
{
try
{
DAC.ListBoxFill("textiles", "TextileName", "QualityCode", "TextileCode", LstOptionValues,
$@"textileCode LIKE '%{TxtTxCode.Text}%'");
}
catch (Exception exception)
{
StLblInfo.Text = @"خطا در ارتباط با پایگاه داده";
BLL.LogWriter(exception.ToString());
}
}
private void TxtTxName_TextChanged(object sender, EventArgs e)
{
var query = _baseQuery + $@" AND textileName LIKE '%{TxtTxName.Text}%'";
try
{
DAC.ListBoxFill("textiles", "TextileName", "QualityCode", "TextileCode", LstOptionValues,
$@"textileName LIKE '%{TxtTxName.Text}%'");
}
catch (Exception exception)
{
StLblInfo.Text = @"خطا در ارتباط با پایگاه داده";
BLL.LogWriter(exception.ToString());
}
}
private void BtnAddOp_Click(object sender, EventArgs e)
{
var q =
$@"UPDATE invoicedetailtextiles SET TextileCode='{LstOptionValues.SelectedValue}' WHERE detId={
AppProperties.SenderObject2} AND ConstraintId={LstOptions.SelectedValue};";
if (DAC.ExecuteSql(q))
{
BLL.DataIfC.DataBind(DgvCurrentOptions, _dt, _da, _bs, _baseQuery);
DgvSetUp();
StLblInfo.Text = DgvCurrentOptions.Rows.Count - 1 + @" ردیف";
}
else
{
q =
$@"SELECT detTxtlId FROM invoicedetailtextiles WHERE detId={AppProperties.SenderObject2
} AND ConstraintId={LstOptions.SelectedValue}";
var connection = new MySqlConnection(DAC.CsBuilder.ConnectionString);
connection.Open();
var cmd = connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = q;
BLL.LogWriter($@"به روز رسانی جزئیات پارچه برای idt={cmd.ExecuteScalar().ToString()} با اشکال مواجه شد.");
}
}
}
}