Exemplo n.º 1
0
        ///<summary>Submits the queries to the database and makes query objects for each query with the results.  Returns false if one of the queries failed.</summary>
        public bool SubmitQueries(bool isShowMessage = false)
        {
            bool     hasRows         = false;
            bool     hasReportServer = !string.IsNullOrEmpty(PrefC.ReportingServer.DisplayStr);
            Graphics grfx            = Graphics.FromImage(new Bitmap(1, 1));
            string   displayText;
            ReportObjectCollection newReportObjects = new ReportObjectCollection();

            _sections.Add(new Section(AreaSectionType.Query, 0));
            for (int i = 0; i < _reportObjects.Count; i++)
            {
                if (_reportObjects[i].ObjectType == ReportObjectType.QueryObject)
                {
                    QueryObject query = (QueryObject)_reportObjects[i];
                    if (!query.SubmitQuery())
                    {
                        _actionCloseReportProgress?.Invoke();
                        MsgBox.Show(this, "There was an error generating this report."
                                    + (hasReportServer ? "\r\nVerify or remove the report server connection settings and try again." : ""));
                        return(false);
                    }
                    if (query.ReportTable.Rows.Count == 0)
                    {
                        continue;
                    }
                    hasRows    = true;
                    TotalRows += query.ReportTable.Rows.Count;
                    //Check if the query needs to be split up into sub queries.  E.g. one payment report query split up via payment type.
                    if (!String.IsNullOrWhiteSpace(query.ColumnNameToSplitOn))
                    {
                        ReportComplexEvent.Fire(ODEventType.ReportComplex, Lan.g("ReportComplex", "Creating Splits Based On") + " " + query.ColumnNameToSplitOn + "...");
                        //The query needs to be split up into sub queries every time the ColumnNameToSplitOn cell changes.
                        //Therefore, we need to create a separate QueryObject for every time the cell value changes.
                        string lastCellValue = "";
                        query.IsLastSplit = false;
                        QueryObject newQuery = null;
                        for (int j = 0; j < query.ReportTable.Rows.Count; j++)
                        {
                            if (query.ReportTable.Rows[j][query.ColumnNameToSplitOn].ToString() == lastCellValue)
                            {
                                if (newQuery == null)
                                {
                                    newQuery = query.DeepCopyQueryObject();
                                    newQuery.AddInitialHeader(newQuery.GetGroupTitle().StaticText, newQuery.GetGroupTitle().Font);
                                }
                                newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
                            }
                            else
                            {
                                //Must happen the first time through
                                if (newQuery != null)
                                {
                                    switch (newQuery.SplitByKind)
                                    {
                                    case SplitByKind.None:
                                        return(false);

                                    case SplitByKind.Enum:
                                        if (newQuery.ListEnumNames == null)
                                        {
                                            return(false);
                                        }
                                        displayText = newQuery.ListEnumNames[PIn.Int(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                                        newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                        newQuery.GetGroupTitle().StaticText = displayText;
                                        break;

                                    case SplitByKind.Definition:
                                        if (newQuery.DictDefNames == null)
                                        {
                                            return(false);
                                        }
                                        if (newQuery.DictDefNames.ContainsKey(PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())))
                                        {
                                            displayText = newQuery.DictDefNames[PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                                            newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                            newQuery.GetGroupTitle().StaticText = displayText;
                                        }
                                        else
                                        {
                                            newQuery.GetGroupTitle().StaticText = "Undefined";
                                        }
                                        break;

                                    case SplitByKind.Date:
                                        displayText = PIn.Date(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()).ToShortDateString();
                                        newQuery.GetGroupTitle().StaticText = displayText;
                                        newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                        break;

                                    case SplitByKind.Value:
                                        displayText = newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString();
                                        newQuery.GetGroupTitle().StaticText = displayText;
                                        newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                        break;
                                    }
                                    newQuery.SubmitQuery();
                                    newReportObjects.Add(newQuery);
                                }
                                if (newQuery == null && query.GetGroupTitle().StaticText != "")
                                {
                                    newQuery = query.DeepCopyQueryObject();
                                    newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
                                    newQuery.AddInitialHeader(newQuery.GetGroupTitle().StaticText, newQuery.GetGroupTitle().Font);
                                }
                                else
                                {
                                    newQuery = query.DeepCopyQueryObject();
                                    newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
                                }
                            }
                            lastCellValue = query.ReportTable.Rows[j][query.ColumnNameToSplitOn].ToString();
                        }
                        switch (newQuery.SplitByKind)
                        {
                        case SplitByKind.None:
                            return(false);

                        case SplitByKind.Enum:
                            if (newQuery.ListEnumNames == null)
                            {
                                return(false);
                            }
                            displayText = newQuery.ListEnumNames[PIn.Int(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                            newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                            newQuery.GetGroupTitle().StaticText = displayText;
                            break;

                        case SplitByKind.Definition:
                            if (newQuery.DictDefNames == null)
                            {
                                return(false);
                            }
                            if (newQuery.DictDefNames.ContainsKey(PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())))
                            {
                                displayText = newQuery.DictDefNames[PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
                                newQuery.GetGroupTitle().Size       = new Size((int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Width / grfx.DpiX * 100 + 2), (int)(grfx.MeasureString(displayText, newQuery.GetGroupTitle().Font).Height / grfx.DpiY * 100 + 2));
                                newQuery.GetGroupTitle().StaticText = displayText;
                            }
                            else
                            {
                                newQuery.GetGroupTitle().StaticText = Lans.g(this, "Undefined");
                            }
                            break;

                        case SplitByKind.Date:
                            newQuery.GetGroupTitle().StaticText = PIn.Date(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()).ToShortDateString();
                            break;

                        case SplitByKind.Value:
                            newQuery.GetGroupTitle().StaticText = newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString();
                            break;
                        }
                        newQuery.SubmitQuery();
                        newQuery.IsLastSplit = true;
                        newReportObjects.Add(newQuery);
                    }
                    else
                    {
                        newReportObjects.Add(_reportObjects[i]);
                    }
                }
                else
                {
                    newReportObjects.Add(_reportObjects[i]);
                }
            }
            if (!hasRows && isShowMessage)
            {
                _actionCloseReportProgress?.Invoke();
                MsgBox.Show(this, "The report has no results to show.");
                return(false);
            }
            _reportObjects = newReportObjects;
            return(true);
        }
Exemplo n.º 2
0
		public QueryObject DeepCopyQueryObject() {
			QueryObject queryObj=new QueryObject();
			queryObj.Name=this.Name;//Doesn't need to be a deep copy.
			queryObj.SectionName=this.SectionName;//Doesn't need to be a deep copy.
			queryObj.ReportObjectKind=this.ReportObjectKind;//Doesn't need to be a deep copy.
			queryObj._sections=this._sections;//Doesn't need to be a deep copy.
			queryObj._arrDataFields=this._arrDataFields;//Doesn't need to be a deep copy.
			queryObj._queryGroupValue=this._queryGroupValue;//Doesn't need to be a deep copy.
			queryObj._isCentered=this._isCentered;//Doesn't need to be a deep copy.
			queryObj._queryWidth=this._queryWidth;//Doesn't need to be a deep copy.
			queryObj._suppressHeaders=this._suppressHeaders;//Doesn't need to be a deep copy.
			queryObj._columnNameToSplitOn=this._columnNameToSplitOn;//Doesn't need to be a deep copy.
			queryObj._splitByKind=this._splitByKind;//Doesn't need to be a deep copy.
			queryObj.IsPrinted=this.IsPrinted;//Doesn't need to be a deep copy.
			queryObj.SummaryOrientation=this.SummaryOrientation;//Doesn't need to be a deep copy.
			queryObj.SummaryGroups=this.SummaryGroups;//Doesn't need to be a deep copy.
			queryObj._isLastSplit=this._isLastSplit;//Doesn't need to be a deep copy.
			queryObj._rowHeightValues=new List<int>();
			queryObj._isNegativeSummary=this._isNegativeSummary;
			for(int i=0;i<this._rowHeightValues.Count;i++) {
				queryObj._rowHeightValues.Add(this._rowHeightValues[i]);
			}
			ReportObjectCollection reportObjectsNew=new ReportObjectCollection();
			for(int i=0;i<this._reportObjects.Count;i++) {
				reportObjectsNew.Add(_reportObjects[i].DeepCopyReportObject());
			}
			queryObj._reportObjects=reportObjectsNew;
			//queryObj._query=this._query;
			queryObj._reportTable=new DataTable();
			//We only care about column headers at this point.  There is no easy way to copy an entire DataTable.
			for(int i=0;i<this.ReportTable.Columns.Count;i++) {
				queryObj._reportTable.Columns.Add(new DataColumn(this.ReportTable.Columns[i].ColumnName));
			}
			queryObj._exportTable=new DataTable();
			//We only care about column headers at this point.  There is no easy way to copy an entire DataTable.
			for(int i=0;i<this._exportTable.Columns.Count;i++) {
				queryObj._exportTable.Columns.Add(new DataColumn(this._exportTable.Columns[i].ColumnName));
			}
			List<string> enumNamesNew=new List<string>();
			if(this._listEnumNames!=null) {
				for(int i=0;i<this._listEnumNames.Count;i++) {
					enumNamesNew.Add(this._listEnumNames[i]);
				}
			}
			queryObj._listEnumNames=enumNamesNew;
			Dictionary<long,string> defNamesNew=new Dictionary<long,string>();
			if(this._dictDefNames!=null) {
				foreach(long defNum in _dictDefNames.Keys) {
					defNamesNew.Add(defNum,this._dictDefNames[defNum]);
				}
			}
			queryObj._dictDefNames=defNamesNew;
			return queryObj;
		}
Exemplo n.º 3
0
		///<summary>Submits the queries to the database and makes query objects for each query with the results.  Returns false if one of the queries failed.</summary>
		public bool SubmitQueries(){
			bool hasRows=false;
			Graphics grfx=Graphics.FromImage(new Bitmap(1,1));
			string displayText;
			ReportObjectCollection newReportObjects=new ReportObjectCollection();
			_sections.Add(new Section(AreaSectionKind.Query,0));
			for(int i=0;i<_reportObjects.Count;i++) {
				if(_reportObjects[i].ReportObjectKind==ReportObjectKind.QueryObject) {
					QueryObject query=(QueryObject)_reportObjects[i];
					if(!query.SubmitQuery()) {
						return false;
					}
					if(query.ReportTable.Rows.Count==0) {
						continue;
					}
					hasRows=true;
					//Check if the query needs to be split up into sub queries.  E.g. one payment report query split up via payment type.
					if(!String.IsNullOrWhiteSpace(query.ColumnNameToSplitOn)) { 
						//The query needs to be split up into sub queries every time the ColumnNameToSplitOn cell changes.  
						//Therefore, we need to create a separate QueryObject for every time the cell value changes.
						string lastCellValue="";
						query.IsLastSplit=false;
						QueryObject newQuery=null;
						for(int j=0;j<query.ReportTable.Rows.Count;j++) {
							if(query.ReportTable.Rows[j][query.ColumnNameToSplitOn].ToString()!=lastCellValue) {
								//Must happen the first time through
								if(newQuery!=null) {
									switch(newQuery.SplitByKind) {
										case SplitByKind.None:
											return false;
										case SplitByKind.Enum:
											if(newQuery.ListEnumNames==null) {
												return false;
											}
											displayText=newQuery.ListEnumNames[PIn.Int(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
											newQuery.GetGroupTitle().Size=new Size((int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Width/grfx.DpiX*100+2),(int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Height/grfx.DpiY*100+2));
											newQuery.GetGroupTitle().StaticText=displayText;
											break;
										case SplitByKind.Definition:
											if(newQuery.DictDefNames==null) {
												return false;
											}
											if(newQuery.DictDefNames.ContainsKey(PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()))) {
												displayText=newQuery.DictDefNames[PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
												newQuery.GetGroupTitle().Size=new Size((int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Width/grfx.DpiX*100+2),(int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Height/grfx.DpiY*100+2));
												newQuery.GetGroupTitle().StaticText=displayText;
											}
											else {
												newQuery.GetGroupTitle().StaticText="Undefined";
											}
											break;
										case SplitByKind.Date:
											displayText=PIn.Date(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()).ToShortDateString();
											newQuery.GetGroupTitle().StaticText=displayText;
											newQuery.GetGroupTitle().Size=new Size((int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Width/grfx.DpiX*100+2),(int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Height/grfx.DpiY*100+2));
											break;
										case SplitByKind.Value:
											displayText=newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString();
											newQuery.GetGroupTitle().StaticText=displayText;
											newQuery.GetGroupTitle().Size=new Size((int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Width/grfx.DpiX*100+2),(int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Height/grfx.DpiY*100+2));
											break;
									}
									newQuery.SubmitQuery();
									newReportObjects.Add(newQuery);
								}
								if(newQuery==null && query.GetGroupTitle().StaticText!="") {
									newQuery=query.DeepCopyQueryObject();
									newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
									newQuery.AddInitialHeader(newQuery.GetGroupTitle().StaticText,newQuery.GetGroupTitle().Font);
								}
								else {
									newQuery=query.DeepCopyQueryObject();
									newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
								}
							}
							else {
								newQuery.ReportTable.ImportRow(query.ReportTable.Rows[j]);
							}
							lastCellValue=query.ReportTable.Rows[j][query.ColumnNameToSplitOn].ToString();
						}
						switch(newQuery.SplitByKind) {
							case SplitByKind.None:
								return false;
							case SplitByKind.Enum:
								if(newQuery.ListEnumNames==null) {
									return false;
								}
								displayText=newQuery.ListEnumNames[PIn.Int(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
								newQuery.GetGroupTitle().Size=new Size((int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Width/grfx.DpiX*100+2),(int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Height/grfx.DpiY*100+2));
								newQuery.GetGroupTitle().StaticText=displayText;
								break;
							case SplitByKind.Definition:
								if(newQuery.DictDefNames==null) {
									return false;
								}
								if(newQuery.DictDefNames.ContainsKey(PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()))) {
									displayText=newQuery.DictDefNames[PIn.Long(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString())];
									newQuery.GetGroupTitle().Size=new Size((int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Width/grfx.DpiX*100+2),(int)(grfx.MeasureString(displayText,newQuery.GetGroupTitle().Font).Height/grfx.DpiY*100+2));
									newQuery.GetGroupTitle().StaticText=displayText;
								}
								else {
									newQuery.GetGroupTitle().StaticText=Lans.g(this,"Undefined");
								}
								break;
							case SplitByKind.Date:
								newQuery.GetGroupTitle().StaticText=PIn.Date(newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString()).ToShortDateString();
								break;
							case SplitByKind.Value:
								newQuery.GetGroupTitle().StaticText=newQuery.ReportTable.Rows[0][query.ColumnNameToSplitOn].ToString();
								break;
						}
						newQuery.SubmitQuery();
						newQuery.IsLastSplit=true;
						newReportObjects.Add(newQuery);
					}
					else {
						newReportObjects.Add(_reportObjects[i]);
					}
				}
				else {
					newReportObjects.Add(_reportObjects[i]);
				}
			}
			if(!hasRows) {
				MsgBox.Show(this,"The report has no results to show.");
				return false;
			}
			_reportObjects=newReportObjects;
			return true;
		}