/// <summary> /// Postavlja kursor unutar zone, vraca TRUE ako je morao da intervenise /// </summary> /// <param name="zone"></param> /// <returns></returns> public static Boolean cursorToZone(this selectZone zone) { Boolean output = false; if (Console.CursorLeft < zone.x) { Console.CursorLeft = zone.x; output = true; } if (Console.CursorLeft > zone.x + zone.weight) { Console.CursorLeft = zone.x + zone.weight; output = true; } if (Console.CursorTop < zone.y) { Console.CursorTop = zone.y; output = true; } if (Console.CursorTop > zone.y + zone.height) { Console.CursorTop = zone.y + zone.height; output = true; } return(output); }
/// <summary> /// Automatski pravi value read zonu na mestu gde je stao kursor /// </summary> /// <returns></returns> protected selectZone autoValueReadZone() { var sr = selectToCorner(textCursorZoneCorner.Right); selectZone output = new selectZone(x, y, sr.x, 1); return(output); }
public static void toLocalY(this selectZone zone, Int32 y) { Console.CursorTop = zone.y + y; zone.cursorToZone(); //return Console.CursorTop - zone.y; //Console.CursorTop = Console.CursorTop + zone.y; }
public static string outputToZone(this selectZone zone, String output) { String cv = ""; cv += output; cv = String.Format("{0,-" + zone.weight + "}", cv); return(cv); }
public static void to(this selectZone zone, Int32 x = 0, Int32 y = 0) { Console.CursorTop = zone.y + y; Console.CursorLeft = zone.x + x; zone.cursorToZone(); //return Console.CursorTop - zone.y; //Console.CursorTop = Console.CursorTop + zone.y; }
protected void process(DataTable table) { // categoryList = table.GetCategoryPriority(); int i = 0; string cat = table.Columns.getFirstOfType <DataColumn>().GetGroup().ToUpper(); int start = 0; int end = 1; DataColumn dcl = null; foreach (DataColumn dc in table.Columns) { dcl = dc; i++; if (dc.GetGroup().ToUpper() == cat) { end = i; } else { Add(cat.ToUpper(), dc); int st = start - 1; if (st < 0) { st = 0; } int ln = (end - start) - 1; if (ln < 0) { ln = 0; } var zone = new selectZone(st, 0, ln, 0); // aceLog.log(cat + " " + zone.ToStringDump(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty, 10)); categoryZones.Add(cat.ToUpper(), zone); start = i; end = i; cat = dc.GetGroup().ToUpper(); categoryList.Add(cat.ToUpper()); } } if (start != end) { int ln2 = (end - start) - 1; if (ln2 < 0) { ln2 = 0; } Add(cat.ToUpper(), dcl); cat = dcl.GetGroup().ToUpper(); categoryZones.Add(cat.ToUpper(), new selectZone(start, 0, ln2, 0)); categoryList.Add(cat.ToUpper()); } }
public static void reprint(List <char> chars, selectZone zone) { Int32 cl = Console.CursorLeft; Int32 ct = Console.CursorTop; Console.CursorLeft = zone.x; Console.CursorTop = zone.y; for (Int32 a = 0; a < zone.weight; a++) { Char c = ' '; if (chars.Count > a) { c = chars[a]; } Console.Write(c); } Console.CursorLeft = cl; Console.CursorTop = ct; }
/// <summary> /// Cita liniju u skladu sa dodeljenom zonom delovanja /// </summary> /// <param name="val">Vrednost koja se edituje</param> /// <param name="zone">Zona editovanja</param> /// <param name="valType">Tip vrednosti</param> /// <returns>Nova vrednost ako ENTER ili stara vrednost ako ESC</returns> public static Object ReadLine(Object val, selectZone zone, Type valType) { String Default = val.toStringSafe(""); readLineValidationMode valMode = readLineValidationMode.stringMode; if (valType == typeof(Int32)) { valMode = readLineValidationMode.ordinalNumber; Default = val.ToString(); } if (valType == typeof(Double)) { valMode = readLineValidationMode.decimalNumber; Default = String.Format("N2", val.imbToNumber(typeof(Double))); } zone.to(); //int pos = Console.CursorLeft; String cv = zone.outputToZone(Default); List <char> chars = new List <char>(); if (string.IsNullOrEmpty(cv) == false) { chars.AddRange(cv.ToCharArray()); } Console.ForegroundColor = ConsoleColor.Red; Console.CursorVisible = true; reprint(chars, zone); //Console.Write(cv); //Console.CursorLeft = zone.x; //Console.CursorTop = zone.y; //Console.SetCursorPosition(zone.x, zone.y); ConsoleKeyInfo info; while (true) { if (Console.KeyAvailable) { info = Console.ReadKey(); Boolean allowChar = false; switch (info.Key) { case ConsoleKey.Escape: return(val); break; case ConsoleKey.Enter: String result = ""; foreach (char c in chars) { result = result + c; } result = result.Trim(); val = result.imbConvertValueSafe(valType); return(val); break; case ConsoleKey.Delete: chars.RemoveAt(zone.localX()); //Console.CursorLeft -= 1; //Console.Write(' '); //Console.CursorLeft -= 1; //chars.Add(' '); break; case ConsoleKey.End: zone.toLocalX(1000); // Console.CursorLeft = zone.x + zone.weight; break; case ConsoleKey.Home: zone.toLocalX(0); break; case ConsoleKey.Backspace: if (chars.Count > zone.localX()) { chars.RemoveAt(zone.localX()); //Console.CursorLeft -= 1; //Console.Write(' '); //Console.CursorLeft += 1; //chars.Add(' '); } //Console.CursorLeft -= 1; break; case ConsoleKey.LeftArrow: zone.moveX(-2); break; case ConsoleKey.RightArrow: //Console.CursorLeft += 1; break; case ConsoleKey.UpArrow: //Console.CursorTop -= 1; break; case ConsoleKey.DownArrow: //Console.CursorTop += 1; break; default: switch (valMode) { case readLineValidationMode.stringMode: if (char.IsLetterOrDigit(info.KeyChar)) { allowChar = true; } if (zone.localX() != 0) { allowChar = true; } else { if (char.IsSeparator(info.KeyChar)) { allowChar = true; } } break; case readLineValidationMode.decimalNumber: if (char.IsSymbol(info.KeyChar) && zone.localX() != 0) { allowChar = true; } else if (char.IsNumber(info.KeyChar)) { allowChar = true; } else if (char.IsPunctuation(info.KeyChar)) { allowChar = true; } break; case readLineValidationMode.ordinalNumber: if (char.IsSymbol(info.KeyChar) && zone.localX() != 0) { allowChar = true; } else if (char.IsNumber(info.KeyChar)) { allowChar = true; } break; } break; } zone.cursorToZone(); if (allowChar) { // Console.Write(info.KeyChar); chars[zone.localX() - 1] = info.KeyChar; } reprint(chars, zone); } /* * * if (info.Key == ConsoleKey.Backspace && Console.CursorLeft > ) * { * chars.RemoveAt(chars.Count - 1); * Console.CursorLeft -= 1; * Console.Write(' '); * Console.CursorLeft -= 1; * * } * else if (info.Key == ConsoleKey.Enter) { Console.Write(Environment.NewLine); break; } * //Here you need create own checking of symbols * else if (char.IsLetterOrDigit(info.KeyChar)) * { * Console.Write(info.KeyChar); * chars.Add(info.KeyChar); * }*/ } //return new string(chars.ToArray()); }
public static void moveY(this selectZone zone, Int32 step = 1) { Console.CursorTop = Console.CursorTop + step; zone.cursorToZone(); }
public static Int32 localY(this selectZone zone) { return(Console.CursorTop - zone.y); }
public static Int32 localX(this selectZone zone) { return(Console.CursorLeft - zone.x); }
/// <summary> /// Pravi selectZone na osnovu sadrzaja trenutne linije. Trazi [ i ] kao granicnike zone. Ako ih ima vise, upotrebice prvi par. /// </summary> /// <remarks> /// Ako u trenutnoj liniji: /// - ima vise [ ] parova: upotrebice prvi /// - je sve prazno ili popunjeno razmacima: upotrebice celu liniju kao zonu /// - ako je od x-a do desnog inner x-a prazno /// </remarks> /// <returns>selectZone objekat koji treba upotrebiti kao inputReadZone ili za nesto drugo</returns> public selectZone getSelectZone(Int32 zoneHeight = -1, Int32 zoneWidth = -1, params selectZoneOption[] option) { var optionList = option.ToList(); selectZone output = new selectZone(); output.y = y; if (zoneHeight == -1) { zoneHeight = 1; output.height = zoneHeight; } selectZoneOption takeOption = option.takeFirstFromList(selectZoneOption.takeDefinedWidth, selectZoneOption.takeFromPositionToRightEnd, selectZoneOption.takeBracetDefinedArea, selectZoneOption.takeCompleteLine); if (takeOption == selectZoneOption.takeDefinedWidth) { if (zoneWidth == -1) { takeOption = selectZoneOption.takeFromPositionToRightEnd; } } if (takeOption == selectZoneOption.takeBracetDefinedArea) { if (target is ISupportsCursorWriteAndSelect) { ISupportsCursorWriteAndSelect target2 = target as ISupportsCursorWriteAndSelect; String lastLine = target2.select(this, -1, true); Int32 si = lastLine.IndexOf("["); if (si == -1) { prevLine(); lastLine = target2.select(this, -1, true); if (lastLine.IndexOf("[") == -1) { nextLine(); } else { si = lastLine.IndexOf("["); } } Int32 ln = lastLine.IndexOf("]") - si; if (ln < 0) { takeOption = selectZoneOption.takeFromPositionToRightEnd; } else { output.y = y; output.x = si; output.weight = ln; } } } switch (takeOption) { case selectZoneOption.takeFromPositionToRightEnd: output.x = x; output.weight = selectToCorner(textCursorZoneCorner.Right).x; break; case selectZoneOption.takeCompleteLine: output.x = target.innerLeftPosition; output.weight = target.innerWidth; break; } var moveOption = option.takeFirstFromList(selectZoneOption.none, selectZoneOption.moveCursorToBottomEndOfZone, selectZoneOption.moveCursorToBeginningOfZone); switch (moveOption) { case selectZoneOption.moveCursorToBeginningOfZone: moveLineTo(output.y); moveXTo(output.x); break; case selectZoneOption.moveCursorToBottomEndOfZone: moveLineTo(output.y + output.height); break; } return(output); }
///// <summary> ///// Cita odredjenu zonu ///// </summary> ///// <param name="mode">Vrste citanja</param> ///// <param name="x">-1 koristi trenutni</param> ///// <param name="y">-1 koristi trenutni</param> ///// <param name="w">vise od 0 znaci citanje 1D ili 2D</param> ///// <param name="h">vise od 0 znaci citanje 2D bloka</param> ///// <returns>Popunjen input result</returns> //public override textInputResult read(textInputResult currentOutput, inputReadMode mode, int x = -1, int y = -1, int w = 0, int h = 0) //{ // selectZone zone = new selectZone(x, y, w, h); // return read(currentOutput, mode, zone); //} /// <summary> /// Citanje pomocu zone objekta /// </summary> /// <param name="mode">Vrsta citanja</param> /// <param name="zone">Zona</param> /// <returns></returns> public override textInputResult read(textInputResult currentOutput, inputReadMode mode, selectZone zone, Object startValue = null) { if (currentOutput == null) { currentOutput = new textInputResult(this, mode, zone); } else { currentOutput.platform = this; currentOutput.readMode = mode; currentOutput.readZone = zone; } if (currentOutput.result == null) { currentOutput.result = startValue; } Console.CursorVisible = false; /// nije inplementirano zonsko citanje switch (mode) { case inputReadMode.readKey: currentOutput.consoleKey = Console.ReadKey(true); break; case inputReadMode.read: Console.CursorVisible = true; Console.SetCursorPosition(zone.x, zone.y); Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = ConsoleColor.Black; currentOutput.result = consolePlatformExtensions.ReadLine(startValue, zone, currentOutput.result.GetType()); Console.CursorVisible = false; Console.ResetColor(); break; case inputReadMode.readLine: currentOutput.result = Console.ReadLine(); break; } return(currentOutput); }
/// <summary> /// Deploys the style to row. /// </summary> /// <param name="ex_row">The ex row.</param> /// <param name="in_row">The in row.</param> /// <param name="ws">The ws.</param> /// <param name="metaSet">The meta set.</param> public void DeployStyleToRow(ExcelRow ex_row, DataRow in_row, ExcelWorksheet ws, tableStyleRowSetter metaSet = null) { DataRowInReportTypeEnum style = DataRowInReportTypeEnum.data; if (extraRowStyles.ContainsKey(in_row)) { style = extraRowStyles[in_row]; } bool isEven = ((in_row.Table.Rows.IndexOf(in_row) % 2) > 0); Boolean isLegend = in_row.Table.TableName == LEGENDTABLE_NAME; var baseStyle = styleSet.rowStyles[style]; var rowsMetaSet = this.GetRowMetaSet(); if (metaSet != null) { rowsMetaSet = metaSet; } var response = rowsMetaSet.evaluate(in_row, this, baseStyle); if (response != null) { if (response.style != null) { baseStyle = response.style; } } if (baseStyle == null) { baseStyle = styleSet.rowStyles[style]; } foreach (string s in response.notes) { Console.WriteLine(s); } ex_row.SetStyle(baseStyle, isEven); switch (style) { case DataRowInReportTypeEnum.columnCaption: if (!isLegend) { foreach (var cpair in categories) { foreach (selectZone zone in categories.categoryZones[cpair.Key]) { var sl = ws.getExcelRange(ex_row, zone); sl.Style.Fill.PatternType = ExcelFillStyle.Solid; var col = categories.categoryColors[cpair.Key]; //.First().DefaultBackground(System.Drawing.Color.Gray); sl.Style.Fill.BackgroundColor.SetColor(col); sl.Style.Fill.BackgroundColor.Tint = new decimal(0.2); } } } break; case DataRowInReportTypeEnum.mergedHeaderTitle: ws.Cells[ex_row.Row, 1, ex_row.Row, in_row.Table.Columns.Count].Merge = true; break; case DataRowInReportTypeEnum.mergedHeaderInfo: ws.Cells[ex_row.Row, 1, ex_row.Row, in_row.Table.Columns.Count].Merge = true; break; case DataRowInReportTypeEnum.mergedFooterInfo: ws.Cells[ex_row.Row, 1, ex_row.Row, in_row.Table.Columns.Count].Merge = true; break; case DataRowInReportTypeEnum.mergedHorizontally: selectZone z = new selectZone(0, 0, Columns.Count - 1, 0); var s2l = ws.getExcelRange(ex_row, z); s2l.Merge = true; break; case DataRowInReportTypeEnum.mergedCategoryHeader: double tn = 0.2; int hlip = -1; foreach (var cpair in categories) { if (hlip == -1) { tn = 0.3; } else { tn = 0.6; } foreach (selectZone zone in categories.categoryZones[cpair.Key]) { var sl = ws.getExcelRange(ex_row, zone); sl.Merge = true; sl.Value = cpair.Key.ToUpper(); sl.Style.Fill.PatternType = ExcelFillStyle.Solid; var col = categories.categoryColors[cpair.Key]; //.First().DefaultBackground(System.Drawing.Color.Gray); sl.Style.Fill.BackgroundColor.SetColor(col); sl.Style.Fill.BackgroundColor.Tint = new decimal(tn); } hlip = -hlip; } isEven = !isEven; break; case DataRowInReportTypeEnum.data: //ex_row.Style.Font.Size = 9; foreach (DataColumn dc in in_row.Table.Columns) { string format = dc.GetFormatForExcel(); var aligment = dc.GetAligment(); ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = aligment.GetHorizontalAlignment(); if (!format.isNullOrEmpty()) { ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.Numberformat.Format = format; } //if (dc.GetValueType().isNumber()) //{ // ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right; //} //else if (dc.GetValueType().IsEnum) //{ // ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; //} //else if (dc.GetValueType().isBoolean()) //{ // ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Center; //} //else //{ // ws.Cells[ex_row.Row, dc.Ordinal + 1].Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; //} } break; } if (!isLegend) { if (ex_row.Row == (RowStart + RowsWithMaxAggregation)) { ex_row.Style.Border.Bottom.Style = ExcelBorderStyle.Dotted; ex_row.Style.Border.Bottom.Color.SetColor(System.Drawing.Color.Red); } } }
public textInputResult(IPlatform __platform, inputReadMode __readMode, selectZone __readZone) { platform = __platform; readMode = __readMode; readZone = __readZone; }
public static void toLocalX(this selectZone zone, Int32 x) { //x = zone.x + x; Console.CursorLeft = zone.x + x; zone.cursorToZone(); }
/// <summary> /// Postavlja boje za dalji izlaz /// </summary> /// <param name="foreColor">Prednja boja. Ako je .none onda resetuje boje</param> /// <param name="backColor">Boja pozadine</param> /// <param name="doInvert"> </param> // public abstract void setColors(platformColorName foreColor, platformColorName backColor, Boolean doInvert=false); /// <summary> /// Cita odredjenu zonu /// </summary> /// <param name="mode">Vrste citanja</param> /// <param name="x">-1 koristi trenutni</param> /// <param name="y">-1 koristi trenutni</param> /// <param name="w">vise od 0 znaci citanje 1D ili 2D</param> /// <param name="h">vise od 0 znaci citanje 2D bloka</param> /// <returns>Popunjen input result</returns> public abstract textInputResult read(textInputResult currentOutput, inputReadMode mode, selectZone zone, object startValue);
public static ExcelRange getExcelRange(this ExcelWorksheet worksheet, ExcelRow row, selectZone zone) { return(worksheet.Cells[row.Row + zone.y, zone.x + 1, row.Row + zone.y + zone.height, zone.width + zone.x + 1]); }