private UltraGridCell mFindCellByRowAndColumnInfo(UltraGridRow objRow, Mars_RowColumnInfo oColInfo) { Logger.logBegin("mFindCellByRowAndColumnInfo"); try { if (objRow == null) { Logger.Error("mFindCellByRowAndColumnInfo", "Row is null"); return(null); } switch (oColInfo.CurrentDataType) { case E_RowColumnType.eType_Number: int iCurrentColId = 0; for (int i = 0; i < objRow.Cells.Count; i++) { UltraGridCell objCurrentCell = objRow.Cells[i]; if (objCurrentCell.Column.Hidden) { continue; } if (iCurrentColId == oColInfo.convertData2Int()) { Logger.Info("mFindCellByRowAndColumnInfo", "find cell"); return(objCurrentCell); } iCurrentColId++; } break; case E_RowColumnType.eType_String: string strColumnName = "", strColumnInnderName = ""; for (int i = 0; i < objRow.Cells.Count; i++) { UltraGridCell objCurrentCell = objRow.Cells[i]; if (objCurrentCell.Column.Hidden) { continue; } strColumnName = objCurrentCell.Column.Header.Caption; strColumnInnderName = objCurrentCell.Column.Key; if ((string.Compare(strColumnName, oColInfo.currentData.ToString(), true) == 0) || ((string.Compare(strColumnInnderName, oColInfo.currentData.ToString(), true) == 0))) { Logger.Info("mFindCellByRowAndColumnInfo", "find cell"); return(objCurrentCell); } } break; } return(null); } finally { Logger.logEnd("mFindCellByRowAndColumnInfo"); } }
private void mClickAtGrid(string strMethodName, object objRowNumber, object objColumnName, MOUSE_BUTTON clickButton, int iClickTimes = 1) { Logger.logBegin(strMethodName); PrepareForReplay(); string strErr = ""; try { if ((objRowNumber == null) || (objColumnName == null)) { this.ReplayReportStep(strMethodName, EventStatus.EVENTSTATUS_FAIL, new object[] { strErr = string.Format("parameter should not be null. Parameters:Row-[{0}], ColumnName-[{1}]", objRowNumber == null?"null":objRowNumber.ToString(), objColumnName == null?"null":objColumnName.ToString()) } ); this.ReplayThrowError(string.Format(strErr)); return; } int iNumber = Int32.Parse(objRowNumber.ToString()); string strColumn = objColumnName.ToString(); UltraGrid objGrid = (UltraGrid)SourceControl; if (iNumber > objGrid.Rows.Count) { strErr = string.Format("Row number [{0}] is larger than the current Grid contains :[{1}]", iNumber, objGrid.Rows.Count); ReportError(strMethodName, strErr); return; } if (objGrid.Rows.Count == 0) { strErr = "Row number is Zero, can't rightClick on Content. "; ReportError(strMethodName, strErr); return; } UltraGridRow objRow = objGrid.Rows[iNumber]; Mars_RowColumnInfo objRowInfo = new Mars_RowColumnInfo(objRowNumber), objColunInfo = new Mars_RowColumnInfo(objColumnName); UltraGridCell objCell = this.mFindCellByRowAndColumnInfo(objRow, objColunInfo); if (objCell == null) { strErr = string.Format("No such Column can be found on the table:[{0}]", strColumn); ReportError(strMethodName, strErr); return; } UIElement objUIElement = objCell.GetUIElement(); Thread.Sleep(200); if (objUIElement == null) { strErr = string.Format("Can't get UIElement: Cell is invisible,no such cell or exceptions? \r\n\tRow:[{0}]\r\n\tColumn:[{1}]", iNumber, strColumn); ReportError(strMethodName, strErr); return; } Rectangle rect = objUIElement.Rect; Point pt = rect.Location; if (iClickTimes != 1) { base.MouseDblClick(pt.X + rect.Width / 2, pt.Y + rect.Height / 2, clickButton); } else { base.MouseClick(pt.X + rect.Width / 2, pt.Y + rect.Height / 2, clickButton); } this.ReplayReportStep(strMethodName, EventStatus.EVENTSTATUS_GENERAL, new object[] { "Passed" }); } catch (Exception e) { strErr = string.Format("Can't continue to RightClick, Exceptions :[{0}]", e.Message); Logger.Error(strMethodName, strErr, e); this.ReplayReportStep("RightClick", EventStatus.EVENTSTATUS_FAIL, new Object[] { strErr }); this.ReplayThrowError(string.Format(strErr)); } }
/** **/ public void MarsTigerActiveCell(params object[] arrRC) { Logger.logBegin("MarsTigerActiveCell"); if (arrRC.Length != 2) { Logger.Error("MarsTigerActiveCell", "Only two parameters are accepted. "); return; } PrepareForReplay(); object oRow = arrRC[0], oColumn = arrRC[1]; UltraGrid objGrid = (UltraGrid)SourceControl; string strError = ""; Mars_RowColumnInfo oRowInfo = new Mars_RowColumnInfo(oRow), oColInfo = new Mars_RowColumnInfo(oColumn); try { if ((objGrid.Rows == null ? -1 : objGrid.Rows.Count) <= 0) { base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, "RowCount is 0" }); return; } if (oRowInfo.CurrentDataType == E_RowColumnType.eType_String) { // the first column of the row with fixed caption, which should be implement later throw new NotImplementedException(); } /** find cells **/ UltraGridRow objRow = mFindRowByRowNumber(oRowInfo.convertData2Int(), objGrid); if (objRow == null) { strError = string.Format("no such row number [{0}] is availble, row number stars 0", objRow); base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, strError }); return; } /** find cells by oColumn, int or header **/ UltraGridCell objCell = mFindCellByRowAndColumnInfo(objRow, oColInfo); if (objCell == null) { strError = string.Format("Can't find sepecial cell. \r\n\tRow:[{0}]\r\n\tColumn:[{1}]", oRow, oColumn); base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, strError }); return; } /** 获得 cell的rectangle, 然后调用mouse事件 **/ UIElement objUIElement = objCell.GetUIElement(); Thread.Sleep(200); if (objUIElement == null) { strError = string.Format("Can't get UIElement: Cell is invisible,no such cell or exceptions? \r\n\tRow:[{0}]\r\n\tColumn:[{1}]", oRow, oColumn); base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, strError }); return; } Rectangle rect = objUIElement.Rect; Point pt = rect.Location; base.MouseClick(pt.X + rect.Width / 2, pt.Y + rect.Height / 2, MOUSE_BUTTON.LEFT_MOUSE_BUTTON); //LeftMouseClick(pt.X, pt.Y); } finally { Logger.logEnd("MarsTigerActiveCell"); } }
private UltraGridCell mFindCellByRowAndColumnInfo(UltraGridRow objRow, Mars_RowColumnInfo oColInfo) { Logger.logBegin("mFindCellByRowAndColumnInfo"); try { if (objRow == null) { Logger.Error("mFindCellByRowAndColumnInfo", "Row is null"); return null; } switch (oColInfo.CurrentDataType) { case E_RowColumnType.eType_Number: int iCurrentColId = 0; for (int i = 0; i < objRow.Cells.Count; i++) { UltraGridCell objCurrentCell = objRow.Cells[i]; if (objCurrentCell.Column.Hidden) continue; if (iCurrentColId == oColInfo.convertData2Int()) { Logger.Info("mFindCellByRowAndColumnInfo", "find cell"); return objCurrentCell; } iCurrentColId++; } break; case E_RowColumnType.eType_String: string strColumnName = "", strColumnInnderName = ""; for (int i = 0; i < objRow.Cells.Count; i++) { UltraGridCell objCurrentCell = objRow.Cells[i]; if (objCurrentCell.Column.Hidden) continue; strColumnName = objCurrentCell.Column.Header.Caption; strColumnInnderName = objCurrentCell.Column.Key; if ((string.Compare(strColumnName, oColInfo.currentData.ToString(), true) == 0) || ((string.Compare(strColumnInnderName, oColInfo.currentData.ToString(), true) == 0))) { Logger.Info("mFindCellByRowAndColumnInfo", "find cell"); return objCurrentCell; } } break; } return null; } finally { Logger.logEnd("mFindCellByRowAndColumnInfo"); } }
private void mClickAtGrid(string strMethodName, object objRowNumber, object objColumnName, MOUSE_BUTTON clickButton, int iClickTimes = 1) { Logger.logBegin(strMethodName); PrepareForReplay(); string strErr = ""; try { if ((objRowNumber == null) || (objColumnName == null)) { this.ReplayReportStep(strMethodName, EventStatus.EVENTSTATUS_FAIL, new object[] { strErr = string.Format("parameter should not be null. Parameters:Row-[{0}], ColumnName-[{1}]", objRowNumber==null?"null":objRowNumber.ToString(), objColumnName==null?"null":objColumnName.ToString())} ); this.ReplayThrowError(string.Format(strErr)); return; } int iNumber = Int32.Parse(objRowNumber.ToString()); string strColumn = objColumnName.ToString(); UltraGrid objGrid = (UltraGrid)SourceControl; if (iNumber > objGrid.Rows.Count) { strErr = string.Format("Row number [{0}] is larger than the current Grid contains :[{1}]", iNumber, objGrid.Rows.Count); ReportError(strMethodName, strErr); return; } if (objGrid.Rows.Count == 0) { strErr = "Row number is Zero, can't rightClick on Content. "; ReportError(strMethodName, strErr); return; } UltraGridRow objRow = objGrid.Rows[iNumber]; Mars_RowColumnInfo objRowInfo = new Mars_RowColumnInfo(objRowNumber), objColunInfo = new Mars_RowColumnInfo(objColumnName); UltraGridCell objCell = this.mFindCellByRowAndColumnInfo(objRow, objColunInfo); if (objCell == null) { strErr = string.Format("No such Column can be found on the table:[{0}]", strColumn); ReportError(strMethodName, strErr); return; } UIElement objUIElement = objCell.GetUIElement(); Thread.Sleep(200); if (objUIElement == null) { strErr = string.Format("Can't get UIElement: Cell is invisible,no such cell or exceptions? \r\n\tRow:[{0}]\r\n\tColumn:[{1}]", iNumber, strColumn); ReportError(strMethodName, strErr); return; } Rectangle rect = objUIElement.Rect; Point pt = rect.Location; if (iClickTimes != 1) base.MouseDblClick(pt.X + rect.Width / 2, pt.Y + rect.Height / 2, clickButton); else base.MouseClick(pt.X + rect.Width / 2, pt.Y + rect.Height / 2, clickButton); this.ReplayReportStep(strMethodName, EventStatus.EVENTSTATUS_GENERAL, new object[] { "Passed" }); } catch (Exception e) { strErr = string.Format("Can't continue to RightClick, Exceptions :[{0}]", e.Message); Logger.Error(strMethodName, strErr, e); this.ReplayReportStep("RightClick", EventStatus.EVENTSTATUS_FAIL, new Object[] { strErr }); this.ReplayThrowError(string.Format(strErr)); } }
/** **/ public void MarsTigerActiveCell(params object[] arrRC) { Logger.logBegin("MarsTigerActiveCell"); if (arrRC.Length != 2) { Logger.Error("MarsTigerActiveCell", "Only two parameters are accepted. "); return; } PrepareForReplay(); object oRow = arrRC[0], oColumn = arrRC[1]; UltraGrid objGrid = (UltraGrid)SourceControl; string strError = ""; Mars_RowColumnInfo oRowInfo = new Mars_RowColumnInfo(oRow), oColInfo = new Mars_RowColumnInfo(oColumn); try { if ((objGrid.Rows == null ? -1 : objGrid.Rows.Count) <= 0) { base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, "RowCount is 0" }); return; } if (oRowInfo.CurrentDataType == E_RowColumnType.eType_String) { // the first column of the row with fixed caption, which should be implement later throw new NotImplementedException(); } /** find cells **/ UltraGridRow objRow = mFindRowByRowNumber(oRowInfo.convertData2Int(), objGrid); if (objRow == null) { strError = string.Format("no such row number [{0}] is availble, row number stars 0", objRow); base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, strError }); return; } /** find cells by oColumn, int or header **/ UltraGridCell objCell = mFindCellByRowAndColumnInfo(objRow, oColInfo); if (objCell == null) { strError = string.Format("Can't find sepecial cell. \r\n\tRow:[{0}]\r\n\tColumn:[{1}]", oRow, oColumn); base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, strError }); return; } /** 获得 cell的rectangle, 然后调用mouse事件 **/ UIElement objUIElement = objCell.GetUIElement(); Thread.Sleep(200); if (objUIElement == null) { strError = string.Format("Can't get UIElement: Cell is invisible,no such cell or exceptions? \r\n\tRow:[{0}]\r\n\tColumn:[{1}]", oRow, oColumn); base.ReplayReportStep("MarsTigerActiveCell", EventStatus.EVENTSTATUS_FAIL, new object[] { oRow, oColumn, strError }); return; } Rectangle rect = objUIElement.Rect; Point pt = rect.Location; base.MouseClick(pt.X + rect.Width / 2, pt.Y + rect.Height / 2, MOUSE_BUTTON.LEFT_MOUSE_BUTTON); //LeftMouseClick(pt.X, pt.Y); } finally { Logger.logEnd("MarsTigerActiveCell"); } }