using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using GeoScene.Data; using GeoScene.Engine; using GeoScene.Globe; using DevComponents.DotNetBar; using System.Data.OracleClient; namespace Cyberpipe.EMS_Forms { public partial class Form_TaksManager : Office2007Form { GSOGlobeControl globeControl1; DataTable dt; OracleConnection conn; private int currentpage = 1; private int lastpage = 1; private int pagesize = 11; public static bool IS_OPEN = false; public Form_TaksManager(GSOGlobeControl globeControl1) { this.globeControl1 = globeControl1; globeControl1.Globe.MemoryLayer.ObjectMinVisiblePixelSize = -1; InitializeComponent(); } private void button_new_Click(object sender, EventArgs e) { EMS_Forms.Form_EditTask form = new Form_EditTask(globeControl1); form.Show(); this.Close(); } private void Form_TaksManager_Load(object sender, EventArgs e) { try { this.dateTimePicker_end.Value = DateTime.Now; reloadGrid(currentpage); conn = OledbHelper.sqlConnection(); string sql = "select t.username from patroler t"; DataTable dt = OracleUtils.ExecuteDataset(OracleUtils.ConnectionString, CommandType.Text, sql).Tables[0]; foreach(DataRow row in dt.Rows){ comboBox_userName.Items.Add(row[0].ToString()); } sql = "select distinct 所属道路 from 标识器"; using (OracleDataReader reader = OracleUtils.ExecuteReader(OracleUtils.ConnectionString, CommandType.Text, sql)) { combo_street.Items.Add(""); while (reader.Read()) { combo_street.Items.Add(reader[0].ToString()); } } if (Utility.userRole.IndexOf("工单创建") == -1) { button_new.Visible = false; } IS_OPEN = true; } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } private void Form_TaksManager_FormClosing(object sender, FormClosingEventArgs e) { globeControl1.Globe.MemoryLayer.RemoveAllFeature(); IS_OPEN = false; } private void showThisForm() { this.Show(); } private void dataGridViewX1_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex != -1 && e.ColumnIndex != -1) { if (dataGridViewX_Task.Columns[e.ColumnIndex].HeaderText == "任务信息") { try { int dbID = 0; dbID = Convert.ToInt32(dataGridViewX_Task.Rows[e.RowIndex].Cells["任务编号"].Value); string sql = "select dbid," + " checktime," + " mark_id," + " task_id," + " case is_checked" + " when 0 then" + " '未定位'" + " when 1 then" + " '已定位'" + " else" + " '未知'" + " end as is_checked" + " from MARK_TASK where task_id='" + dbID + "' order by dbid"; DataTable taskInfoDt = new DataTable(); taskInfoDt = OledbHelper.ExecuteDataTable(sql); if (taskInfoDt.Rows.Count == 0) { MessageBox.Show("没有相应详细任务信息!", "提示"); return; } else { this.Hide(); flyToTask(e.RowIndex); EMS_Forms.Form_TaskInfo p = new Form_TaskInfo(globeControl1,taskInfoDt); p.showParentForm += new Form_TaskInfo.Handle(showThisForm);//改变值的事件 p.Show(); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } } //标签信息 public class listID { public string MarkId; public int check = 0; public double x; public double y; public string checktime = "标签未定位"; public long t = 0; } //private void refreshTable() //{ // try // { // string sql = "select * from TASKINFO"; // dt = OledbHelper.QueryTable(sql); // dataGridViewX_Task.DataSource = dt; // } // catch (Exception ex) // { // MessageBox.Show(ex.ToString()); // } //} private void flyToTask(int rowIndex) { int dbID = 0; dbID = Convert.ToInt32(dataGridViewX_Task.Rows[rowIndex].Cells["任务编号"].Value); string userName = Convert.ToString(dataGridViewX_Task.Rows[rowIndex].Cells["任务执行人员"].Value); System.DateTime t = new DateTime(); try { OracleConnection conn = null; List<listID> listIDs = new List<listID>(); conn = OledbHelper.sqlConnection(); conn.Open(); OracleCommand cmd = new OracleCommand("select * from MARK_TASK", conn); OracleDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { int id = Convert.ToInt32(dr["TASK_ID"]); if (id == dbID) { listID li = new listID(); li.MarkId = Convert.ToString(dr["MARK_ID"]); if (Convert.ToInt32(dr["IS_CHECKED"]) == 1) { //Datatime li.check = Convert.ToInt32(dr["IS_CHECKED"]); li.checktime = Convert.ToString(dr["CHECKTIME"]); t = (System.DateTime)dr["CHECKTIME"]; li.t = t.Year * 10000000000 + t.Day * 1000000 + t.Month * 100000000 + t.Hour * 10000 + t.Minute * 100 + t.Second; } listIDs.Add(li); } } dr.Close(); conn.Close(); conn = OledbHelper.sqlConnection(); conn.Open(); cmd = new OracleCommand("select * from 标识器", conn); dr = cmd.ExecuteReader(); int ID = GeoScene.Data.GSOProjectManager.AddProject("+proj=tmerc +lat_0=0 +lon_0=120 +k=1 +x_0=499885 +y_0=6 +ellps=krass +units=m +no_defs"); double x = 558443.622; double y = 3451941.845; GSOGeoModel model = new GSOGeoModel(); string filepath; GSOPoint3d p = new GSOPoint3d(); //GSOPoint3d po = new GSOPoint3d(); GSOPoint3ds pnts = new GSOPoint3ds(); GSOGeoPolyline3D line = new GSOGeoPolyline3D(); while (dr.Read()) { string id = Convert.ToString(dr["编号"]);//// for (int i = 0; i < listIDs.Count; i++) { if (id == Convert.ToString(listIDs[i].MarkId)) { x = Convert.ToDouble(dr["X坐标"]); y = Convert.ToDouble(dr["Y坐标"]); GeoScene.Data.GSOPoint2d pt2d = new GeoScene.Data.GSOPoint2d(y, x); GeoScene.Data.GSOPoint2d result = GeoScene.Data.GSOProjectManager.Inverse(pt2d, ID); p.X = result.X; p.Y = result.Y; p.X += 0.000019; p.Y += 0.000539; p.Z = 1.5; if (Convert.ToInt16(listIDs[i].check) == 1) { filepath = Application.StartupPath + "/EMSgcm/小旗子/lvqi/lvqi.gcm"; model.FilePath = filepath; } if (Convert.ToInt16(listIDs[i].check) == 0) { filepath = Application.StartupPath + "/EMSgcm/小旗子/hongqi/hongqi.gcm"; model.FilePath = filepath; } model.Position = p; model.AltitudeMode = EnumAltitudeMode.Absolute; GSOFeature f = new GSOFeature(); f.Geometry = model; f.Name = "标识器:" + id; GSOFeature newFeature = globeControl1.Globe.MemoryLayer.AddFeature(f); GSOLabel label = new GSOLabel(); label.Text = "任务工单号:" + dbID + "\r\n" + "标识器编号:" + listIDs[i].MarkId + "\r\n" + "管线定位员:" + userName + "\r\n" + "定位时间:" + listIDs[i].checktime; label.Style = new GSOLabelStyle(); label.Style.Opaque = 0.8; //设置标注的透明度,取值区间是0-1 label.Style.TracktionLineType = EnumTracktionLineType.Solid; label.Style.TextStyle.FontHeight = 10; label.Style.TextStyle.FontName = "宋体"; label.Style.TractionLineEndPos = new GSOPoint2d(80, 60); label.Style.BackBeginColor = Color.Cyan; label.Style.BackEndColor = Color.White; //bai label.Style.MaxVisibleDistance = -1; newFeature.Label = label; listIDs[i].x = p.X; listIDs[i].y = p.Y; if(i == 0) globeControl1.Globe.JumpToFeature(newFeature, 200); } } } dr.Close(); conn.Close(); // 按扫描时间对任务点进行排序 int m = 0; long time = 0; for (int ii = 0; ii < listIDs.Count; ii++) { for (int k = ii; k < listIDs.Count; k++) { if (time < listIDs[k].t) { time = listIDs[k].t; m = k; } } if (listIDs[m].check == 1) { p.X = listIDs[m].x; p.Y = listIDs[m].y; p.Z = 2.5; pnts.Add(p); time = listIDs[ii].t; listIDs[ii].t = listIDs[m].t; listIDs[m].t = time; int i = 0; i = listIDs[ii].check; listIDs[ii].check = listIDs[m].check; listIDs[m].check = i; x = listIDs[ii].x; listIDs[ii].x = listIDs[m].x; listIDs[m].x = x; y = listIDs[ii].y; listIDs[ii].y = listIDs[m].y; listIDs[m].y = y; } time = 0; } if (pnts.Count != 0) { line.AddPart(pnts); //把节点添加到线上 line.AltitudeMode = EnumAltitudeMode.Absolute; GSOSimpleLineStyle3D style1 = new GSOSimpleLineStyle3D(); //创建线的风格 //style1.LineColor = Color.FromArgb(250, 255, 0, 255); style1.LineColor = Color.Red; style1.LineWidth = 3; //设置线的宽度为3 style1.VertexVisible = true; //显示线的节点 line.Style = style1; //把风格添加到线上 GSOFeature f2 = new GSOFeature(); f2.Geometry = line; //把线对象添加到几何对象上 f2.Name = "轨迹"; //设置几何对象的名称 f2.SetFieldValue("description", "这是线的属性"); //设置几何对象的字段值 GSOFeature newFeature2 = globeControl1.Globe.MemoryLayer.AddFeature(f2); globeControl1.Globe.JumpToFeature(newFeature2, 230); globeControl1.Refresh(); } //else //{ // if (pnts.Count == 0) // { // MessageBox.Show("未有任务探测记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // } //} } catch (Exception ex) { MessageBox.Show(ex.ToString()); } finally { //conn.Close(); } } private void button_search_Click(object sender, EventArgs e) { try { currentpage = 1; reloadGrid(currentpage); } catch (Exception ex) { MessageBox.Show("查询失败:" + ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void reloadGrid(int pageIndex) { if (dateTimePicker_start.Value != null && dateTimePicker_end.Value != null) { int compare = DateTime.Compare(dateTimePicker_start.Value, dateTimePicker_end.Value); if (compare == 1) { MessageBox.Show("起始时间不能大于终止时间,请重新设置!", "提示"); return; } } string sqlcount = "select count(*) from taskinfo t where 1=1"; string sqlrows = "select * from (select rownum as rowno,dbid," + "deploytime," + "descirption," + "finishtime," + "street," + "taskstate," + "username," + "'查看' as btn " + "from taskinfo where 1=1 "; if (!String.IsNullOrEmpty(comboBox_userName.Text.Trim())) { sqlcount += " and username='" + comboBox_userName.Text.Trim() + "' "; sqlrows += " and username='" + comboBox_userName.Text.Trim() + "' "; } if (dateTimePicker_start.Value != null) { sqlcount += "and deploytime>=to_date('" + dateTimePicker_start.Value.ToShortDateString() + "','yyyy-MM-dd') "; sqlrows += "and deploytime>=to_date('" + dateTimePicker_start.Value.ToShortDateString() + "','yyyy-MM-dd') "; } if (dateTimePicker_end.Value != null) { DateTime time = dateTimePicker_end.Value; time = time.AddDays(1); sqlcount += "and deploytime<=to_date('" + time.ToShortDateString() + "','yyyy-MM-dd') "; sqlrows += "and deploytime<=to_date('" + time.ToShortDateString() + "','yyyy-MM-dd') "; } if (!String.IsNullOrEmpty(combo_street.Text)) { sqlcount += "and street='" + combo_street.Text + "' "; sqlrows += "and street='" + combo_street.Text + "' "; } sqlrows += " and rownum<=" + (pagesize * pageIndex) + ") table_alias where table_alias.rowno>=" + ((pageIndex - 1) * pagesize + 1); int rows = int.Parse(OracleUtils.ExecuteScalar(OracleUtils.ConnectionString, CommandType.Text, sqlcount).ToString()); int pages = 0; if (rows % pagesize == 0) { pages = rows / pagesize; } else { pages = rows / pagesize + 1; } lastpage = pages; lab_page_msg.Text = "共" + rows + "条记录,每页" + pagesize + "条,第" + pageIndex + "页,共" + pages + "页"; combo_page_num.Items.Clear(); for (int i = 1; i <= pages; i++) { combo_page_num.Items.Add(new ComboBoxItem(i.ToString(), i.ToString())); } if (currentpage == 1) { btn_page_first.Enabled = false; btn_page_pre.Enabled = false; btn_page_last.Enabled = true; btn_page_next.Enabled = true; } else if (currentpage == lastpage) { btn_page_first.Enabled = true; btn_page_pre.Enabled = true; btn_page_last.Enabled = false; btn_page_next.Enabled = false; } else { btn_page_first.Enabled = true; btn_page_pre.Enabled = true; btn_page_last.Enabled = true; btn_page_next.Enabled = true; } DataTable table = OracleUtils.ExecuteDataset(OracleUtils.ConnectionString, CommandType.Text, sqlrows).Tables[0]; dataGridViewX_Task.DataSource = table; if (table.Rows.Count == 0) { MessageBox.Show("没有找到任何数据!", "提示"); } } private void button_first_Click(object sender, EventArgs e) { currentpage = 1; reloadGrid(currentpage); } private void button_pre_Click(object sender, EventArgs e) { currentpage--; if (currentpage < 1) { currentpage = 1; } reloadGrid(currentpage); } private void button_next_Click(object sender, EventArgs e) { currentpage++; if (currentpage > lastpage) { currentpage = lastpage; } reloadGrid(currentpage); } private void button_last_Click(object sender, EventArgs e) { currentpage = lastpage; reloadGrid(currentpage); } private void comboBoxItem1_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(combo_page_num.Text)) { currentpage = int.Parse(combo_page_num.Text); reloadGrid(currentpage); } } } }