FormInitMap.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using DevExpress.Utils;
  12. using ProjectBase.Data.BaseDAL;
  13. using SIASUN.Autopilot.BLL;
  14. using SIASUN.Autopilot.Model;
  15. using ProjectBase.Data.Logs;
  16. namespace SIASUN.Autopilot.View
  17. {
  18. public partial class FormInitMap : DevExpress.XtraEditors.XtraForm
  19. {
  20. /// <summary>
  21. /// 图片宽度
  22. /// </summary>
  23. private int ImageWidth;
  24. /// <summary>
  25. /// 图片高度
  26. /// </summary>
  27. private int ImageHeight;
  28. /// <summary>
  29. /// 鼠标位置
  30. /// </summary>
  31. private Point mousePoint = new Point(); //鼠标位置
  32. public FormInitMap()
  33. {
  34. InitializeComponent();
  35. }
  36. private void FormInitMap_Load(object sender, EventArgs e)
  37. {
  38. this.picExControl1.SetImage(global::SIASUN.Autopilot.View.Properties.Resources.地图1, true);
  39. this.picExControl1.MouseMoveTooltipEvent += new PicExControl.MouseMoveTooltip(picExControl1_MouseMove);
  40. ImageWidth = global::SIASUN.Autopilot.View.Properties.Resources.地图1.Width;
  41. ImageHeight = global::SIASUN.Autopilot.View.Properties.Resources.地图1.Height;
  42. this.txt_X1.Properties.ReadOnly = true;
  43. this.txt_X2.Properties.ReadOnly = true;
  44. this.txt_Y1.Properties.ReadOnly = true;
  45. this.txt_Y2.Properties.ReadOnly = true;
  46. string mapId = System.Configuration.ConfigurationManager.AppSettings["MapId"];
  47. this.txt_MapId.Text = mapId;
  48. }
  49. /// <summary>
  50. /// 鼠标移动显示经纬度
  51. /// </summary>
  52. /// <param name="e"></param>
  53. private void picExControl1_MouseMove(MouseEventArgs e)
  54. {
  55. if (mousePoint.X != e.X || mousePoint.Y != e.Y)
  56. {
  57. ToolTipControllerShowEventArgs args = this.toolTip_Message.CreateShowArgs();
  58. float x = (e.X - this.picExControl1.StartPoint.X) / this.picExControl1.Wrate;
  59. float y = (e.Y - this.picExControl1.StartPoint.Y) / this.picExControl1.Hrate;
  60. args.ToolTip = string.Format("x:{0}\ny:{1}", x.ToString(), y.ToString());
  61. args.SelectedControl = this.picExControl1;
  62. //args.Title = "提示";
  63. this.toolTip_Message.ShowHint(args, System.Windows.Forms.Control.MousePosition);
  64. mousePoint.X = e.X;
  65. mousePoint.Y = e.Y;
  66. }
  67. else
  68. {
  69. mousePoint.X = e.X;
  70. mousePoint.Y = e.Y;
  71. }
  72. //pointStandard.Add(new PointF((e.X - this.picExControl1.StartPoint.X) / this.picExControl1.Wrate,
  73. // (e.Y - this.picExControl1.StartPoint.Y) / this.picExControl1.Hrate));
  74. }
  75. private void picExControl1_MouseLeave(object sender, EventArgs e)
  76. {
  77. this.toolTip_Message.HideHint();
  78. }
  79. /// <summary>
  80. /// 地图控件鼠标单击事件
  81. /// </summary>
  82. /// <param name="sender"></param>
  83. /// <param name="e"></param>
  84. private void picExControl1_MouseClick(object sender, MouseEventArgs e)
  85. {
  86. if (e.Button == MouseButtons.Right)
  87. {
  88. float x = (e.X - this.picExControl1.StartPoint.X) / this.picExControl1.Wrate;
  89. float y = (e.Y - this.picExControl1.StartPoint.Y) / this.picExControl1.Hrate;
  90. if (string.IsNullOrEmpty(this.txt_X1.Text) && string.IsNullOrEmpty(this.txt_Y1.Text) )
  91. {
  92. this.txt_X1.Text = x.ToString();
  93. this.txt_Y1.Text = y.ToString();
  94. }
  95. else if (string.IsNullOrEmpty(this.txt_X2.Text) && string.IsNullOrEmpty(this.txt_Y2.Text))
  96. {
  97. this.txt_X2.Text = x.ToString();
  98. this.txt_Y2.Text = y.ToString();
  99. }
  100. }
  101. }
  102. /// <summary>
  103. /// 清零按钮事件
  104. /// </summary>
  105. /// <param name="sender"></param>
  106. /// <param name="e"></param>
  107. private void btn_Clear_Click(object sender, EventArgs e)
  108. {
  109. this.txt_X1.Text = null;
  110. this.txt_X2.Text = null;
  111. this.txt_Y1.Text = null;
  112. this.txt_Y2.Text = null;
  113. }
  114. /// <summary>
  115. /// 保存按钮事件
  116. /// </summary>
  117. /// <param name="sender"></param>
  118. /// <param name="e"></param>
  119. private void btn_Save_Click(object sender, EventArgs e)
  120. {
  121. if (!Vaildate())
  122. {
  123. return;
  124. }
  125. try
  126. {
  127. MoLocationMap mo = new MoLocationMap();
  128. mo.MapId = this.txt_MapId.Text.Trim();
  129. mo.LocationLon1 = Convert.ToSingle(this.txt_Lon1.Text.Trim());
  130. mo.LocationLat1 = Convert.ToSingle(this.txt_Lat1.Text.Trim());
  131. mo.LocationLon2 = Convert.ToSingle(this.txt_Lon2.Text.Trim());
  132. mo.LocationLat2 = Convert.ToSingle(this.txt_Lat2.Text.Trim());
  133. mo.LocationX1 = Convert.ToSingle(this.txt_X1.Text.Trim());
  134. mo.LocationY1 = Convert.ToSingle(this.txt_Y1.Text.Trim());
  135. mo.LocationX2 = Convert.ToSingle(this.txt_X2.Text.Trim());
  136. mo.LocationY2 = Convert.ToSingle(this.txt_Y2.Text.Trim());
  137. bool flag = BLLFactory<BlLocationMap>.Instance.InsertUpdate(mo, new string[] { mo.MapId });
  138. if (flag)
  139. {
  140. DevExpress.XtraEditors.XtraMessageBox.Show("保存成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  141. this.Close();
  142. }
  143. else
  144. {
  145. DevExpress.XtraEditors.XtraMessageBox.Show("保存失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  146. }
  147. }
  148. catch (Exception ex)
  149. {
  150. DevExpress.XtraEditors.XtraMessageBox.Show("保存失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  151. LogHelper.log.Error(string.Format("插入或更新数据库location_map出现错误:{0}", ex));
  152. }
  153. }
  154. /// <summary>
  155. /// 验证输入信息是否完整
  156. /// </summary>
  157. /// <returns></returns>
  158. private bool Vaildate()
  159. {
  160. if (string.IsNullOrEmpty(this.txt_MapId.Text))
  161. {
  162. DevExpress.XtraEditors.XtraMessageBox.Show("请输入地图名称。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  163. return false;
  164. }
  165. if (string.IsNullOrEmpty(this.txt_X1.Text))
  166. {
  167. DevExpress.XtraEditors.XtraMessageBox.Show("请选择点1的X坐标。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  168. return false;
  169. }
  170. if (string.IsNullOrEmpty(this.txt_Y1.Text))
  171. {
  172. DevExpress.XtraEditors.XtraMessageBox.Show("请选择点1的Y坐标。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  173. return false;
  174. }
  175. if (string.IsNullOrEmpty(this.txt_Lon1.Text))
  176. {
  177. DevExpress.XtraEditors.XtraMessageBox.Show("请输入点1的经度。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  178. return false;
  179. }
  180. if (string.IsNullOrEmpty(this.txt_Lat1.Text))
  181. {
  182. DevExpress.XtraEditors.XtraMessageBox.Show("请输入点1的纬度。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  183. return false;
  184. }
  185. if (string.IsNullOrEmpty(this.txt_X2.Text))
  186. {
  187. DevExpress.XtraEditors.XtraMessageBox.Show("请选择点2的X坐标。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  188. return false;
  189. }
  190. if (string.IsNullOrEmpty(this.txt_Y2.Text))
  191. {
  192. DevExpress.XtraEditors.XtraMessageBox.Show("请选择点2的Y坐标。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  193. return false;
  194. }
  195. if (string.IsNullOrEmpty(this.txt_Lon2.Text))
  196. {
  197. DevExpress.XtraEditors.XtraMessageBox.Show("请输入点2的经度。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  198. return false;
  199. }
  200. if (string.IsNullOrEmpty(this.txt_Lat2.Text))
  201. {
  202. DevExpress.XtraEditors.XtraMessageBox.Show("请输入点2的纬度。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  203. return false;
  204. }
  205. return true;
  206. }
  207. }
  208. }