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

📄 runrepoertviewctl.cs

📁 树形逻辑报表程序源码,能根居元数据定义拖拉开发新的报表.
💻 CS
📖 第 1 页 / 共 4 页
字号:
				button_reportexport.Enabled = IsRunned;
				return false;
			}

			button_stop.Enabled = true;

			try
			{
				//取得有效的条件表达式
				string conntionexpstr = getContitionExp();

				//MessageBox.Show(this,conntionexpstr);

				if (conntionexpstr.Length>0)
				{
					//重设置数据源
					DataDynamics.ActiveReports.DataSources.OleDBDataSource datasource = (DataDynamics.ActiveReports.DataSources.OleDBDataSource)currentreport.DataSource;
					datasource.ConnectionString = TreeConnection.connstr;     

					if (reportconfiginfo.datasourceSQL.Length>0)//从字典生成的SQL
					{
						if (reportconfiginfo.IsNotSqlStrInDict)
							datasource.SQL = "SELECT * FROM " + reportconfiginfo.datasourceSQL + " WHERE " + conntionexpstr; 
						else
							datasource.SQL = "SELECT * FROM (" +reportconfiginfo.datasourceSQL + ") AS abcd WHERE " + conntionexpstr; 
					}
					else
					{
						datasource.SQL = "SELECT * FROM (" + originalSQL + ") AS abcd WHERE " + conntionexpstr; 
					}
				}

				//根据用户配置设置控件的可见性
				doShowOrHideControlAction();

				//运行生成报表
				currentreport.Run(true);
			}
			catch
			{
				IsRunned = false;
				button_reportexport.Enabled = IsRunned;

				return false;
			}

			IsRunned = true;
			button_stop.Enabled = IsRunned;
			button_reportexport.Enabled = IsRunned;

			return true;

		}


		/// <summary>
		/// initSearchFields() - 根据配置,生成查询界面的各控件,并给出表达式格式,存放在Tag中
		/// </summary>
		public bool initSearchFields()
		{
			//当组控件不可见或太小时,不进行控件内容的生成,直接返回false
			if (groupBox_searchcontition.Visible==false || groupBox_searchcontition.Width <200)
				return false;

			groupcontitionwidth=groupBox_searchcontition.Width;

			groupBox_searchcontition.Controls.Clear();
			groupBox_searchcontition.Height = 43;

			//取报表的信息,如果取不到,不进行控件内容的生成,直接返回false
			if(reportconfiginfo==null)
				return false;
			DataTable searchfields = reportconfiginfo.getSearchfieldsInfo();
			if (searchfields==null)
				return false;

			Label fieldlable;
			//控件内容的生成的开始点(位置)
			Point currentpos = new Point(16,18);
			int fontsize = 7;
			int controlheigt = 20;

			foreach( DataRow rw in searchfields.Rows)
			{
				string typechar = ""+ rw["DataType"];
				int ctlwidth = rw.IsNull("ControlWidth")?0:Convert.ToInt32(rw["ControlWidth"].ToString());
				ctlwidth = (ctlwidth==0)?1:ctlwidth;
				
				//显示的标题文本
				string lablestr = "" + rw["CLableCaption"];//多语言化时要替换它的内容
				if(lablestr.Length==0)
					lablestr = ""+rw["DataField"];

				int lablelength = countlablesize(lablestr);
				
				if (typechar.Equals("B") && "CheckBox".Equals(""+ rw["ControlClass"]))
				{
					//产生一个控件
					CheckBox fieldcheckbox = new CheckBox();
					fieldcheckbox.Text = lablestr;
					fieldcheckbox.TextAlign = ContentAlignment.BottomLeft;
					fieldcheckbox.Width = lablelength*fontsize + 28;
					fieldcheckbox.Height = controlheigt;

					//检查是否要换行显示?
					currentpos = CheckAndWrapToNextRow(currentpos,fieldcheckbox.Width,0,"N",groupBox_searchcontition);
					fieldcheckbox.Location = currentpos;
					groupBox_searchcontition.Controls.Add(fieldcheckbox);

					fieldcheckbox.Tag = ""+rw["DataField"]+"=@boolean@";
					controlsarray.Add(fieldcheckbox);
					datatypesarray.Add("B");
					ctltypesarray.Add("CheckBox");

					//计算下一个控件的开始位置
					currentpos = new Point(currentpos.X+fieldcheckbox.Width+20,currentpos.Y);
				}
				else
				{
					fieldlable = new System.Windows.Forms.Label();
				
					//标题控件
					fieldlable.BorderStyle = BorderStyle.FixedSingle;
					fieldlable.TextAlign = ContentAlignment.BottomRight;
					fieldlable.Text = lablestr;
					fieldlable.Width = lablelength*fontsize+16;
					fieldlable.ImageList = imageList_ctl;
					fieldlable.ImageIndex = 3;
					fieldlable.ImageAlign = ContentAlignment.BottomLeft;
					fieldlable.Height = controlheigt;

					//检查是否要换行显示?
					currentpos = CheckAndWrapToNextRow(currentpos,fieldlable.Width,ctlwidth*fontsize,""+rw["EqualOrRange"],groupBox_searchcontition);
					fieldlable.Location = currentpos;
					groupBox_searchcontition.Controls.Add(fieldlable);

					currentpos = new Point(currentpos.X+fieldlable.Width,currentpos.Y);

					if(typechar.Equals("D") && "DateTimePicker".Equals(""+ rw["ControlClass"]))//时间控件
					{
						//产生一个控件
						DateTimePicker picker = new DateTimePicker();
						picker.Format = DateTimePickerFormat.Custom;
						picker.Width = ctlwidth*fontsize;
						picker.Height = controlheigt;
						picker.Location = currentpos;
						groupBox_searchcontition.Controls.Add(picker);

						if ("Y".Equals(""+rw["EqualOrRange"]))//from ....to ....范围
						{
							//from控件
							picker.Tag = ""+rw["DataField"]+">='@text@'";//多数据库时,要考虑不同类数据库间的差异性
							//picker.Tag = ""+rw["DataField"]+">={ts'@text@'}";
							picker.Value = new DateTime(2000,1,1);
							controlsarray.Add(picker);
							datatypesarray.Add("D");
							ctltypesarray.Add("DateTimePicker");
							currentpos = new Point(currentpos.X+picker.Width,currentpos.Y);
				
							//中间的“-”
							fieldlable = new System.Windows.Forms.Label();
							fieldlable.Text = "-";
							fieldlable.TextAlign = ContentAlignment.BottomLeft;
							fieldlable.Width = 8;
							fieldlable.Height = controlheigt;
							fieldlable.Location = currentpos;
							groupBox_searchcontition.Controls.Add(fieldlable);
							currentpos = new Point(currentpos.X+fieldlable.Width,currentpos.Y);

							//to控件
							picker = new DateTimePicker();
							picker.Format = DateTimePickerFormat.Short;
							picker.Width = ctlwidth*fontsize;
							picker.Height = controlheigt;
							picker.Location = currentpos;
							groupBox_searchcontition.Controls.Add(picker);
							
							picker.Tag = ""+rw["DataField"]+"<='@text@'";//多数据库时,要考虑不同类数据库间的差异性
							//picker.Tag = ""+rw["DataField"]+"<={ts'@text@'}";
							controlsarray.Add(picker);
							datatypesarray.Add("D");
							ctltypesarray.Add("DateTimePicker");
							currentpos = new Point(currentpos.X+picker.Width+20,currentpos.Y);
						}
						else
						{
							//picker.Tag = ""+rw["DataField"]+"={ts'@text@'}";
							picker.Tag = ""+rw["DataField"]+"='@text@'";//多数据库时,要考虑不同类数据库间的差异性
							
							controlsarray.Add(picker);
							datatypesarray.Add("D");
							ctltypesarray.Add("DateTimePicker");

							currentpos = new Point(currentpos.X+picker.Width+20,currentpos.Y);
						}

					}
					else if("ComboBox".Equals(""+ rw["ControlClass"]))
					{
						OleDbConnection conn = new OleDbConnection();
						conn.ConnectionString = TreeConnection.connstr;
						conn.Open();
						try
						{
							DataRow manageinfo_rw = reportconfiginfo.getManageInfo().Rows[0];
							string datadictid = "" + manageinfo_rw["BusinessDictID"];
							string sqlstr = "";
						
							//分各种情况构造SQL语句
							if (datadictid.Length>0)
							{
								System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("select ObjectName,SQLStr from TreeDbObjectInfos where ObjectName='"+ datadictid +"'",conn);
								System.Data.OleDb.OleDbDataReader rd = cmd.ExecuteReader();

								//查数据字典
								if(rd.Read())
								{
									sqlstr = ("" + rd["SQLStr"]).Trim();
								}
								rd.Close();

								//如果数据字典中设置了SQL语句,则使用SQL语句,否则使用datadictid作为表名或视图名
								if(sqlstr.Length>0)
								{
									sqlstr = "SELECT DISTINCT " + rw["DataField"] + " FROM (" + sqlstr + ") AS abcd";
								}
								else
								{
									sqlstr = "SELECT DISTINCT " + rw["DataField"] + " FROM " + datadictid ;
								}
							}
							else //没有设置数据字典,从报表的数据源对象中取SQL
							{
								string SQLstr = "";
								try
								{
									SQLstr = ((DataDynamics.ActiveReports.DataSources.OleDBDataSource) currentreport.DataSource).SQL;
								}
								catch
								{
									SQLstr = "";
								}
			
								if (SQLstr==null || SQLstr.Equals(""))
								{
									try
									{
										SQLstr = ((DataDynamics.ActiveReports.DataSources.SqlDBDataSource) currentreport.DataSource).SQL;
									}
									catch
									{
										SQLstr = "";
									}
								}

								if (!(""+SQLstr).Equals(""))
								{//取到了SQL
									sqlstr = "SELECT DISTINCT " + rw["DataField"] + " FROM (" + SQLstr + ") AS abcd";
								}
							}

							System.Data.OleDb.OleDbDataAdapter adpter = new System.Data.OleDb.OleDbDataAdapter(sqlstr,conn);
							System.Data.DataSet dataset = new DataSet();
							adpter.Fill(dataset);

							ComboBox combobx = new ComboBox();
							combobx.Width = ctlwidth*fontsize;
							combobx.Height = controlheigt;
							combobx.Location = currentpos;
							groupBox_searchcontition.Controls.Add(combobx);

							//初始为空值
							combobx.Items.Add("");

							//combobx.DataSource = dataset.Tables[0];
							//combobx.DisplayMember = rw["DataField"].ToString();
							foreach( DataRow contentrow in dataset.Tables[0].Rows)
							{
								combobx.Items.Add(contentrow[rw["DataField"].ToString()]);
							}

							combobx.SelectedIndex = 0;
							
							if ("Y".Equals(""+rw["EqualOrRange"]))//from ....to ....范围
							{
								//from控件
								if (typechar.Equals("N")||typechar.Equals("B"))
								{
									combobx.Tag = ""+rw["DataField"]+">=@text@";
									datatypesarray.Add("N");
								}
								else if (typechar.Equals("D"))
								{
									//combobx.Tag = ""+rw["DataField"]+">={ts'@text@'}";//多数据库时,要考虑不同类数据库间的差异性
									combobx.Tag = ""+rw["DataField"]+">='@text@'";//多数据库时,要考虑不同类数据库间的差异性
									datatypesarray.Add("D");
								}
								else
								{ 
									combobx.Tag = ""+rw["DataField"]+">='@text@'";
									datatypesarray.Add("C");
								}
							
								controlsarray.Add(combobx);
								ctltypesarray.Add("ComboBox");
								currentpos = new Point(currentpos.X+combobx.Width,currentpos.Y);
				
								//中间的“-”
								fieldlable = new System.Windows.Forms.Label();
								fieldlable.Text = "-";
								fieldlable.Width = 8;
								fieldlable.Height = controlheigt;
								fieldlable.Location = currentpos;
								groupBox_searchcontition.Controls.Add(fieldlable);
								currentpos = new Point(currentpos.X+fieldlable.Width,currentpos.Y);

								//to控件
								combobx = new ComboBox();
								combobx.Width = ctlwidth*fontsize;
								combobx.Height = controlheigt;
								combobx.Location = currentpos;
								groupBox_searchcontition.Controls.Add(combobx);

								//初始为空值
								combobx.Items.Add("");

								//combobx.DataSource = dataset.Tables[0];
								//combobx.DisplayMember = rw["DataField"].ToString();
								foreach( DataRow contentrow in dataset.Tables[0].Rows)
								{
									combobx.Items.Add(contentrow[rw["DataField"].ToString()]);
								}
								combobx.SelectedIndex = 0;

								if (typechar.Equals("N")||typechar.Equals("B"))
								{
									combobx.Tag = ""+rw["DataField"]+"<=@text@";
									datatypesarray.Add("N");
								}
								else if (typechar.Equals("D"))
								{
									//combobx.Tag = ""+rw["DataField"]+"<={ts'@text@'}";//多数据库时,要考虑不同类数据库间的差异性
									combobx.Tag = ""+rw["DataField"]+"<='@text@'";//多数据库时,要考虑不同类数据库间的差异性
									datatypesarray.Add("D");
								}
								else
								{ 
									combobx.Tag = ""+rw["DataField"]+"<='@text@'";
									datatypesarray.Add("C");
								}
							
								controlsarray.Add(combobx);
								ctltypesarray.Add("ComboBox");
								currentpos = new Point(currentpos.X+combobx.Width+20,currentpos.Y);
							}
							else
							{
								if (typechar.Equals("N")||typechar.Equals("B"))
								{
									combobx.Tag = ""+rw["DataField"]+"=@text@";
									datatypesarray.Add("N");
								}
								else if (typechar.Equals("D"))
								{
									//combobx.Tag = ""+rw["DataField"]+"={ts'@text@'}";//多数据库时,要考虑不同类数据库间的差异性
									combobx.Tag = ""+rw["DataField"]+"='@text@'";//多数据库时,要考虑不同类数据库间的差异性
									datatypesarray.Add("D");
								}
								else
								{ 
									combobx.Tag = ""+rw["DataField"]+"='@text@'";
									datatypesarray.Add("C");
								}
							
								controlsarray.Add(combobx);
								ctltypesarray.Add("ComboBox");
								currentpos = new Point(currentpos.X+combobx.Width+20,currentpos.Y);
							}
						}
						catch (Exception er)
						{
							System.Diagnostics.Debug.WriteLine("出错:"+er.Message);
						}

⌨️ 快捷键说明

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