📄 dygxdesign.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace DataC
{
/// <summary>
/// Summary description for DYGXDesign.
/// </summary>
public class DYGXDesign : System.Windows.Forms.Form
{
private CFieldRelation _cFieldRelation=null;
private System.Data.OleDb.OleDbConnection _oleConn;
private System.Collections.ArrayList _alFields=null;
private
// string _strTransType=null;
bool _blGetValues=false;
public System.Windows.Forms.ListView lv;
private System.Windows.Forms.Button btOK;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox cbZHLX;
private System.Windows.Forms.ContextMenu cmRightKeyRule;
private System.Windows.Forms.MenuItem miDateDropDot;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public DYGXDesign(System.Data.OleDb.OleDbConnection oleConn, CFieldRelation relation)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
_oleConn=oleConn;
this.FieldRelation=relation;
_alFields=new System.Collections.ArrayList();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lv = new System.Windows.Forms.ListView();
this.btOK = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label1 = new System.Windows.Forms.Label();
this.cbZHLX = new System.Windows.Forms.ComboBox();
this.cmRightKeyRule = new System.Windows.Forms.ContextMenu();
this.miDateDropDot = new System.Windows.Forms.MenuItem();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// lv
//
this.lv.ContextMenu = this.cmRightKeyRule;
this.lv.FullRowSelect = true;
this.lv.Location = new System.Drawing.Point(0, 72);
this.lv.MultiSelect = false;
this.lv.Name = "lv";
this.lv.Size = new System.Drawing.Size(256, 160);
this.lv.TabIndex = 5;
this.lv.View = System.Windows.Forms.View.Details;
this.lv.DoubleClick += new System.EventHandler(this.lv_DoubleClick);
this.lv.SelectedIndexChanged += new System.EventHandler(this.lv_SelectedIndexChanged);
//
// btOK
//
this.btOK.Location = new System.Drawing.Point(176, 48);
this.btOK.Name = "btOK";
this.btOK.TabIndex = 6;
this.btOK.Text = "确定";
this.btOK.Click += new System.EventHandler(this.btOK_Click);
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Controls.Add(this.cbZHLX);
this.groupBox1.Location = new System.Drawing.Point(2, -4);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(254, 44);
this.groupBox1.TabIndex = 7;
this.groupBox1.TabStop = false;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(54, 17);
this.label1.TabIndex = 3;
this.label1.Text = "转换类型";
//
// cbZHLX
//
this.cbZHLX.Items.AddRange(new object[] {
"直接转换",
"定值转换"});
this.cbZHLX.Location = new System.Drawing.Point(88, 16);
this.cbZHLX.Name = "cbZHLX";
this.cbZHLX.Size = new System.Drawing.Size(144, 20);
this.cbZHLX.TabIndex = 2;
this.cbZHLX.Text = "直接转换";
this.cbZHLX.SelectedIndexChanged += new System.EventHandler(this.cbZHLX_SelectedIndexChanged);
//
// cmRightKeyRule
//
this.cmRightKeyRule.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.miDateDropDot});
this.cmRightKeyRule.Popup += new System.EventHandler(this.cmRightKeyRule_Popup);
//
// miDateDropDot
//
this.miDateDropDot.Index = 0;
this.miDateDropDot.Text = "日期去点规则";
this.miDateDropDot.Click += new System.EventHandler(this.miDateDropDot_Click);
//
// DYGXDesign
//
this.AcceptButton = this.btOK;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(256, 230);
this.ControlBox = false;
this.Controls.Add(this.groupBox1);
this.Controls.Add(this.btOK);
this.Controls.Add(this.lv);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "DYGXDesign";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "转换设置";
this.Load += new System.EventHandler(this.DYGXDesign_Load);
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void DYGXDesign_Load(object sender, System.EventArgs e)
{
lv.Items.Clear();
lv.Columns.Clear();
ColumnHeader aa=new ColumnHeader();
aa.Text="源字段值";
ColumnHeader bb=new ColumnHeader();
bb.Text="新值";
lv.Columns.Add(aa);
lv.Columns.Add(bb);
lv.Visible=false;
if(this.FieldRelation.TransType==null)
cbZHLX.Text="直接转换";
else
cbZHLX.Text=this.FieldRelation.TransType;
}
public CFieldRelation FieldRelation
{
get { return this._cFieldRelation;}
set { this._cFieldRelation = value;}
}
private void btOK_Click(object sender, System.EventArgs e)
{
FieldRelation.TransType=cbZHLX.Text;
FieldRelation.ValueMap.Clear();
for( int i=0; i<lv.Items.Count; i++ )
{
if( lv.Items[i].SubItems[1].Text=="")
continue;
if (lv.Items[i].SubItems[0].Text!="")
FieldRelation.ValueMap.Add( lv.Items[i].SubItems[0].Text,
lv.Items[i].SubItems[1].Text);
else
FieldRelation.ValueMap.Add(" ",lv.Items[i].SubItems[1].Text);
}
this.Close();
}
/*public string TransType
{
get
{
return _strTransType;
}
}*/
private void lv_DoubleClick(object sender, System.EventArgs e)
{
if(lv.SelectedItems.Count<0)
return;
frmInputDialog winID=new frmInputDialog(lv.SelectedItems[0].Text);
winID.ShowDialog();
lv.Items[lv.SelectedIndices[0]].SubItems[1].Text=winID.XZ;
}
/*[System.Runtime.InteropServices.DllImport("user32.dll",EntryPoint="SendMessageA")]
public static extern int SendMessage(int hwnd,int wMsg,int wParam,int lParam);
[System.Runtime.InteropServices.DllImport("user32.dll",EntryPoint="FindWindow")]
public static extern int FindWindow(string lpClassName ,string lpWindowName);
/// <summary>
/// 向frmmain窗体发送消息已获得选定字段的所有值。
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>*/
private void cbZHLX_SelectedIndexChanged(object sender, System.EventArgs e)
{
/*if(cbZHLX.Text=="定值转换")
{
lv.Visible=true;
if(!blGetValues)
{
int hwnd=FindWindow(null,"数据转换工具");
SendMessage(hwnd,WM_GetZDZ,0,0);
}
lv.Items.Clear();
if(strsFields==null)
return;
if(blGetValues)
{
return;
}
blGetValues=true;
if(cbQDCFZ.Checked)
{
QDCFZ();
foreach(string strT in strsNoSameZDZ)
{
ListViewItem temp=new ListViewItem();
temp.Text=strT;
temp.SubItems.Add("");
lv.Items.Add(temp);
}
}
else
{
for(int i=0;i<strsFields.Length;i++)
{
ListViewItem temp=new ListViewItem();
temp.Text=strsFields[i];
temp.SubItems.Add("");
lv.Items.Add(temp);
}
}
}*/
if(cbZHLX.Text=="定值转换")
{
lv.Visible=true;
if(!_blGetValues)
{
_alFields=GetFieldValues();
_blGetValues=true;
for( int i=0; i<_alFields.Count; i++ )
{
ListViewItem temp=new ListViewItem();
string strText=_alFields[i].ToString();
temp.Text=strText;
if(this.FieldRelation.ValueMap.ContainsKey(strText))
temp.SubItems.Add(this.FieldRelation.ValueMap[strText].ToString());
else
temp.SubItems.Add("");
lv.Items.Add(temp);
}
}
}
else
{
lv.Visible=false;
}
}
public System.Collections.ArrayList GetFieldValues()
{
if(_oleConn.State==System.Data.ConnectionState.Closed )
{
try
{
_oleConn.Open();
}
catch(System.Exception a)
{
MessageBox.Show("*****连接数据源失败!("+a.Message+")*****");
return null;
}
}
System.Collections.ArrayList valueList = new System.Collections.ArrayList();
System.Data.OleDb.OleDbCommand dc=_oleConn.CreateCommand();
dc.CommandText="select distinct "+_cFieldRelation.SourceField+ " from "+_cFieldRelation.SourceTable;
System.Data.OleDb.OleDbDataReader dr=dc.ExecuteReader();
while(dr.Read())
{
valueList.Add( dr.GetValue(0).ToString() );
}
dr.Close();
dc.Dispose();
return valueList;
}
private void lv_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void miDateDropDot_Click(object sender, System.EventArgs e)
{
if(cbZHLX.Text=="定值转换")
{
for(int i=0;i<lv.Items.Count;i++)
{
lv.Items[i].SubItems[1].Text=lv.Items[i].Text.Replace(".","");
}
}
}
private void cmRightKeyRule_Popup(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -