⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 treecontitonexpdlg.cs

📁 树形逻辑报表程序源码,能根居元数据定义拖拉开发新的报表.
💻 CS
📖 第 1 页 / 共 2 页
字号:
		}
		#endregion


		class fieldinfo 
		{
			public string name;
			public string descript;
			public string type;

			public fieldinfo(string _name, string _descript, string _type)
			{
			   name = _name;
			   descript = _descript;
			   type = _type;
			}

			public override string ToString()
			{
				return descript;
			}
		}
		/// <summary>
		/// initFieldsList( string datadictionid ) - 从数据字典中取信息,初始化数据域列表控件
		/// </summary>
		public void initFieldsList( ActiveReport report )
		{
			if (report==null)
				return;

			string SQLstr = "";
			try
			{
				SQLstr = ((OleDBDataSource) report.DataSource).SQL;
			}
			catch
			{
				SQLstr = "";
			}
			
			if (SQLstr==null || SQLstr.Equals(""))
			{
				try
				{
					SQLstr = ((SqlDBDataSource) report.DataSource).SQL;
				}
				catch
				{
					SQLstr = "";
				}
			}

			
			if (SQLstr==null || SQLstr.Equals(""))
			{//是其它类型的数据源,直接从数据域里取信息
				for(int i=0; i<report.Fields.Count; i++)
				{
					comboBox_field.Items.Add(new fieldinfo(report.Fields[i].Name,report.Fields[i].Name,"C"));
				}
			}
			else
			{
				OleDbConnection conn = new OleDbConnection();
				conn.ConnectionString = TreeConnection.connstr;
				conn.Open();

				try
				{
					OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM ("+SQLstr+") AS ABCD WHERE 'A'='B'",conn);
					DataSet dataset = new DataSet();

					adapter.Fill(dataset);
					DataTable table = dataset.Tables[0];
			
					foreach ( DataColumn col in table.Columns)
					{
						string fieldtype;

						if (col.DataType.Name.ToLower().IndexOf("date")>=0)
						{
							fieldtype = "D";
						}
						else if(col.DataType.Name.ToLower().IndexOf("int")>=0 || col.DataType.Name.ToLower().IndexOf("num")>=0 || col.DataType.Name.ToLower().IndexOf("float")>=0 || col.DataType.Name.ToLower().IndexOf("double")>=0)
						{
							fieldtype = "N";
						}
						else if(col.DataType.Name.ToLower().IndexOf("bool")>=0)
						{
							fieldtype = "B";
						}
						else
						{
							fieldtype = "C";
						}

						comboBox_field.Items.Add(new fieldinfo(col.ColumnName,col.ColumnName,fieldtype));
					}

				}
				catch
				{}

				conn.Close();
			}

		}

		/// <summary>
		/// initFieldsList( string datadictionid ) - 从数据字典中取信息,初始化数据域列表控件
		/// </summary>
		public void initFieldsList( string datadictionid )
		{
			OleDbConnection conn = new OleDbConnection();
			conn.ConnectionString = TreeConnection.connstr;
			conn.Open();

			OleDbCommand cmd = new OleDbCommand("SELECT itemname,EItemDescription,CItemDescription,HItemDescription,TypeOfData,LengthOfData FROM TreeDbObjectInfos_items WHERE ObjectName='" + datadictionid +"'", conn);
			OleDbDataReader rd = cmd.ExecuteReader();
 
			while (rd.Read())
			{
				string fieldtype;

				if ((""+rd["TypeOfData"]).ToLower().IndexOf("date")>=0)
				{
					fieldtype = "D";
				}
				else if((""+rd["TypeOfData"]).ToLower().IndexOf("int")>=0 || (""+rd["TypeOfData"]).ToLower().IndexOf("num")>=0 || (""+rd["TypeOfData"]).ToLower().IndexOf("float")>=0 || (""+rd["TypeOfData"]).ToLower().IndexOf("double")>=0)
				{
					fieldtype = "N";
				}
				else if((""+rd["TypeOfData"]).ToLower().IndexOf("bool")>=0)
				{
					fieldtype = "B";
				}
				else
				{
					fieldtype = "C";
				}

				comboBox_field.Items.Add(new fieldinfo(""+rd["itemname"],""+rd["itemname"]+" ["+rd["CItemDescription"]+"]",fieldtype));

			}

			rd.Close();
			conn.Close();
		}
		
		
		private void comboBox_field_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (comboBox_field.SelectedIndex<0)
				return;

			fieldinfo info = (fieldinfo)comboBox_field.SelectedItem;

			comboBox_operate.Items.Clear();

			if("N".Equals(info.type) || "D".Equals(info.type))
			{
				comboBox_operate.Items.Add("=");
				comboBox_operate.Items.Add(">=");
				comboBox_operate.Items.Add("<=");
				comboBox_operate.Items.Add(">");
				comboBox_operate.Items.Add("<");
			}
			else if("B".Equals(info.type))
			{
				comboBox_operate.Items.Add("=");
			}
			else
			{
				comboBox_operate.Items.Add("=");
				comboBox_operate.Items.Add("包含");
				comboBox_operate.Items.Add(">=");
				comboBox_operate.Items.Add("<=");
				comboBox_operate.Items.Add(">");
				comboBox_operate.Items.Add("<");
			}

			comboBox_operate.Text = "=";
			checkBox_not.Checked =  false;
		}

		private void TreeContitonExpDlg_Load(object sender, System.EventArgs e)
		{
			radioButton_and.Checked =true;
		}

		private void button_add_Click(object sender, System.EventArgs e)
		{
			if (comboBox_field.Text.Length==0)
				return;

			fieldinfo field = (fieldinfo)comboBox_field.SelectedItem;

			string express = "(";
			if(textBox_value.Text.Length==0)
			{
				express += field.name + " Is NULL";
				
				if("C".Equals(field.type))
					express += " OR " + field.name + "=''";
			}
			else
			{
				string datastr = "";
				if( "D".Equals(field.type))
				{
					try
					{
						datastr = DateTime.Parse(textBox_value.Text).ToString();
					}
					catch
					{
						MessageBox.Show(this, "你输入日期格式必须合法,格式为: 2002-12-23 11:20:05");
						return;
					}
                    
					//express += field.name + comboBox_operate.Text + "{ts'" + datastr +"'}";
					express += field.name + comboBox_operate.Text + "'" + datastr +"'";//不同种类数据库,日期表示方法不一样
				}
				else if("N".Equals(field.type))
				{
					try
					{
						datastr = System.Decimal.Parse(textBox_value.Text).ToString();
					}
					catch
					{
						MessageBox.Show(this, "你必须输入一个数值型数据!!");
						return;
					}
                    
					express += field.name + comboBox_operate.Text + datastr;
				}
				else if("B".Equals(field.type))
				{
					datastr = textBox_value.Text.ToLower().Trim();

					if ("true".Equals(datastr)||"false".Equals(datastr))
					{
						express += field.name + comboBox_operate.Text + datastr;
					}
					else
					{
						MessageBox.Show(this,"只能输入true或false");
						return;
					}
				}
				else
				{
					if ("包含".Equals(comboBox_operate.Text))
						express += field.name + " LIKE '%" + textBox_value.Text + "%'";
					else
						express += field.name + comboBox_operate.Text + "'"+textBox_value.Text+"'";
				}

   			}

			express += ")";

			if(checkBox_not.Checked)
				express = "NOT " + express;

			string relatestr = "OR";
			if(radioButton_and.Checked)
				relatestr = "AND";

			textBox_contition.Text = textBox_contition.Text.Trim();
			if (textBox_contition.Text.Length>0)
				express = " " + relatestr + " " + express;

			textBox_contition.Text += express;
   
			comboBox_field.SelectedIndex = -1;
			checkBox_not.Checked = false;
			comboBox_operate.Items.Clear();
			textBox_value.Text = "";
		}

		private void button_ok_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.OK;
			this.Close();
		}

		private void button_cancel_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			this.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -