PCRuKuTemp.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using WeifenLuo.WinFormsUI.Docking;
  12. using WWPipeLine.MapBasic;
  13. using SuperMap.Data;
  14. using SuperMap.Mapping;
  15. using Sunny.UI;
  16. using System.IO;
  17. using SuperMap.Data.Conversion;
  18. namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
  19. {
  20. public partial class PCRuKuTemp : ConditionPanel
  21. {
  22. Recordset rd = null;
  23. public PCRuKuTemp()
  24. {
  25. this.ConditionPanelName = "普查数据入临时库";
  26. InitializeComponent();
  27. this.SetSize(1000, 600);
  28. this.IsShowResultWindow = false;
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. ComsStatic.setUIDataGridView(uidgv);
  33. ComsStatic.BindUICombox(uicbxlayer, false);
  34. uirbtGD.Checked = true;
  35. }
  36. public override object Do(DockPanel dockPanel = null)
  37. {
  38. #region ImportSetting导入文件
  39. //OpenFileDialog ofd = new OpenFileDialog { Filter = "CSV文件|*.csv", RestoreDirectory = true, Title = "请选择需要上传的图片" };
  40. //if (ofd.ShowDialog() == DialogResult.OK)
  41. //{
  42. // DataImport di = new DataImport();
  43. // ImportSettingCSV setting = new ImportSettingCSV();
  44. // setting.FirstRowIsField = true;
  45. // setting.SourceFileCharset = Charset.GB18030;
  46. // setting.ImportMode = ImportMode.Overwrite;
  47. // setting.SourceFilePath = ofd.FileName;
  48. // setting.TargetDatasource = ComsStatic.Datasource;
  49. // setting.TargetDatasetName = "PuChaTemp";
  50. // //setting.TargetPrjCoordSys= new PrjCoordSys(PrjCoordSysType.China20003DegreeGk40N);
  51. // setting.SetFieldsAsPoint(new string[] { "x", "y" });
  52. // di.ImportSettings.Add(setting);
  53. // di.Run();
  54. //}
  55. #endregion
  56. if (rd == null) { Sunny.UI.UIMessageTip.ShowError("请先选择普查表类型"); return null; }
  57. //if (rd != null && !rd.IsEmpty) rd.DeleteAll();
  58. if (uirbtGD.Checked)
  59. {
  60. if (panel2.Controls.Find("X", true).Length != 1 || panel2.Controls.Find("Y", true).Length != 1)
  61. { UIMessageTip.ShowError("缺少X坐标和Y坐标的配置信息"); return null; }
  62. UIComboBox cbxX = panel2.Controls.Find("X", true)[0] as UIComboBox;
  63. UIComboBox cbxY = panel2.Controls.Find("Y", true)[0] as UIComboBox;
  64. if (cbxX.SelectedItem.ToString() == "不导入" || cbxY.SelectedItem.ToString() == "不导入")
  65. { UIMessageTip.ShowError("X坐标和Y坐标为成图必须字段"); return null; }
  66. List<UIComboBox> list = new List<UIComboBox>();
  67. foreach (Control ctl in panel2.Controls)
  68. {
  69. UIComboBox cbx = ctl as UIComboBox;
  70. if (cbx.SelectedItem.ToString() == "不导入") continue;
  71. list.Add(cbx);
  72. }
  73. int successCount = 0;
  74. foreach (DataGridViewRow dgvr in uidgv.Rows)
  75. {
  76. double smx = ComsStatic.StringToDouble(dgvr.Cells[cbxX.SelectedItem.ToString()].Value);
  77. double smy = ComsStatic.StringToDouble(dgvr.Cells[cbxY.SelectedItem.ToString()].Value);
  78. if (smx == 0 || smy == 0) continue;
  79. rd.AddNew(new GeoPoint(smx, smy));
  80. foreach (UIComboBox cbx in list.ToArray())
  81. {
  82. object fieldValue = null;
  83. switch ((FieldType)cbx.Tag)
  84. {
  85. case FieldType.Int32:
  86. fieldValue = ComsStatic.StringToInt(dgvr.Cells[cbx.SelectedItem.ToString()].Value); break;
  87. case FieldType.Int16:
  88. fieldValue = ComsStatic.StringToInt16(dgvr.Cells[cbx.SelectedItem.ToString()].Value); break;
  89. case FieldType.Double:
  90. fieldValue = ComsStatic.StringToDouble(dgvr.Cells[cbx.SelectedItem.ToString()].Value); break;
  91. case FieldType.DateTime:
  92. DateTime result = DateTime.MinValue;
  93. DateTime.TryParse(dgvr.Cells[cbx.SelectedItem.ToString()].Value?.ToString(), out result);
  94. fieldValue = result;
  95. break;
  96. default:
  97. fieldValue = dgvr.Cells[cbx.SelectedItem.ToString()].Value?.ToString(); break;
  98. }
  99. rd.SetFieldValue(cbx.Name, fieldValue);
  100. }
  101. rd.SetFieldValue("FLDM", uicbxlayer.SelectedItem.ToString());
  102. if (rd.Update())
  103. successCount++;
  104. }
  105. if (uidgv.Rows.Count == successCount)
  106. ComsStatic.ShowOKLog("数据导入成功");
  107. else
  108. ComsStatic.ShowErrorLog(string.Format("应导入{0}条数据,共导入{1}条。", uidgv.Rows.Count, successCount));
  109. }
  110. if (uirbtGX.Checked)
  111. {
  112. }
  113. return true;
  114. }
  115. private void uiButton1_Click(object sender, EventArgs e)
  116. {
  117. OpenFileDialog ofd = new OpenFileDialog { Filter = "CSV文件|*.csv", RestoreDirectory = true, Title = "请选择需要上传的文件" };
  118. if (ofd.ShowDialog() != DialogResult.OK) return;
  119. uidgv.DataSource = ComsStatic.CSVToDataTable(ofd.FileName, uirbnT.Checked);
  120. if (uidgv.Rows.Count == 0) { Sunny.UI.UIMessageTip.ShowError("当前普查数据为空"); return; }
  121. List<string> listPuCha = new List<string>();
  122. foreach (DataGridViewColumn dc in uidgv.Columns)
  123. {
  124. listPuCha.Add(dc.Name);
  125. }
  126. panel1.Controls.Clear(); panel2.Controls.Clear();
  127. string allTag = ",tz,fsw,xh,gg,cz,kj,gj,msfs,msrq,dzms,qsdw,tcdw,x,y,dmgc,ms,".ToLower();
  128. if (uirbtGX.Checked)
  129. allTag = ",tz,gj,cz,msfs,msrq,yl,qsdw,dzms,tcdw,";
  130. foreach (FieldInfo info in rd.GetFieldInfos())
  131. {
  132. if (!allTag.Contains("," + info.Name.ToLower() + ",") || info.IsSystemField) continue;
  133. Point p = new Point(2, uiGroupBox2.Controls.Find("cbxPeiZhi", true).Length * 30);
  134. UILabel cbxPeiZhi = new UILabel() { Name = "cbxPeiZhi", Size = new Size(160, 25), TextAlign = ContentAlignment.MiddleRight, Text = string.Format("{0}对应字段:", info.Caption) };
  135. cbxPeiZhi.Location = p;
  136. panel1.Controls.Add(cbxPeiZhi);
  137. UIComboBox cbxPuCha = new UIComboBox() { Name = info.Name, Tag = info.Type, DropDownStyle = UIDropDownStyle.DropDownList, Size = new Size(160, 25) };
  138. cbxPuCha.Items.Add("不导入"); foreach (string pz in listPuCha.ToArray()) { cbxPuCha.Items.Add(pz); }
  139. cbxPuCha.Location = p;
  140. cbxPuCha.SelectedIndex = 0;
  141. panel2.Controls.Add(cbxPuCha);
  142. }
  143. uirbnF.Enabled = false; uirbnT.Enabled = false; uirbtGD.Enabled = false; uirbtGX.Enabled = false; uiButton1.Enabled = false;
  144. }
  145. private void uirbtGX_CheckedChanged(object sender, EventArgs e)
  146. {
  147. DatasetVector dv = ComsStatic.Datasource.Datasets["TempJD"] as DatasetVector;
  148. if (uirbtGX.Checked)
  149. dv = ComsStatic.Datasource.Datasets["TempLK"] as DatasetVector;
  150. dv.Truncate();
  151. rd = dv.GetRecordset(true, CursorType.Dynamic);
  152. }
  153. public override void AfterClose()
  154. {
  155. ComsStatic.RecordsetDispose(rd);
  156. base.AfterClose();
  157. }
  158. }
  159. }