using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WWPipeLine.MapBasic.Conditions; using WeifenLuo.WinFormsUI.Docking; using WWPipeLine.MapBasic; using SuperMap.Data; using SuperMap.Mapping; using Sunny.UI; using System.IO; using SuperMap.Data.Conversion; namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi { public partial class PCRuKuTemp : ConditionPanel { Recordset rd = null; public PCRuKuTemp() { this.ConditionPanelName = "普查数据入临时库"; InitializeComponent(); this.SetSize(1000, 600); this.IsShowResultWindow = false; } protected override void OnLoad(EventArgs e) { ComsStatic.setUIDataGridView(uidgv); ComsStatic.BindUICombox(uicbxlayer, false); uirbtGD.Checked = true; } public override object Do(DockPanel dockPanel = null) { #region ImportSetting导入文件 //OpenFileDialog ofd = new OpenFileDialog { Filter = "CSV文件|*.csv", RestoreDirectory = true, Title = "请选择需要上传的图片" }; //if (ofd.ShowDialog() == DialogResult.OK) //{ // DataImport di = new DataImport(); // ImportSettingCSV setting = new ImportSettingCSV(); // setting.FirstRowIsField = true; // setting.SourceFileCharset = Charset.GB18030; // setting.ImportMode = ImportMode.Overwrite; // setting.SourceFilePath = ofd.FileName; // setting.TargetDatasource = ComsStatic.Datasource; // setting.TargetDatasetName = "PuChaTemp"; // //setting.TargetPrjCoordSys= new PrjCoordSys(PrjCoordSysType.China20003DegreeGk40N); // setting.SetFieldsAsPoint(new string[] { "x", "y" }); // di.ImportSettings.Add(setting); // di.Run(); //} #endregion if (rd == null) { Sunny.UI.UIMessageTip.ShowError("请先选择普查表类型"); return null; } //if (rd != null && !rd.IsEmpty) rd.DeleteAll(); if (uirbtGD.Checked) { if (panel2.Controls.Find("X", true).Length != 1 || panel2.Controls.Find("Y", true).Length != 1) { UIMessageTip.ShowError("缺少X坐标和Y坐标的配置信息"); return null; } UIComboBox cbxX = panel2.Controls.Find("X", true)[0] as UIComboBox; UIComboBox cbxY = panel2.Controls.Find("Y", true)[0] as UIComboBox; if (cbxX.SelectedItem.ToString() == "不导入" || cbxY.SelectedItem.ToString() == "不导入") { UIMessageTip.ShowError("X坐标和Y坐标为成图必须字段"); return null; } List list = new List(); foreach (Control ctl in panel2.Controls) { UIComboBox cbx = ctl as UIComboBox; if (cbx.SelectedItem.ToString() == "不导入") continue; list.Add(cbx); } int successCount = 0; foreach (DataGridViewRow dgvr in uidgv.Rows) { double smx = ComsStatic.StringToDouble(dgvr.Cells[cbxX.SelectedItem.ToString()].Value); double smy = ComsStatic.StringToDouble(dgvr.Cells[cbxY.SelectedItem.ToString()].Value); if (smx == 0 || smy == 0) continue; rd.AddNew(new GeoPoint(smx, smy)); foreach (UIComboBox cbx in list.ToArray()) { object fieldValue = null; switch ((FieldType)cbx.Tag) { case FieldType.Int32: fieldValue = ComsStatic.StringToInt(dgvr.Cells[cbx.SelectedItem.ToString()].Value); break; case FieldType.Int16: fieldValue = ComsStatic.StringToInt16(dgvr.Cells[cbx.SelectedItem.ToString()].Value); break; case FieldType.Double: fieldValue = ComsStatic.StringToDouble(dgvr.Cells[cbx.SelectedItem.ToString()].Value); break; case FieldType.DateTime: DateTime result = DateTime.MinValue; DateTime.TryParse(dgvr.Cells[cbx.SelectedItem.ToString()].Value?.ToString(), out result); fieldValue = result; break; default: fieldValue = dgvr.Cells[cbx.SelectedItem.ToString()].Value?.ToString(); break; } rd.SetFieldValue(cbx.Name, fieldValue); } rd.SetFieldValue("FLDM", uicbxlayer.SelectedItem.ToString()); if (rd.Update()) successCount++; } if (uidgv.Rows.Count == successCount) ComsStatic.ShowOKLog("数据导入成功"); else ComsStatic.ShowErrorLog(string.Format("应导入{0}条数据,共导入{1}条。", uidgv.Rows.Count, successCount)); } if (uirbtGX.Checked) { } return true; } private void uiButton1_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog { Filter = "CSV文件|*.csv", RestoreDirectory = true, Title = "请选择需要上传的文件" }; if (ofd.ShowDialog() != DialogResult.OK) return; uidgv.DataSource = ComsStatic.CSVToDataTable(ofd.FileName, uirbnT.Checked); if (uidgv.Rows.Count == 0) { Sunny.UI.UIMessageTip.ShowError("当前普查数据为空"); return; } List listPuCha = new List(); foreach (DataGridViewColumn dc in uidgv.Columns) { listPuCha.Add(dc.Name); } panel1.Controls.Clear(); panel2.Controls.Clear(); string allTag = ",tz,fsw,xh,gg,cz,kj,gj,msfs,msrq,dzms,qsdw,tcdw,x,y,dmgc,ms,".ToLower(); if (uirbtGX.Checked) allTag = ",tz,gj,cz,msfs,msrq,yl,qsdw,dzms,tcdw,"; foreach (FieldInfo info in rd.GetFieldInfos()) { if (!allTag.Contains("," + info.Name.ToLower() + ",") || info.IsSystemField) continue; Point p = new Point(2, uiGroupBox2.Controls.Find("cbxPeiZhi", true).Length * 30); UILabel cbxPeiZhi = new UILabel() { Name = "cbxPeiZhi", Size = new Size(160, 25), TextAlign = ContentAlignment.MiddleRight, Text = string.Format("{0}对应字段:", info.Caption) }; cbxPeiZhi.Location = p; panel1.Controls.Add(cbxPeiZhi); UIComboBox cbxPuCha = new UIComboBox() { Name = info.Name, Tag = info.Type, DropDownStyle = UIDropDownStyle.DropDownList, Size = new Size(160, 25) }; cbxPuCha.Items.Add("不导入"); foreach (string pz in listPuCha.ToArray()) { cbxPuCha.Items.Add(pz); } cbxPuCha.Location = p; cbxPuCha.SelectedIndex = 0; panel2.Controls.Add(cbxPuCha); } uirbnF.Enabled = false; uirbnT.Enabled = false; uirbtGD.Enabled = false; uirbtGX.Enabled = false; uiButton1.Enabled = false; } private void uirbtGX_CheckedChanged(object sender, EventArgs e) { DatasetVector dv = ComsStatic.Datasource.Datasets["TempJD"] as DatasetVector; if (uirbtGX.Checked) dv = ComsStatic.Datasource.Datasets["TempLK"] as DatasetVector; dv.Truncate(); rd = dv.GetRecordset(true, CursorType.Dynamic); } public override void AfterClose() { ComsStatic.RecordsetDispose(rd); base.AfterClose(); } } }