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 DevComponents.DotNetBar; using DevComponents.DotNetBar.Controls; using EMS; using GeoScene.Data; namespace Cyberpipe { public partial class FrmPatrolerManager : Office2007Form { private GeoScene.Globe.GSOGlobeControl globeControl1; private int currentpage = 1; private int lastpage = 1; private int pagesize = 10; string combo_stateText = ""; public static bool IS_OPEN = false; public FrmPatrolerManager(GeoScene.Globe.GSOGlobeControl globeControl1) { InitializeComponent(); this.globeControl1 = globeControl1; } private void reloadDataGrid(int pageIndex) { if (pageIndex <= 0) { pageIndex = 1; currentpage = 1; } string sqlcount = "select count(*) from patroler where 1=1 "; string sqlrows = "select * from (select rownum as rowno,dbid,username,sex,age,phonenum,accountstate,'编辑' as btnEdit,'注销' as btnLogout,'日志' as btnLog,'任务' as btnTask,'定位' as btnLocate from patroler where 1=1"; if (!String.IsNullOrEmpty(txt_username.Text.Trim())) { sqlcount += " and username like '%" + txt_username.Text.Trim() + "%'"; sqlrows += " and username like '%" + txt_username.Text.Trim() + "%'"; } if (!String.IsNullOrEmpty(txt_phone.Text.Trim())) { sqlcount += " and phonenum='" + txt_phone.Text.Trim() + "'"; sqlrows += " and phonenum='" + txt_phone.Text.Trim() + "'"; } if (null != combo_sex.SelectedItem && !String.IsNullOrEmpty(combo_sex.SelectedItem.ToString())) { sqlcount += " and sex='" + combo_sex.SelectedItem.ToString() + "'"; sqlrows += " and sex='" + combo_sex.SelectedItem.ToString() + "'"; } if (null != combo_state.SelectedItem && !String.IsNullOrEmpty(combo_state.SelectedItem.ToString())) { sqlcount += " and accountstate='" + combo_stateText + "'"; sqlrows += " and accountstate='" + combo_stateText + "'"; } sqlrows += " and rownum<=" + (pagesize * pageIndex) + ") table_alias where table_alias.rowno>=" + ((pageIndex - 1) * pagesize + 1); sqlrows += " order by table_alias.dbid desc"; 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]; dataGridViewX1.DataSource = table; for (int i = 0; i < dataGridViewX1.Rows.Count; i++) { if (dataGridViewX1.Rows[i].Cells["ACCOUNTSTATE"].Value.ToString() == "ONLINE") { dataGridViewX1.Rows[i].Cells["ACCOUNTSTATE"].Value = "在线"; } else { if (dataGridViewX1.Rows[i].Cells["ACCOUNTSTATE"].Value.ToString() == "OFFLINE") { dataGridViewX1.Rows[i].Cells["ACCOUNTSTATE"].Value = "离线"; } else { if (dataGridViewX1.Rows[i].Cells["ACCOUNTSTATE"].Value.ToString() == "LEAVER") { dataGridViewX1.Rows[i].Cells["ACCOUNTSTATE"].Value = "注销"; } } } } } private void dataGridViewX1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0 || e.ColumnIndex<0) { return; } String resultMsg = null; String buttonText = dataGridViewX1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); try { long dbid = long.Parse(dataGridViewX1.Rows[e.RowIndex].Cells["dbid"].Value.ToString()); if ("编辑".Equals(buttonText)) { String name = dataGridViewX1.Rows[e.RowIndex].Cells["USERNAME"].Value.ToString(); String sex = dataGridViewX1.Rows[e.RowIndex].Cells["SEX"].Value.ToString(); String age = dataGridViewX1.Rows[e.RowIndex].Cells["AGE"].Value.ToString(); string phone = dataGridViewX1.Rows[e.RowIndex].Cells["PHONENUM"].Value.ToString(); age = String.IsNullOrEmpty(age.ToString().Trim()) ? "1" : age.ToString().Trim(); FrmPatrolerEdit frm = new FrmPatrolerEdit(dbid.ToString(),name,age,sex,phone); frm.reloadGrid += new ReloadPatrolerGrid(reloadDataGrid); frm.ShowDialog(); } if ("注销".Equals(buttonText)) { string state = dataGridViewX1.Rows[e.RowIndex].Cells["ACCOUNTSTATE"].Value.ToString(); if ("在线".Equals(state)) { if (MessageBox.Show("确定注销?", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { String sql = "update patroler t set t.accountstate='LEAVER' where t.dbid=" + dbid; OracleUtils.ExecuteNonQuery(OracleUtils.ConnectionString, CommandType.Text, sql); dataGridViewX1.Rows.RemoveAt(e.RowIndex); dataGridViewX1.Refresh(); resultMsg = "巡检人员注销成功!"; } } } if ("日志".Equals(buttonText)) { Log p = new Log(dbid.ToString()); p.Show(); } if ("任务".Equals(buttonText)) { try { String state = dataGridViewX1.Rows[e.RowIndex].Cells["ACCOUNTSTATE"].Value.ToString(); if ("在线".Equals(state)) { string sql = "select t.dbid " + "from taskinfo t " + "where (t.taskstate = '开始任务' or t.taskstate = '执行过程中') " + "and t.patroler_id =" + dbid + " " + "order by t.deploytime desc"; DataTable dt = OracleUtils.ExecuteDataset(OracleUtils.ConnectionString, CommandType.Text, sql).Tables[0]; if (dt.Rows.Count > 0) { TaskInfo p = new TaskInfo(int.Parse(dt.Rows[0][0].ToString())); p.Show(); } else { MessageBox.Show("当前用户没有开始任务或接受任务", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } else { MessageBox.Show("当前用户没有在线", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } } catch (Exception ex) { MessageBox.Show("任务打开失败:" + ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if ("定位".Equals(buttonText)) { try { String username = dataGridViewX1.Rows[e.RowIndex].Cells["USERNAME"].Value.ToString(); string sql = "select t.latitude, t.longitude " + "from position t " + "where t.dbid = (select max(dbid) from position where patroler_id = " + dbid + ")"; DataTable table = OracleUtils.ExecuteDataset(OracleUtils.ConnectionString, CommandType.Text, sql).Tables[0]; if (table.Rows.Count > 0) { double x = double.Parse(table.Rows[0]["longitude"].ToString()); double y = double.Parse(table.Rows[0]["latitude"].ToString()); GSOPoint3d p = new GSOPoint3d(); p.X = x; p.Y = y; p.Z = 7; GSOGeoModel model = new GSOGeoModel(); string filepath = Application.StartupPath + "/EMSgcm/person/ren.gcm"; model.FilePath = filepath; model.Position = p; model.AltitudeMode = EnumAltitudeMode.Absolute; GeoScene.Globe.GSOCameraState cameraState = new GeoScene.Globe.GSOCameraState(); cameraState.Longitude = x; cameraState.Latitude = y; cameraState.Heading = -3.51574088627348; cameraState.Tilt = 44.392160966227; cameraState.Distance = 50; cameraState.Altitude = 0; cameraState.AltitudeMode = EnumAltitudeMode.Absolute; model.CameraState = cameraState; GSOFeature f = new GSOFeature(); f.Geometry = model; GSOFeature newFeature = globeControl1.Globe.MemoryLayer.AddFeature(f); //globeControl1.Globe.JumpToPosition(p, EnumAltitudeMode.Absolute, 50); globeControl1.Globe.JumpToCameraState(cameraState); globeControl1.Refresh(); //GSOMarkerStyle3D mstyle = new GSOMarkerStyle3D(); //mstyle.IconPath = Application.StartupPath + "\\Resource\\imagebig\\worker.png"; //mstyle.IconScale = 3; //p.Style = mstyle; //GSOFeature f = new GSOFeature(); //f.Geometry = p; //f.Name = username; //GSOFeature newFeature = globeControl1.Globe.MemoryLayer.AddFeature(f); //globeControl1.Globe.JumpToFeature(f, 300); //globeControl1.Refresh(); } } catch (Exception ex) { MessageBox.Show("定位失败:" + ex.ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (!String.IsNullOrEmpty(resultMsg)) { MessageBox.Show(resultMsg, "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { if ("注销".Equals(buttonText)) { resultMsg = "巡检人员注销操作失败:" + ex.ToString(); ; } if ("编辑".Equals(buttonText)) { resultMsg = "巡检人员编辑操作失败:" + ex.ToString(); ; } MessageBox.Show(resultMsg, "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void FrmPatrolerManager_Load(object sender, EventArgs e) { try { reloadDataGrid(currentpage); initForm(); IS_OPEN = true; } catch (Exception ex) { MessageBox.Show("窗体加载失败:" + ex.ToString(), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); ex.ToString(); } } private void initForm() { if (Utility.userRole.IndexOf("巡检员新增") == -1) { btn_add_person.Visible = false; } if (Utility.userRole.IndexOf("巡检员编辑") == -1) { dataGridViewX1.Columns["btnEdit"].Visible = false; } if (Utility.userRole.IndexOf("巡检员注销") == -1) { dataGridViewX1.Columns["btnDel"].Visible = false; } } private void btn_query_person_Click(object sender, EventArgs e) { try { currentpage = 1; reloadDataGrid(currentpage); } catch (Exception ex) { MessageBox.Show("查询失败:" + ex.ToString(), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); ex.ToString(); } } private void btn_add_person_Click(object sender, EventArgs e) { try { FrmPatrolerEdit frm = new FrmPatrolerEdit(); frm.reloadGrid += new ReloadPatrolerGrid(reloadDataGrid); frm.ShowDialog(); } catch (Exception ex) { MessageBox.Show("新增巡检人员操作失败:" + ex.ToString(), "错误信息", MessageBoxButtons.OK, MessageBoxIcon.Error); ex.ToString(); } } private void btn_page_first_Click(object sender, EventArgs e) { currentpage = 1; reloadDataGrid(currentpage); } private void btn_page_pre_Click(object sender, EventArgs e) { currentpage--; if (currentpage <= 0) { currentpage = 1; } reloadDataGrid(currentpage); } private void btn_page_next_Click(object sender, EventArgs e) { currentpage++; if (currentpage > lastpage) { currentpage = lastpage; } reloadDataGrid(currentpage); } private void combo_page_num_SelectedIndexChanged(object sender, EventArgs e) { if (!String.IsNullOrEmpty(combo_page_num.Text.Trim())) { currentpage = int.Parse(combo_page_num.Text.Trim()); reloadDataGrid(currentpage); } } private void btn_page_last_Click(object sender, EventArgs e) { currentpage = lastpage; reloadDataGrid(currentpage); } private void combo_state_SelectedIndexChanged(object sender, EventArgs e) { if (combo_state.SelectedItem.ToString() == "在线") { combo_stateText = "ONLINE"; } if (combo_state.SelectedItem.ToString() == "离线") { combo_stateText = "OFFLINE"; } if (combo_state.SelectedItem.ToString() == "注销") { combo_stateText = "LEAVER"; } } private void FrmPatrolerManager_FormClosing(object sender, FormClosingEventArgs e) { globeControl1.Globe.MemoryLayer.RemoveAllFeature(); IS_OPEN = false; } } }