-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- new procedure: divide - new procedure: thousand separator - fixed duplicate error if column for "copy old" already exists
- Loading branch information
Showing
16 changed files
with
1,249 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SQLite; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DataTableConverter.Assisstant.SQL_Functions | ||
{ | ||
[SQLiteFunction(Name = "DIVIDE", Arguments = 2, FuncType = FunctionType.Scalar)] | ||
class Divide : SQLiteFunction | ||
{ | ||
|
||
public override object Invoke(object[] args) | ||
{ | ||
decimal.TryParse(args[0].ToString(), out decimal dividend); | ||
decimal.TryParse(args[1].ToString(), out decimal divisor); | ||
return divisor != 0 ? (Math.Floor((dividend / divisor) * 100)/100).ToString("0.##") : "0"; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
DataTableConverter/Assisstant/SQL Functions/ThousandSeparator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data.SQLite; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace DataTableConverter.Assisstant.SQL_Functions | ||
{ | ||
[SQLiteFunction(Name = "THOUSAND_SEPARATOR", Arguments = 1, FuncType = FunctionType.Scalar)] | ||
class ThousandSeparator : SQLiteFunction | ||
{ | ||
|
||
public override object Invoke(object[] args) | ||
{ | ||
decimal.TryParse(args[0].ToString(), out decimal result); | ||
int decimals = BitConverter.GetBytes(decimal.GetBits(result)[3])[2]; | ||
return result.ToString($"N{decimals}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using DataTableConverter.Extensions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace DataTableConverter.Classes.WorkProcs | ||
{ | ||
[Serializable()] | ||
class ProcDivide: WorkProc | ||
{ | ||
internal static readonly string ClassName = "Dividieren"; | ||
public decimal Divisor = 1; | ||
|
||
public ProcDivide(int ordinal, int id, string name) : base(ordinal, id, name) { } | ||
|
||
public ProcDivide(string[] columns, decimal divisor, string newColumn, bool copyOldColumn) | ||
{ | ||
Divisor = divisor; | ||
NewColumn = newColumn; | ||
Columns = new DataTable { TableName = "Columnnames" }; | ||
Columns.Columns.Add("Spalten", typeof(string)); | ||
foreach (string col in columns) | ||
{ | ||
Columns.Rows.Add(col); | ||
} | ||
CopyOldColumn = copyOldColumn; | ||
} | ||
|
||
public override string[] GetHeaders() | ||
{ | ||
return RemoveEmptyHeaders(Columns.AsEnumerable().Select(dr => dr.ItemArray.FirstOrDefault()?.ToString())); | ||
} | ||
|
||
public override void RenameHeaders(string oldName, string newName) | ||
{ | ||
foreach (DataRow row in Columns.Rows) | ||
{ | ||
if (row[0].ToString() == oldName) | ||
{ | ||
row[0] = newName; | ||
} | ||
} | ||
} | ||
|
||
public override void RemoveHeader(string colName) | ||
{ | ||
Columns = Columns.AsEnumerable().Where(row => row[0].ToString() != colName).ToTable(Columns); | ||
} | ||
|
||
public override void DoWork(ref string sortingOrder, Case duplicateCase, List<Tolerance> tolerances, Proc procedure, string filename, ContextMenuStrip ctxRow, OrderType orderType, Form1 invokeForm, string tableName) | ||
{ | ||
string[] columns = GetHeaders(); | ||
if (PrepareMultiple(columns, invokeForm, tableName, out string[] sourceColumns, out string[] destinationColumns)) | ||
{ | ||
invokeForm.DatabaseHelper.Divide(sourceColumns, destinationColumns, Divisor, tableName); | ||
} | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
DataTableConverter/Classes/WorkProcs/ProcThousandSeparator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using DataTableConverter.Extensions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
|
||
namespace DataTableConverter.Classes.WorkProcs | ||
{ | ||
[Serializable()] | ||
class ProcThousandSeparator : WorkProc | ||
{ | ||
internal static readonly string ClassName = "Tausender Trennzeichen"; | ||
|
||
public override string[] GetHeaders() | ||
{ | ||
return RemoveEmptyHeaders(Columns.AsEnumerable().Select(dr => dr.ItemArray.FirstOrDefault()?.ToString())); | ||
} | ||
|
||
public ProcThousandSeparator(int ordinal, int id, string name) : base(ordinal, id, name) { } | ||
|
||
public ProcThousandSeparator(string[] columns, string newColumn, bool copyOldColumn) | ||
{ | ||
NewColumn = newColumn; | ||
Columns = new DataTable { TableName = "Columnnames" }; | ||
Columns.Columns.Add("Spalten", typeof(string)); | ||
foreach (string col in columns) | ||
{ | ||
Columns.Rows.Add(col); | ||
} | ||
CopyOldColumn = copyOldColumn; | ||
} | ||
|
||
public override void RenameHeaders(string oldName, string newName) | ||
{ | ||
foreach (DataRow row in Columns.Rows) | ||
{ | ||
if (row[0].ToString() == oldName) | ||
{ | ||
row[0] = newName; | ||
} | ||
} | ||
} | ||
|
||
public override void RemoveHeader(string colName) | ||
{ | ||
Columns = Columns.AsEnumerable().Where(row => row[0].ToString() != colName).ToTable(Columns); | ||
} | ||
|
||
public override void DoWork(ref string sortingOrder, Case duplicateCase, List<Tolerance> tolerances, Proc procedure, string filename, ContextMenuStrip ctxRow, OrderType orderType, Form1 invokeForm, string tableName) | ||
{ | ||
string[] columns = GetHeaders(); | ||
if (PrepareMultiple(columns, invokeForm, tableName, out string[] sourceColumns, out string[] destinationColumns)) | ||
{ | ||
invokeForm.DatabaseHelper.ThousandSeparator(sourceColumns, destinationColumns, tableName); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.