Exemplo n.º 1
0
        public void GenerateEntity(TableDetails details)
        {
            //generate <tablename>.cs in /Entities/
            string        path = $@"c:\Ookla\{details.ClassName}\Entities\{details.ClassName}.cs";
            StringBuilder sb   = new StringBuilder();

            sb.AppendLine("using System;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System.Linq;");
            sb.AppendLine("using System.Threading.Tasks;");
            sb.Append(Environment.NewLine);
            sb.AppendLine("namespace FL.PG.PLM_EEM_API.Entities");
            sb.AppendLine("{");
            sb.AppendLine($"    public class {details.ClassName}");
            sb.AppendLine("    {");

            foreach (FieldDetails field in details.Fields)
            {
                sb.AppendLine($"        public {field.ModifiedFieldType} {field.ModifiedFieldName} {{ get; set; }}");
            }

            sb.AppendLine("    }");
            sb.AppendLine("}");

            WriteToFile(sb, path);
        }
Exemplo n.º 2
0
        public void GenerateMap(TableDetails details)
        {
            //generate <tablename>Map.cs in /EntityMaps/
            string        path = $@"c:\Ookla\{details.ClassName}\EntityMaps\{details.ClassName}Map.cs";
            StringBuilder sb   = new StringBuilder();

            sb.AppendLine("using FL.PG.PLM_EEM_API.Entities;");
            sb.AppendLine("using Microsoft.EntityFrameworkCore;");
            sb.AppendLine("using Microsoft.EntityFrameworkCore.Metadata.Builders;");
            sb.Append(Environment.NewLine);
            sb.AppendLine("namespace FL.PG.PLM_EEM_API.EntityMaps");
            sb.AppendLine("{");
            sb.AppendLine($"    public class {details.ClassName}Map : IEntityTypeConfiguration<{details.ClassName}>");
            sb.AppendLine("    {");
            sb.AppendLine($"        public void Configure(EntityTypeBuilder<{details.ClassName}> builder)");
            sb.AppendLine("        {");
            sb.AppendLine($@"            builder.ToTable(""{details.TableName}"");");
            sb.Append(Environment.NewLine);
            sb.AppendLine("            builder.HasKey(t => t.Id);");
            sb.Append(Environment.NewLine);

            foreach (FieldDetails field in details.Fields)
            {
                sb.AppendLine($@"            builder.Property(e => e.{field.ModifiedFieldName}).HasColumnName(""{field.FieldName}"").HasDefaultValue({field.DefaultValue});");
            }

            sb.AppendLine("        }");
            sb.AppendLine("    }");
            sb.AppendLine("}");

            WriteToFile(sb, path);
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtTableNumber.Text == "")
            {
                MessageBox.Show("Please Enter Table Number", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTableNumber.Focus();
                return;
            }
            TableDetails td = new TableDetails();

            td.Id          = Convert.ToInt32(txtId.Text);
            td.TableNumber = txtTableNumber.Text;
            td.AddedDate   = System.DateTime.Now;

            bool isexists = blt.CheckTable(txtTableNumber.Text);

            if (isexists)
            {
                MessageBox.Show("Table Number Already Exists in Database", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Clear();
            }
            else
            {
                int i = blt.UpdateTable(td);
                if (i > 0)
                {
                    MessageBox.Show("Table Number Updated Successfully", "Record", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Clear();
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Create a new <see cref="SqliteVisualizerService"/> instance.
        /// </summary>
        /// <param name="modBuilder"><see cref="ModuleBuilder"/> instance for all dynamic types</param>
        public VisualizerWindowViewModel(ModuleBuilder modBuilder)
        {
            Debug.Assert(modBuilder != null, "Argument should not be null");
            this.modBuilder = modBuilder;

#pragma warning disable VSTHRD101 // Avoid unsupported async delegates
            this.LoadNextCommand = new RelayCommand(async(o) =>
            {
                await this.LoadSelectedTableRowsAsync(newSelectedTable: false);
            });
#pragma warning restore VSTHRD101 // Avoid unsupported async delegates

            this.CancelCommand = new RelayCommand((o) =>
            {
                // If the cancel call is initiated, the current table details should be already available
                var detailsTask = this.GetTableDetailsAsync(this.SelectedTable);
                Debug.Assert(detailsTask.IsCompleted, "Task should be complete");

#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
                TableDetails details = detailsTask.Result;
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits

                Debug.Assert(this.cancelTokenSource != null, "CancellationTokenSource should not be null");
                this.cancelTokenSource.Cancel();

                this.CancelCommand.Enable = false;
            });
        }
Exemplo n.º 5
0
        public void GeneratePlmContextLines(TableDetails details)
        {
            //plmContext
            //dbset
            //modelbuilder
            //virtual

            //generate <tablename>Controller.cs in /Controllers/
            string        path = $@"c:\Ookla\{details.ClassName}\AdditionalLines.cs";
            StringBuilder sb   = new StringBuilder();

            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.AppendLine("Add to appropriate sections of PlmContext.cs:");
            sb.Append(Environment.NewLine);
            sb.AppendLine($"        DbSet<{details.ClassName}> {details.ClassNamePlural} {{ get; set; }}");
            sb.AppendLine($"        modelBuilder.ApplyConfiguration(new {details.ClassName}Map());");
            sb.AppendLine($"        public virtual DbSet<{details.ClassName}> {details.ClassNamePlural} {{ get; set; }}");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            sb.AppendLine("Add to appropriate sections of Startup.cs:");
            sb.Append(Environment.NewLine);
            sb.AppendLine($"        services.AddScoped<I{details.ClassName}Service, {details.ClassName}Service>();");
            sb.Append(Environment.NewLine);
            sb.Append(Environment.NewLine);
            WriteToFile(sb, path);
        }
Exemplo n.º 6
0
        //eger elave edilmis data varsa yene elave etdikde yeni setr yox sadece cari setrin say sutununun  countu artir
        private bool chekcIfRowExistInDtTotal(TableDetails tableDetails, bool isDoubleClick)
        {
            bool isHave = false;

            foreach (DataRow allRow in totalDT.Select())
            {
                Console.WriteLine("allRow: " + allRow["foodName"]);
                if ((string)allRow["foodName"] == tableDetails.FoodStuff.Name)
                {
                    Console.WriteLine("allRow foodName== total.FoodStuff.Name  " + allRow["foodName"] + "  " + tableDetails.FoodStuff.Name);
                    if (isDoubleClick)
                    {
                        allRow["count"] = (int)allRow["count"] + 1;
                    }

                    tableDetails.FoodStuff.Price = (float)allRow["price"];
                    tableDetails.FoodQty         = (int)allRow["count"];
                    tableDetails.Sum             = (float)allRow["total"];
                    tableDetails.Id = (int)allRow["id"];
                    Console.WriteLine("=-=-=-=-=-=-=-=-=-=-= " + allRow["foodName"] + "  " + allRow["total"] + " " + allRow["id"]);
                    TableDetailsDao totalDao = new TableDetailsDao();
                    //MessageBox.Show("total id : " + total.Id);
                    int returnId = totalDao.updateTableDetails(tableDetails);
                    isHave = true;
                    return(isHave);
                    //break;
                }
                //break;
            }
            totalDT.RowChanged += new DataRowChangeEventHandler(Row_Changed);
            return(isHave);
        }
Exemplo n.º 7
0
        public List <TableDetails> getTableDetailsByTableId(int tableId)
        {
            List <TableDetails> totalListByTableId = new List <TableDetails>();
            string totalQuery = "SELECT * from  main.get_table_details_by_table_id(:t_id)";

            dataBase = new DataBase();
            var npgCommand = dataBase.getNpgCommandForRequest(totalQuery);

            npgCommand.Parameters.AddWithValue("t_id", tableId);
            NpgsqlDataReader reader = npgCommand.ExecuteReader();

            while (reader.Read())
            {
                TableDetails total = new TableDetails();
                total.Id              = reader.IsDBNull(reader.GetOrdinal("td_id")) ? 0 : reader.GetInt32(reader.GetOrdinal("td_id"));
                total.Table.Id        = reader.IsDBNull(reader.GetOrdinal("table_id")) ? 0 : reader.GetInt32(reader.GetOrdinal("table_id"));
                total.FoodStuff.Id    = reader.IsDBNull(reader.GetOrdinal("food_stuff_id")) ? 0 : reader.GetInt32(reader.GetOrdinal("food_stuff_id"));
                total.FoodQty         = reader.IsDBNull(reader.GetOrdinal("food_qty")) ? 0 : reader.GetInt32(reader.GetOrdinal("food_qty"));
                total.Sum             = reader.IsDBNull(reader.GetOrdinal("summary")) ? 0 : reader.GetFloat(reader.GetOrdinal("summary"));
                total.Table.Name      = reader.IsDBNull(reader.GetOrdinal("table_name")) ? string.Empty : reader.GetString(reader.GetOrdinal("table_name"));
                total.FoodStuff.Price = reader.IsDBNull(reader.GetOrdinal("price")) ? 0 : reader.GetFloat(reader.GetOrdinal("price"));
                total.FoodStuff.Name  = reader.IsDBNull(reader.GetOrdinal("food_stuff_name")) ? string.Empty : reader.GetString(reader.GetOrdinal("food_stuff_name"));

                totalListByTableId.Add(total);
            }
            dataBase.CloseAndDispose();
            return(totalListByTableId);
        }
Exemplo n.º 8
0
        public int insertTableDetails(TableDetails total)
        {
            Console.WriteLine("inseert method: ");
            string insertTotalQuery = "SELECT main.insert_table_details(:t_table_id,:t_food_stuff_id,:t_food_price,:t_cost,:t_food_qty,:t_food_sum)";

            dataBase = new DataBase();
            var insertCommand = dataBase.getNpgCommandForRequest(insertTotalQuery);

            insertCommand.Parameters.AddWithValue("t_table_id", total.Table.Id);
            insertCommand.Parameters.AddWithValue("t_food_stuff_id", total.FoodStuff.Id);
            insertCommand.Parameters.AddWithValue("t_food_price", total.FoodStuff.Price);
            insertCommand.Parameters.AddWithValue("t_cost", total.FoodStuff.Cost);
            insertCommand.Parameters.AddWithValue("t_food_qty", total.FoodQty);
            insertCommand.Parameters.AddWithValue("t_food_sum", total.Sum);
            NpgsqlDataReader dr = insertCommand.ExecuteReader();
            int returnId        = 0;

            while (dr.Read())
            {
                //returnId = dr.IsDBNull(dr.GetOrdinal("t_id")) ? 0 : dr.GetInt32(dr.GetOrdinal("t_id"));
                returnId = dr.GetInt32(0);
            }
            dataBase.CloseAndDispose();
            return(returnId);
        }
Exemplo n.º 9
0
 public DbObject BuildHistoryName(TableDetails table)
 {
     return(new DbObject()
     {
         Name = _historyCommonConfiguration.Prefix + table.Name,
         Schema = _historyCommonConfiguration.Schema
     });
 }
        public int UpdateTable(TableDetails td)
        {
            tbl_table tt = _db.tbl_table.Where(c => c.Id == td.Id).FirstOrDefault();

            tt.TableNumber = td.TableNumber;
            tt.AddedDate   = td.AddedDate;
            return(_db.SaveChanges());
        }
        public int AddNewTable(TableDetails td)
        {
            tbl_table tt = new tbl_table();

            tt.TableNumber = td.TableNumber;
            tt.AddedDate   = td.AddedDate;
            _db.tbl_table.Add(tt);
            return(_db.SaveChanges());
        }
Exemplo n.º 12
0
        public void GenerateServiceTests(TableDetails details)
        {
            //generate <tablename>ServiceTests.cs in /Tests/Services/
            string        path = $@"c:\Ookla\{details.ClassName}\Tests\Services\{details.ClassName}ServiceTests.cs";
            StringBuilder sb   = new StringBuilder();

            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using FL.PG.PLM_EEM_API.Entities;");
            sb.AppendLine("using FL.PG.PLM_EEM_API.Services;");
            sb.AppendLine("using FluentAssertions;");
            sb.AppendLine("using System.Threading.Tasks;");
            sb.AppendLine("using Xunit;");
            sb.Append(Environment.NewLine);
            sb.AppendLine("namespace FL.PG.PLM_EEM_API.Tests.Services");
            sb.AppendLine("{");
            sb.AppendLine($"    public class {details.ClassName}ServiceTests : ServiceTest<{details.ClassName}Service>");
            sb.AppendLine("    {");
            sb.AppendLine($"        private readonly {details.ClassName}Service _service;");
            sb.Append(Environment.NewLine);
            sb.AppendLine($"        public {details.ClassName}ServiceTests()");
            sb.AppendLine("        {");
            sb.AppendLine($"            _service = new {details.ClassName}Service(_readWriteContext, _logger.Object);");
            sb.AppendLine("        }");
            sb.Append(Environment.NewLine);
            sb.AppendLine("        [Fact]");
            sb.AppendLine($"        public async Task GetByDistrictIdAsync_Returns{details.ClassNamePlural}()");
            sb.AppendLine("        {");
            sb.AppendLine("            //Arrange");
            sb.AppendLine("            var districtId = 12345;");
            sb.Append(Environment.NewLine);
            sb.AppendLine($"            var {details.ClassName}Entities = new List<{details.ClassName}>");
            sb.AppendLine("            {");
            sb.AppendLine($@"                new {details.ClassName}{{Id = 1001 , {details.ClassName}Name = ""test name 1""}},");
            sb.AppendLine($@"                new {details.ClassName}{{Id = 1002, {details.ClassName}Name = ""test name 2""}},");
            sb.AppendLine($@"                new {details.ClassName}{{Id = 1003, {details.ClassName}Name = ""test name 3""}},");
            sb.AppendLine($@"                new {details.ClassName}{{Id = 1004 , {details.ClassName}Name = ""test name 4""}}");
            sb.AppendLine("            };");
            sb.Append(Environment.NewLine);
            sb.AppendLine($"            _readWriteContext.{details.ClassNamePlural}.AddRange({details.ClassName}Entities);");
            sb.Append(Environment.NewLine);
            sb.AppendLine("            _readWriteContext.SaveChanges();");
            sb.Append(Environment.NewLine);
            sb.AppendLine("            //Act");
            sb.AppendLine("            var result = await _service.GetByDistrictIdAsync(districtId);");
            sb.Append(Environment.NewLine);
            sb.AppendLine("            //Assert");
            sb.AppendLine("            result.Should().HaveCount(4);");
            sb.AppendLine($"            result.Should().BeOfType(typeof(List<{details.ClassName}>));");
            sb.AppendLine("        }");
            sb.AppendLine("    }");
            sb.AppendLine("}");

            WriteToFile(sb, path);
        }
    public List <TableDetails> FindRelationships(string table, string schema)
    {
        string sSQL = @"inner join (SELECT
FK.TABLE_NAME as FK_Table,
CU.COLUMN_NAME as FK_Column,
FK.TABLE_SCHEMA as FK_Schema,
PK.TABLE_NAME as PK_Table,
PT.COLUMN_NAME as PK_Column,
Constraint_Name = C.CONSTRAINT_NAME
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME
INNER JOIN (
SELECT i1.TABLE_NAME, i2.COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME
WHERE i1.CONSTRAINT_TYPE = 'PRIMARY KEY'
) PT ON PT.TABLE_NAME = PK.TABLE_NAME
WHERE FK.TABLE_NAME = '" + table.Replace("'", "''") + "'";

        if (!string.IsNullOrEmpty(schema))
        {
            sSQL += " and FK.TABLE_SCHEMA = '" + schema.Replace("'", "''") + "'";
        }
        sSQL += ") E on E.PK_Table = t.name and E.FK_Schema = OBJECT_SCHEMA_NAME(t.object_id)";

        List <TableDetails> details = new List <TableDetails>();

        // list all tables:
        foreach (DataRow r in GetDataTable("SELECT distinct OBJECT_SCHEMA_NAME(t.object_id) AS schema_name, E.FK_COlumn ,t.name AS table_name ,p.rows AS rows, E.FK_Column  AS rows FROM sys.tables t INNER JOIN sys.indexes i ON t.object_id = i.object_id INNER JOIN sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id " + sSQL).Rows)
        {
            var det = new TableDetails()
            {
                Name = r["TABLE_NAME"].ToString()
                ,
                Schema = r["schema_name"].ToString()
                ,
                Type = "TABLE"
                ,
                RowCount = long.Parse("0" + r["rows"].ToString().Replace(",", "").Replace(".", ""))
                ,
                FileGroup = r["FK_Column"].ToString()
            };
            if (details.Any(D => D.Name == det.Name && D.Schema == det.Schema))
            {
                continue;
            }

            details.Add(det);
        }

        return(details);
    }
Exemplo n.º 14
0
        private void ViewTable(object sender, RoutedEventArgs e)
        {
            var selection = grdTables.SelectedItem as Table;

            if (selection != null)
            {
                var detailView = new TableDetails();
                detailView.Initialize(selection.ID);
                MainWindow.LoadView(detailView);
            }
        }
Exemplo n.º 15
0
        private void LoadTableNumber()
        {
            List <TableDetails> lsttb = blt.GetAllTables();
            TableDetails        pro   = new TableDetails();

            pro.TableNumber = "Choose Table";
            lsttb.Insert(0, pro);

            cmbTable.DataSource    = lsttb;
            cmbTable.DisplayMember = "TableNumber";
            cmbTable.ValueMember   = "Id";
        }
Exemplo n.º 16
0
 public override int InsertOrUpdate(TableDetails obj)
 {
     try
     {
         //new DalMenuCategory().InsertOrUpdate(obj);
         return(1);
     }
     catch (Exception)
     {
         return(0);
     }
 }
Exemplo n.º 17
0
        private void Row_Changed(object sender, DataRowChangeEventArgs e)
        {
            TableDetails total = new TableDetails();

            total.Table = table;

            total.FoodStuff.Name  = (string)e.Row["foodName"];
            total.FoodStuff.Price = (float)e.Row["price"];
            total.Sum             = (float)e.Row["total"];
            total.FoodQty         = (int)e.Row["count"];
            //chekcIfRowExistInDtTotal(total, false);
        }
Exemplo n.º 18
0
        private async Task <IEnumerable <object> > GetTableRowsAsync(TableDetails details, int maxRowCount, CancellationToken token)
        {
            var rows = await details.Query.ExecuteAsync(maxRowCount, token);

            var rowInstances = new List <object>();

            foreach (var r in rows)
            {
                var rowInst = details.CreateRowInstance(r);
                rowInstances.Add(rowInst);
            }

            return(rowInstances);
        }
    public List <TableDetails> TableDetails(bool loadExtendedDetails = true)
    {
        List <TableDetails> details = new List <TableDetails>();

        string sSQL = @"SELECT case when Z.TABLE_NAME is null then 0 else 1 end as [HasPK], OBJECT_SCHEMA_NAME(t.object_id) AS schema_name ,t.name AS table_name ,i.index_id ,i.name AS index_name ,p.partition_number ,fg.name AS filegroup_name ,p.rows AS rows 
FROM sys.tables t INNER JOIN sys.indexes i ON t.object_id = i.object_id INNER JOIN sys.partitions p ON i.object_id=p.object_id AND i.index_id=p.index_id LEFT OUTER JOIN sys.partition_schemes ps ON i.data_space_id=ps.data_space_id LEFT OUTER JOIN sys.destination_data_spaces dds ON ps.data_space_id=dds.partition_scheme_id AND p.partition_number=dds.destination_id INNER JOIN sys.filegroups fg ON COALESCE(dds.data_space_id, i.data_space_id)=fg.data_space_id
outer apply (
select top 1 C.Table_Name, C.Table_Schema
from INFORMATION_SCHEMA.COLUMNS C
left join information_schema.key_column_usage K on K.Table_name = C.Table_Name and K.Table_Schema = C.Table_Schema and K.Column_Name = C.Column_Name 
where  C.TABLE_NAME = t.name and C.TABLE_SCHEMA = OBJECT_SCHEMA_NAME(t.object_id) and not  OBJECTPROPERTY(OBJECT_ID(CONSTRAINT_SCHEMA + '.' + CONSTRAINT_NAME), 'IsPrimaryKey') is null
) Z";


        // list all tables:
        foreach (DataRow r in GetDataTable(sSQL).Rows)
        {
            var det = new TableDetails()
            {
                Name = r["TABLE_NAME"].ToString()
                ,
                Schema = r["schema_name"].ToString()
                ,
                Type = "TABLE"
                ,
                FileGroup = r["filegroup_name"].ToString()
                ,
                RowCount = long.Parse("0" + r["rows"].ToString().Replace(",", "").Replace(".", ""))
                ,
                HasPk = Convert.ToBoolean(r["HasPk"])
            };
            if (details.Any(D => D.Name == det.Name && D.Schema == det.Schema))
            {
                continue;
            }

            if (loadExtendedDetails)
            {
                DataRow d = GetDataTable("sp_spaceused '" + det.Schema + "." + det.Name + "'").Rows[0];

                det.IndexSpace  = double.Parse(d["index_size"].ToString().Replace(" KB", "").Replace(",", ""));
                det.DiskSpace   = double.Parse(d["data"].ToString().Replace(" KB", "").Replace(",", ""));
                det.UnusedSpace = double.Parse(d["unused"].ToString().Replace(" KB", "").Replace(",", ""));
                det.Reserved    = double.Parse(d["Reserved"].ToString().Replace(" KB", "").Replace(",", ""));
            }
            details.Add(det);
        }

        return(details);
    }
Exemplo n.º 20
0
        private void btnFoodDoubleClick(object sender, EventArgs e)
        {
            TableDetails total     = new TableDetails();
            FoodStuff    foodStuff = (FoodStuff)((Button)sender).Tag;

            total.Table     = table;
            total.FoodStuff = foodStuff;
            bool isHave = chekcIfRowExistInDtTotal(total, true);

            if (!isHave)
            {
                addToTotalDataTable(total);
            }
        }
Exemplo n.º 21
0
        private ChangeScript GenerateHistoryTrigger(TableDetails table)
        {
            _logger.LogMessage("Generating History Trigger for {0}.", table.FullName);

            StringBuilder columnBuilder = new StringBuilder();

            foreach (var column in table.Columns)
            {
                columnBuilder.AppendFormat("[{0}],", column.Name);
            }
            columnBuilder.Remove(columnBuilder.Length - 1, 1);
            StringBuilder builder     = new StringBuilder();
            var           triggerName = string.Format("[{0}].[{1}_HistoryTrigger]", table.Schema, table.Name);

            if (_historyCommonConfiguration.IncludeDropOrAlterStatements)
            {
                builder.AppendFormat(@"IF OBJECT_ID('{0}') IS NOT NULL DROP TRIGGER {0}; 
                                       GO
                                      ", triggerName);
            }

            builder.AppendFormat(@"
                    CREATE TRIGGER {0}
                       ON  [{1}].[{2}]
                       AFTER UPDATE, DELETE
                    AS 
                    BEGIN
	                    SET NOCOUNT ON;
	                    INSERT INTO [{3}].[{4}]
                               ({5})
	                    SELECT {5}
	                    FROM DELETED
                    END
                    GO"
                                 , triggerName
                                 , table.Schema, table.Name
                                 , table.HistoricalTable.Schema, table.HistoricalTable.Name
                                 , columnBuilder.ToString());

            return(new ChangeScript()
            {
                Name = string.Format("{0}_HistoryTrigger", table.Name),
                Schema = table.Schema,
                RelatedTables = new[] { table, table.HistoricalTable },
                ScriptText = builder.ToString(),
                ScriptType = ScriptType.Trigger,
                State = table.HistoricalTable.State
            });
        }
Exemplo n.º 22
0
        public override TableDetails LoadFromReader(DataTableReader reader)
        {
            var temp = new TableDetails();

            if (reader != null && !reader.IsClosed)
            {
                temp.TableId = reader.GetInt32(0);
                if (!reader.IsDBNull(1))
                {
                    temp.TableCode = reader.GetString(1);
                }
            }

            return(temp);
        }
Exemplo n.º 23
0
        private async Task <IList <string> > ValidateLastRowBeforeAdding(TableDetails model)
        {
            ICollection <string> validationErrors = null;

            bool isValid = await Task <bool> .Run(() =>
            {
                return(_tableModelValidationService.ValidateItemCode(model.ItemCode, out validationErrors) &&
                       _tableModelValidationService.ValidateItemDescription(model.ItemDescription, out validationErrors) &&
                       _tableModelValidationService.ValidateItemQuantity(model.ItemQuantity, out validationErrors) &&
                       _tableModelValidationService.ValidateItemPrice(model.ItemPrice, out validationErrors));
            })
                           .ConfigureAwait(false);

            return((IList <string>)validationErrors);
        }
Exemplo n.º 24
0
        public void GenerateFiles(string tableName)
        {
            TableName = tableName;
            TableDetails td = GetSchema();

            GenerateEntity(td);
            GenerateModel(td);
            GenerateMap(td);
            GenerateMapProfile(td);
            GenerateServiceInterface(td);
            GenerateService(td);
            GenerateController(td);
            GeneratePlmContextLines(td);
            GenerateControllerTests(td);
            GenerateServiceTests(td);
        }
    public List <TableDetails> ViewDetails(bool count = true)
    {
        List <TableDetails> details = new List <TableDetails>();

        foreach (DataRow r in GetDataTable("SELECT SCHEMA_NAME(schema_id) AS schema_name,name AS view_name FROM sys.views where is_ms_shipped = 0").Rows)
        {
            var det = new TableDetails()
            {
                Name = r["view_name"].ToString()
                ,
                Schema = r["schema_name"].ToString()
                ,
                Type = "VIEW"
                ,
                FileGroup = string.Empty
                ,
                RowCount = 0
            };
            if (count)
            {
                try
                {
                    det.RowCount = Convert.ToInt64(ExecuteScalar("select count(1) from [" + r["schema_name"].ToString() + "].[" + r["view_name"].ToString() + "]"));
                }
                catch
                {
                    //there is an issue with the view, so skipt it...
                }
            }
            if (details.Any(D => D.Name == det.Name && D.Schema == det.Schema))
            {
                continue;
            }


            det.IndexSpace  = 0;
            det.DiskSpace   = 0;
            det.UnusedSpace = 0;
            det.Reserved    = 0;

            details.Add(det);
        }


        return(details);
    }
Exemplo n.º 26
0
        public void GenerateModel(TableDetails details)
        {
            //generate <tablename>Model.cs in /ViewModels/
            string        path = $@"c:\Ookla\{details.ClassName}\ViewModels\{details.ClassName}Model.cs";
            StringBuilder sb   = new StringBuilder();

            sb.AppendLine("using System;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System.Linq;");
            sb.AppendLine("using System.Threading.Tasks;");
            sb.AppendLine("using FluentValidation;");
            sb.Append(Environment.NewLine);
            sb.AppendLine("namespace FL.PG.PLM_EEM_API.ViewModels");
            sb.AppendLine("{");
            sb.AppendLine($"    public class {details.ClassName}Model");
            sb.AppendLine("    {");

            foreach (FieldDetails field in details.Fields)
            {
                sb.AppendLine($"        public {field.ModifiedFieldType} {field.ModifiedFieldName} {{ get; set; }}");
            }

            sb.AppendLine("    }");

            sb.Append(Environment.NewLine);
            sb.AppendLine($"    public class {details.ClassName}ModelValidator : AbstractValidator<{details.ClassName}Model>");
            sb.AppendLine("    {");
            sb.AppendLine($"        public {details.ClassName}ModelValidator()");
            sb.AppendLine("        {");
            foreach (FieldDetails field in details.Fields)
            {
                if (field.ModifiedFieldType == "string" && !field.FieldName.StartsWith("txt") && field.FieldLengthMax == false)
                {
                    sb.AppendLine($"            RuleFor(x => x.{field.ModifiedFieldName}).{field.NullText}().Length(0, {field.FieldLength});");
                }
                else
                {
                    sb.AppendLine($"            RuleFor(x => x.{field.ModifiedFieldName}).{field.NullText}();");
                }
            }
            sb.AppendLine("        }");
            sb.AppendLine("    }");
            sb.AppendLine("}");

            WriteToFile(sb, path);
        }
Exemplo n.º 27
0
        public void DrawTableModel(int tableGroupNo)
        {
            this.lastUsedtableGroup = tableGroupNo;

            Hashtable invHashtable = GetCurrentOrders();

            gridTableModel.Children.Clear();
            TableDetails tableDetails = new TableDetails();

            tableDetails.Organization_no = PosSettings.Default.Organization;
            tableDetails.Store_no        = PosSettings.Default.Store;
            tableDetails.Table_group_no  = tableGroupNo;

            DataSet   dataSet = tableDetails.LoadTable();
            DataTable dt      = dataSet.Tables[0];

            foreach (DataRow dr in dt.Rows)
            {
                TableButtonData bData = new TableButtonData();
                bData.Display_row_no    = int.Parse(dr["display_row_no"].ToString());
                bData.Display_column_no = int.Parse(dr["display_column_no"].ToString());
                bData.Table_no          = int.Parse(dr["table_no"].ToString());
                bData.Table_name        = dr["table_name"].ToString();
                bData.Picture_name      = dr["picture_name"].ToString();

                Button tableBtn = new Button();
                tableBtn.DataContext = bData;

                if (invHashtable.ContainsKey(bData.Table_name))
                {
                    DataRow dr1 = invHashtable[bData.Table_name] as DataRow;
                    bData.Pos_no   = int.Parse(dr1["pos_no"].ToString());
                    bData.Trans_no = int.Parse(dr1["trans_no"].ToString());
                    tableBtn.Style = (Style)FindResource("btnXLSActive");
                }
                else
                {
                    tableBtn.Style = (Style)FindResource("btnXLS");
                }


                gridTableModel.Children.Add(tableBtn);

                tableBtn.Click += new RoutedEventHandler(tableBtn_Click);
            }
        }
Exemplo n.º 28
0
        public void GenerateService(TableDetails details)
        {
            //generate <tablename>Service.cs in /Services/
            string        path = $@"c:\Ookla\{details.ClassName}\Services\{details.ClassName}Service.cs";
            StringBuilder sb   = new StringBuilder();

            sb.AppendLine("using System;");
            sb.AppendLine("using FL.PG.PLM_EEM_API.Entities;");
            sb.AppendLine("using FL.PG.PLM_EEM_API.Services.Interfaces;");
            sb.AppendLine("using Microsoft.EntityFrameworkCore;");
            sb.AppendLine("using Microsoft.Extensions.Logging;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System.Linq;");
            sb.AppendLine("using System.Threading.Tasks;");
            sb.Append(Environment.NewLine);
            sb.AppendLine("namespace FL.PG.PLM_EEM_API.Services");
            sb.AppendLine("{");
            sb.AppendLine($"    public class {details.ClassName}Service : I{details.ClassName}Service");
            sb.AppendLine("    {");

            sb.AppendLine("        private readonly IPlmReadWriteContext _plmDataContext;");
            sb.AppendLine($"        private readonly ILogger<{details.ClassName}Service> _logger;");

            sb.AppendLine($"        public {details.ClassName}Service(IPlmReadWriteContext plmDataContext, ILogger<{details.ClassName}Service> logger)");
            sb.AppendLine("        {");
            sb.AppendLine("            _plmDataContext = plmDataContext;");
            sb.AppendLine("            _logger = logger;");
            sb.AppendLine("        }");

            sb.AppendLine($"        public async Task<List<{details.ClassName}>> GetByDistrictIdAsync(int districtId, bool onlyActive = true)");
            sb.AppendLine("        {");
            sb.AppendLine("            throw new NotImplementedException();");
            sb.AppendLine("            var result = string.Empty; //do stuff here");
            sb.AppendLine("            return result;");
            sb.AppendLine("        }");

            sb.AppendLine("    }");
            sb.AppendLine("}");

            WriteToFile(sb, path);
        }
Exemplo n.º 29
0
        public void GenerateServiceInterface(TableDetails details)
        {
            //generate I<tablename>Service.cs in /Services/Interfaces/
            string        path = $@"c:\Ookla\{details.ClassName}\Services\Interfaces\I{details.ClassName}Service.cs";
            StringBuilder sb   = new StringBuilder();

            sb.AppendLine("using System;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System.Linq;");
            sb.AppendLine("using System.Threading.Tasks;");
            sb.AppendLine("using FL.PG.PLM_EEM_API.Entities;");
            sb.Append(Environment.NewLine);
            sb.AppendLine("namespace FL.PG.PLM_EEM_API.Services.Interfaces");
            sb.AppendLine("{");
            sb.AppendLine($"    public interface I{details.ClassName}Service");
            sb.AppendLine("    {");
            sb.AppendLine($"        Task<List<{details.ClassName}>> GetByDistrictIdAsync(int districtId, bool onlyActive = true);");
            sb.AppendLine("    }");
            sb.AppendLine("}");

            WriteToFile(sb, path);
        }
Exemplo n.º 30
0
        private async Task <TableDetails> GetTableDetailsAsync(string table)
        {
            TableDetails details;

            if (!this.tableDetails.TryGetValue(table, out details))
            {
                // Escape string for sqlite - http://www.sqlite.org/lang_expr.html
                var escapedTableName = this.selectedTable.Replace("\"", "\\\"");
                escapedTableName = escapedTableName.Replace("'", "''");
                var query = await SqliteFuncEvalQuery.CreateAsync(
                    this.inspectionContext,
                    this.sqliteInstanceName,
                    $"SELECT * FROM '{escapedTableName}'");

                // Move off the main thread since we are about to do some code gen
                await TaskScheduler.Default;

                details = new TableDetails(this.selectedTable, query, this.modBuilder);
                this.tableDetails[table] = details;
            }

            return(details);
        }