using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Common;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WSDDBBrowser.Core.Model
{
    public class DBModel:DbContext
    {
        public DBModel(DbConnection connection)
            : base(connection, true)
        {

        }

        public virtual DbSet<g_sbProcess> sbProcesses { get; set; }
        public virtual DbSet<g_sbRecord> sbRecords { get; set; }
        public virtual DbSet<g_sbNumber> sbNumbers { get; set; }
        public virtual DbSet<g_sbUser> sbUsers { get; set; }
        public virtual DbSet<g_sbPTech> sbPTechs { get; set; }


        public virtual DbSet<g_tgNumber> tgNumbers { get; set; }
        public virtual DbSet<g_tgProcess> tgProcesses { get; set; }
        public virtual DbSet<g_tgRecord> tgRecords { get; set; }
        public virtual DbSet<g_tgTech> tgTechs { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            #region g_sbxxxx   
            #region g_sbNumber

            modelBuilder.Entity<g_sbNumber>()
                .Property(e => e.cNumber)
                .IsUnicode(false);

            modelBuilder.Entity<g_sbNumber>()
                .Property(e => e.nBeginLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_sbNumber>()
                .Property(e => e.nEndLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_sbNumber>()
                .Property(e => e.nActiveLen)
                .HasPrecision(9, 1);
            #endregion

            #region g_sbProcess
            modelBuilder.Entity<g_sbProcess>()
                .Property(e => e.cOrderNo)
                .IsUnicode(false);

            modelBuilder.Entity<g_sbProcess>()
                .Property(e => e.cProjectNo)
                .IsUnicode(false);

            modelBuilder.Entity<g_sbProcess>()
                .Property(e => e.cTechnologyNo)
                .IsUnicode(false);

            modelBuilder.Entity<g_sbProcess>()
                .Property(e => e.nTotalLen)
                .HasPrecision(9, 1);
            #endregion

            #region g_sbRecord
            modelBuilder.Entity<g_sbRecord>()
                .Property(e => e.nProcessLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_sbRecord>()
                .Property(e => e.cDeviceId)
                .IsFixedLength();

            modelBuilder.Entity<g_sbRecord>()
                .Property(e => e.nMValue)
                .HasPrecision(9, 1);
            #endregion

            #region g_sbUser
            modelBuilder.Entity<g_sbUser>()
                .Property(e => e.cUserName)
                .IsFixedLength();

            modelBuilder.Entity<g_sbUser>()
                .Property(e => e.nBeginLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_sbUser>()
                .Property(e => e.nEndLen)
                .HasPrecision(9, 1);
            #endregion

            #region g_sbPTech
            modelBuilder.Entity<g_sbPTech>()
                .Property(e => e.nTarget)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_sbPTech>()
                .Property(e => e.nTolerance)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_sbPTech>()
                .Property(e => e.cDeviceId)
                .IsFixedLength();

            modelBuilder.Entity<g_sbPTech>()
                .Property(e => e.cDeviceName)
                .IsFixedLength();
            #endregion
            #endregion 

            #region g_tgxxxx
            modelBuilder.Entity<g_tgNumber>()
                .Property(e => e.cNumber)
                .IsUnicode(false);

            modelBuilder.Entity<g_tgNumber>()
                .Property(e => e.nBeginLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_tgNumber>()
                .Property(e => e.nEndLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_tgProcess>()
                .Property(e => e.cOrderNo)
                .IsUnicode(false);

            modelBuilder.Entity<g_tgProcess>()
                .Property(e => e.cProjectNo)
                .IsUnicode(false);

            modelBuilder.Entity<g_tgProcess>()
                .Property(e => e.cTechnologyNo)
                .IsUnicode(false);

            modelBuilder.Entity<g_tgProcess>()
                .Property(e => e.nTotalLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_tgRecord>()
                .Property(e => e.cDeviceId)
                .IsFixedLength();

            modelBuilder.Entity<g_tgRecord>()
                .Property(e => e.nK)
                .HasPrecision(9, 3);

            modelBuilder.Entity<g_tgRecord>()
                .Property(e => e.nB)
                .HasPrecision(9, 2);

            modelBuilder.Entity<g_tgRecord>()
                .Property(e => e.nProcessLen)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_tgRecord>()
                .Property(e => e.nVelocity)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_tgRecord>()
                .Property(e => e.nValues)
                .IsUnicode(false);

            modelBuilder.Entity<g_tgTech>()
                .Property(e => e.cDeviceId)
                .IsFixedLength();

            modelBuilder.Entity<g_tgTech>()
                .Property(e => e.cDeviceName)
                .IsFixedLength();

            modelBuilder.Entity<g_tgTech>()
                .Property(e => e.nTarget)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_tgTech>()
                .Property(e => e.nTolerance)
                .HasPrecision(9, 1);

            modelBuilder.Entity<g_tgTech>()
                .Property(e => e.nCtrlLine)
                .HasPrecision(9, 1);
            #endregion
        }
    }


}
