-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplanning.aspx.cs
executable file
·234 lines (221 loc) · 9.63 KB
/
planning.aspx.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
public partial class planning : System.Web.UI.Page
{
static SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["automationConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (Session["inp"] == null) Response.Redirect("inputLogin.aspx");
if (Request.QueryString["mid"] == null) Response.Redirect("assembly.aspx");
lblmid.Text = Request.QueryString["mid"].ToString();
DataView dvplan = (DataView)(sdsplan.Select(DataSourceSelectArguments.Empty));
DataView dvphase = (DataView)(sdsphase.Select(DataSourceSelectArguments.Empty));
dvphase.Sort = "phaseORDER";
int x;
for (int i = 0; i < dvplan.Table.Rows.Count; i++)
{
string coll = dvplan.Table.Rows[i]["date"].ToString();
string[] collarr = coll.Split(',');
x = 0;
foreach (string c in collarr)
{
TableRow tr = new TableRow();
tblplanning.Rows.Add(tr);
TableCell c1 = new TableCell();
tr.Cells.Add(c1);
TableCell c2 = new TableCell();
tr.Cells.Add(c2);
if (x == 0)
{
c1.Text = dvphase.Table.Rows[dvphase.Find(dvplan.Table.Rows[i]["phase"])]["phaseNAME"].ToString();
c2.Text = dvphase.Table.Rows[dvphase.Find(dvplan.Table.Rows[i]["phase"])]["phaseDURATION"].ToString();
x = 1;
}
TableCell c3 = new TableCell();
tr.Cells.Add(c3);
c3.Text = c;
TableCell c4 = new TableCell();
tr.Cells.Add(c4);
Button bdel = new Button();
bdel.Text = "REMOVE";
bdel.ID = dvplan.Table.Rows[i]["phase"].ToString() + "," + c;
bdel.Click += Bdel_Click;
bdel.CausesValidation = false;
c4.Controls.Add(bdel);
}
}
}
private void Bdel_Click(object sender, EventArgs e)
{
// throw new NotImplementedException();
DataView dvplan = (DataView)(sdsplan.Select(DataSourceSelectArguments.Empty));
dvplan.Sort = "phase";
Button but = (Button)sender;
string []parts = but.ID.ToString().Split(',');
string phase = parts[0];
string date = parts[1];
List<string> licoll=new List<string>();
licoll.AddRange(dvplan.Table.Rows[dvplan.Find(phase)]["date"].ToString().Split(','));
if (licoll.Contains(date)) licoll.Remove(date);
string rebuilt = string.Join(",", licoll);
con.Open();
SqlCommand cmd = new SqlCommand("update [plan] set date=@reb,job=@job,phase=@phase where job=@job and phase=@phase",con);
cmd.Parameters.AddWithValue("@reb",rebuilt);
cmd.Parameters.AddWithValue("@job",Request.QueryString["jid"].ToString());
cmd.Parameters.AddWithValue("@phase",phase);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("planning.aspx?jid=" + Request.QueryString["jid"].ToString() + "&mid=" + Request.QueryString["mid"].ToString());
}
protected void addduration_Click(object sender, EventArgs e)
{
DataView dvplan = (DataView)(sdsplan.Select(DataSourceSelectArguments.Empty));
dvplan.Sort = "phase";
DateTime init = Convert.ToDateTime(tbstrt.Text);
DateTime last = Convert.ToDateTime(tbend.Text);
if (last >= init)
{
List<DateTime> li = new List<DateTime>();
for (DateTime i = init; i <= last; i = i.AddDays(1))
{
li.Add(i);
}
string[] ex = dvplan.Table.Rows[dvplan.Find(ddlop.SelectedValue)]["date"].ToString().Split(',');
if (dvplan.Table.Rows[dvplan.Find(ddlop.SelectedValue)]["date"].ToString() != "")
{
foreach (string ee in ex)
{
DateTime eee = Convert.ToDateTime(ee);
if (!li.Contains(eee)) li.Add(eee);
}
}
li.Sort();
List<string> dates = new List<string>();
foreach (DateTime item in li)
{
dates.Add(item.ToShortDateString());
}
string rebuilt = string.Join(",", dates);
con.Open();
SqlCommand cmd = new SqlCommand("update [plan] set date=@reb where job=@j and phase=@p", con);
cmd.Parameters.AddWithValue("@reb", rebuilt);
cmd.Parameters.AddWithValue("@j", Request.QueryString["jid"].ToString());
cmd.Parameters.AddWithValue("@p", ddlop.SelectedValue);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("planning.aspx?jid=" + Request.QueryString["jid"].ToString() + "&mid=" + Request.QueryString["mid"].ToString());
}
}
protected void resetduration_Click(object sender, EventArgs e)
{
DataView dvplan = (DataView)(sdsplan.Select(DataSourceSelectArguments.Empty));
dvplan.Sort = "phase";
DateTime init = Convert.ToDateTime(tbstrt.Text);
DateTime last = Convert.ToDateTime(tbend.Text);
if (last >= init)
{
List<DateTime> li = new List<DateTime>();
for (DateTime i = init; i <= last; i = i.AddDays(1))
{
li.Add(i);
}
li.Sort();
List<string> dates = new List<string>();
foreach (DateTime item in li)
{
dates.Add(item.ToShortDateString());
}
string rebuilt = string.Join(",", dates);
con.Open();
SqlCommand cmd = new SqlCommand("update [plan] set date=@reb where job=@j and phase=@p", con);
cmd.Parameters.AddWithValue("@reb", rebuilt);
cmd.Parameters.AddWithValue("@j", Request.QueryString["jid"].ToString());
cmd.Parameters.AddWithValue("@p", ddlop.SelectedValue);
cmd.ExecuteNonQuery();
con.Close();
Response.Redirect("planning.aspx?jid=" + Request.QueryString["jid"].ToString() + "&mid=" + Request.QueryString["mid"].ToString());
}
}
protected void gotoinput_Click(object sender, EventArgs e)
{
Response.Redirect("inputmap.aspx?mid="+Request.QueryString["mid"].ToString());
}
protected void gotoprogress_Click(object sender, EventArgs e)
{
Session["bu"] = "planning.aspx?mid=" + Request.QueryString["mid"].ToString() + "&jid=" + Request.QueryString["jid"].ToString();
Response.Redirect("jobprogress.aspx?jid="+Request.QueryString["jid"].ToString()+"&mid="+Request.QueryString["mid"].ToString());
}
protected void adjust_Click(object sender, EventArgs e)
{
List<DateTime> li = new List<DateTime>();
DataView dvplan = (DataView)(sdsplan.Select(DataSourceSelectArguments.Empty));
dvplan.Sort = "phase";
for (int i = 0; i < dvplan.Table.Rows.Count; i++)
{
string[] datarr = dvplan.Table.Rows[i]["date"].ToString().Split(',');
if (dvplan.Table.Rows[i]["date"].ToString() != "")
{
foreach (string s in datarr)
{
if (!li.Contains(Convert.ToDateTime(s))) li.Add(Convert.ToDateTime(s));
}
}
}
li.Sort();
int count = li.Count;
List<DateTime> wd = new List<DateTime>();
int p = 0;
DateTime dt = li[0];
while(p<=count)
{
if(isworkingday(dt)==1)
{
wd.Add(dt);
p++;
}
dt = dt.AddDays(1);
}
for (int i = 0; i < dvplan.Table.Rows.Count; i++)
{
string[] datarr = dvplan.Table.Rows[i]["date"].ToString().Split(',');
List<string> reb = new List<string>();
if (dvplan.Table.Rows[i]["date"].ToString() != "")
{
foreach (string s in datarr)
{
int index = li.IndexOf(Convert.ToDateTime(s));
reb.Add(wd[index].ToShortDateString());
}
}
string rebuilt = string.Join(",", reb);
con.Open();
SqlCommand cmd = new SqlCommand("update [plan] set date=@reb where job=@j and phase=@p", con);
cmd.Parameters.AddWithValue("@reb", rebuilt);
cmd.Parameters.AddWithValue("@j", Request.QueryString["jid"].ToString());
cmd.Parameters.AddWithValue("@p", dvplan.Table.Rows[i]["phase"].ToString());
cmd.ExecuteNonQuery();
con.Close();
}
Response.Redirect("planning.aspx?jid=" + Request.QueryString["jid"].ToString() + "&mid=" + Request.QueryString["mid"].ToString());
}
public int isworkingday(DateTime dt)
{
DataView dvhol = (DataView)(sdsholi.Select(DataSourceSelectArguments.Empty));
DataView dvmhol = (DataView)(sdsmonholi.Select(DataSourceSelectArguments.Empty));
dvhol.Sort = "holidayDATE";
dvmhol.Sort = "holiday";
if (dvhol.Find(dt) < 0) return 1;
else
{
if (dvmhol.Find(dt) >= 0) return 1;
else return 0;
}
}
}