-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrmCreateMachine.cs
More file actions
154 lines (135 loc) · 4.72 KB
/
Copy pathFrmCreateMachine.cs
File metadata and controls
154 lines (135 loc) · 4.72 KB
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
146
147
148
149
150
151
152
153
154
using DSI_CRM.Models;
using DSI_CRM.Service;
using DSI_CRM.Services;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace DSI_CRM
{
public partial class FrmCreateMachine : Form
{
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int HT_CAPTION = 0x2;
[DllImportAttribute("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
[DllImportAttribute("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect, // x-coordinate of upper-left corner
int nTopRect, // y-coordinate of upper-left corner
int nRightRect, // x-coordinate of lower-right corner
int nBottomRect, // y-coordinate of lower-right corner
int nWidthEllipse, // height of ellipse
int nHeightEllipse // width of ellipse
);
public string Return_Value { get; set; }
public FrmCreateMachine()
{
InitializeComponent();
Init_Page();
Return_Value = null;
}
private void Init_Page()
{
FormBorderStyle = FormBorderStyle.None;
Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 20, 20));
if (DataStore.Get_Theme_CONFIG())
{
Top_Pn.BackColor = DataStore.Get_CONFIG_Theme_Color();
}
Top_Pn.MouseDown += Mouse_Down;
Machine_Dg.CellDoubleClick += Machine_Dg_CellDoubleClick;
}
private void Machine_Dg_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
Return_Value = Machine_Dg.Rows[e.RowIndex].Cells[0].Value.ToString();
if (string.IsNullOrEmpty(Return_Value))
{
Close();
}
}
private void Mouse_Down(object sender, System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ReleaseCapture();
SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
}
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
Continue_Bt.Visible = false;
Indicator_Pn.Visible = false;
Machine_Dg.Visible = false;
Size = new Size(705, 171);
Refresh();
}
private bool Validate_Fields()
{
if (string.IsNullOrEmpty(Item_Number_Tb.Text))
{
return false;
}
else if (Item_Number_Tb.Text.Contains("="))
{
Process.Display_Alert("Item_Number contains an illegal character", false);
return false;
}
else if (string.IsNullOrEmpty(Description_Tb.Text))
{
return false;
}
else
{
return true;
}
}
private void Create_Bt_Click(object sender, EventArgs e)
{
if (Validate_Fields())
{
DataStore.Retrieve_Machines_Dup(Item_Number_Tb.Text, Description_Tb.Text);
Draw_Machines_Dup();
Continue_Bt.Visible = true;
Indicator_Pn.Visible = true;
Machine_Dg.Visible = true;
Size = new Size(705, 430);
Refresh();
}
}
private void Draw_Machines_Dup()
{
Machine_Dg.Rows.Clear();
foreach (MachineDup m in DataStore.Get_Machine_Dup())
{
Machine_Dg.Rows.Add(m.Item_Number, m.Description);
}
}
private void Continue_Bt_Click(object sender, EventArgs e)
{
try
{
Return_Value = DataStore.Create_Machine_REST(Item_Number_Tb.Text);
Machine m = new Machine()
{
Machine_Number = (int)long.Parse(Return_Value),
Description = Description_Tb.Text
};
DataStore.Update_Machine_REST(m);
}
catch (Exception ex)
{
Process.Display_Alert(ex.Message, false);
Close();
}
}
private void Close_Bt_Click(object sender, EventArgs e)
{
Close();
}
}
}