private void ShowGrid(string PauseReason) { string wherestrr = "1=1"; if (cmbReceiver.Text != "--全部--" && cmbReceiver.Text != string.Empty) { wherestrr = " Receiver='" + cmbReceiver.Text + "'"; } string sqlstring = "Select * from Booking Where " + wherestrr + " And (State='正式' Or State='延时到明天' OR StartServiceTime between '" + DateTime.Today.ToString() + "' and '" + DateTime.Today.AddDays(1).ToShortDateString() + "')"; sqlstring += " Union all Select * from Booking Where " + wherestrr + " And (State='维修进行中' Or State='中断' Or State='过时') And StartServiceTime between '" + DateTime.Today.AddDays(-7).ToShortDateString() + "' and '" + DateTime.Today.ToShortDateString() + "'"; sqlstring += " Union all Select * from Booking Where " + wherestrr + " And State='完工' And EndServiceTime between '" + DateTime.Today.AddDays(-1).ToShortDateString() + "' and '" + DateTime.Today.ToShortDateString() + "'"; DataTable RoDt1 = SQLDbHelper.Query(sqlstring).Tables[0]; RoDt1.DefaultView.Sort = "StartServiceTime Desc"; RoDt = RoDt1.DefaultView.Table; foreach (DataRow Dr in RoDt.Rows) { string time = string.Empty; switch (Dr["State"].ToString()) { case "正式": case "延时到明天": Colindex = 0; time = Dr["ComeTime"].ToString(); break; case "维修进行中": case "过时": Colindex = 1; time = Dr["StartServiceTime"].ToString(); break; case "中断": Colindex = 2; time = ClsBLL.PauseTime(int.Parse(Dr["ID"].ToString())).ToString(); break; case "完工": Colindex = 3; time = Dr["EndServiceTime"].ToString(); break; case "洗车": Colindex = 4; time = Dr["ClearCarTime"].ToString(); break; default: break; } try { string Time = string.Empty; string Spantime = string.Empty; if (time == string.Empty && Colindex != 4) { time = DateTime.Now.ToString(); } if (time != string.Empty) { TimeSpan ts = DateTime.Now.Subtract(DateTime.Parse(time)); Spantime = ts.Hours.ToString() + "°" + ts.Minutes.ToString() + "'"; Time = DateTime.Parse(time).ToString("MM-dd HH:mm"); } //在等待列判断中断原因,不显示等待时间 if (Dr["State"].ToString() == "正式" || Dr["State"].ToString() == "延时到明天") { string delayreason = ClsBLL.DelayReason(int.Parse(Dr["ID"].ToString())); if (delayreason != string.Empty) { Spantime = delayreason; } } //列序号,状态,车牌,维修类型,(进场时间/开始工作时间/中断时间/完工时间/洗车时间),时间差,停车位,计划完成时间 string info = Colindex.ToString() + "," + Dr["State"].ToString() + "," + Dr["CarNo"].ToString() + "," + Dr["ServiceType"].ToString() + "," + Time + "," + Spantime + "," + Dr["ParkSite"].ToString() + "," + Dr["PlanOutTime"].ToString() + "," + Dr["Receiver"].ToString() + "," + Dr["Worker"].ToString() + "," + Dr["Remark"].ToString(); if (Dr["State"].ToString() == "正式" || Dr["State"].ToString() == "延时到明天") { if (PauseReason != string.Empty && PauseReason != Spantime) { } else { AddCarCard(Dr["ID"].ToString(), info); } } else { if (Dr["State"].ToString() == "中断" && PauseReason != string.Empty) { if (ClsBLL.PauseReason(int.Parse(Dr["ID"].ToString())) == PauseReason) { AddCarCard(Dr["ID"].ToString(), info); } } else { AddCarCard(Dr["ID"].ToString(), info); } } } catch (Exception Err) { MessageBox.Show(Err.Message); } } for (int i = 0; i < dataGridView1.Columns.Count; i++) { if (dataGridView1.Columns[i].HeaderText.IndexOf("[") > 0) { string header = dataGridView1.Columns[i].HeaderText; header = header.Substring(0, header.IndexOf("[")); dataGridView1.Columns[i].HeaderText = header + "[" + Cards[i].ToString() + "]"; } else { dataGridView1.Columns[i].HeaderText = dataGridView1.Columns[i].HeaderText + "[" + Cards[i].ToString() + "]"; } } dataGridView1.ClearSelection(); }
//添加车辆预约卡片 private void AddCarCard(string ID, string info, int rowindex) { DoubleClickButton bt = new DoubleClickButton(); string[] strs = info.Split(new Char[] { ',' }); string startdate = strs[4]; decimal hours = decimal.Parse(strs[3]); string plancomdate = strs[5];//计划完成时间 DateTime PlanEndDate = DateTime.Now; if (plancomdate != string.Empty) { PlanEndDate = DateTime.Parse(plancomdate); } else { PlanEndDate = DateTime.Parse(startdate).AddMinutes(double.Parse(Convert.ToString(hours * 60 + ClsBLL.Pausemins(int.Parse(ID), DateTime.Parse(startdate))))); } if (strs[0] == "中断") //如果是中断,则停在做中断操作时的时间点,否则停在按计算计划完成的时间点上 { PlanEndDate = ClsBLL.PauseTime(int.Parse(ID)); } TimeSpan DtSp = PlanEndDate.Subtract(starttime); //计划完成时间和开始时间或计划开始时间的差 int hour = DtSp.Hours; //如果超出了时间范围,显示在最后一列 if (hour > dataGridView1.ColumnCount - 3) { hour = dataGridView1.ColumnCount - 3; } if (hour < 0) { hour = 0; } bt.AccessibleDescription = hour.ToString(); bt.TabIndex = rowindex; Cards[rowindex, hour] = Cards[rowindex, hour] + 1; decimal left = dataGridView1.Columns[0].Width + dataGridView1.Columns[1].Width + dataGridView1.Columns[2].Width * hour; bt.Left = int.Parse(Convert.ToString(Math.Round(left, 0))); int top = rowindex * dataGridView1.Rows[0].Height + dataGridView1.ColumnHeadersHeight + 3; bt.Height = dataGridView1.Rows[0].Height - 6; bt.Width = dataGridView1.Columns[2].Width; bt.Top = top; bt.Tag = strs[0]; //状态 bt.Name = ID; bt.ImageKey = info; dataGridView1.Controls.Add(bt); string planout = strs[7]; if (planout != string.Empty) { planout = DateTime.Parse(planout).ToString("MM-dd HH:mm"); } bt.Text = strs[1] + "\n" + planout; if (strs[8].IndexOf("分单") > -1) { string fendan = string.Empty; if (strs[8].Length > strs[8].IndexOf("分单") + 2) { fendan = strs[8].Substring(strs[8].IndexOf("分单") + 2, 1); if (!ClsBLL.IsNumber(fendan)) { fendan = string.Empty; } } if (fendan == string.Empty) { bt.Text = strs[1] + " 合\n" + planout; } else { bt.Text = strs[1] + " 合" + fendan + "\n" + planout; } } bt.Font = new Font("宋体", 11, FontStyle.Regular); ToolTip tt = new ToolTip(); tt.SetToolTip(bt, strs[strs.Length - 1]); Color cl = Color.PowderBlue; //"正式","已派工", "维修进行中", "中断", "完工", "洗车","过时","延时到明天" if (strs[0] == States[2]) { cl = Color.Green; if (strs[8].IndexOf("返修") > -1) { cl = Color.MediumSeaGreen; } if (strs[8].IndexOf("追加项目") > -1) { cl = Color.OliveDrab; } } if (strs[0] == States[3]) { cl = Color.LightGray; } if (strs[0] == States[4]) { cl = Color.Blue; } if (strs[0] == States[5]) { cl = Color.MediumOrchid; } if (strs[0] == States[6]) { cl = Color.Red; } if (strs[0] == States[7]) { cl = Color.Orange; } bt.BackColor = cl; bt.ContextMenuStrip = contextMenuStrip2; bt.MouseDown += new MouseEventHandler(bt_MouseDown); bt.MouseMove += new MouseEventHandler(bt_MouseMove); bt.MouseUp += new MouseEventHandler(bt_MouseUp); bt.DoubleClick += new EventHandler(bt_DoubleClick); //ChangeWidth(rowindex,hour,bt); }