public static string ScriptForCreateTable(MigrationTable table)
        {
            var script = Script.New();

            script.AppendLine("Create.Table(\"{0}\")", table.Name);

            // columns
            foreach (var column in table.Columns)
            {
                script.AppendLine("      .WithColumn(\"{0}\"){1}", column.Name, column.ScriptActions());
            }

            script.AppendSemicolon();
            script.AppendEmptyLine();

            // foreign keys
            foreach (var column in table.ForeignKeyColumns)
            {
                script.AppendLine("Create{0}", column.ForeignKeyActions());
                script.AppendSemicolon();
            }


            return script.ToString();
        }
        public static string ScriptForCreateTable(MigrationTable table)
        {
            var script = Script.New();

            script.AppendLine("Create.Table(\"{0}\")", table.Name);

            // columns
            foreach (var column in table.Columns)
            {
                script.AppendLine("      .WithColumn(\"{0}\"){1}", column.Name, column.ScriptActions());
            }

            script.AppendSemicolon();
            script.AppendEmptyLine();

            // foreign keys
            foreach (var column in table.ForeignKeyColumns)
            {
                script.AppendLine("Create{0}", column.ForeignKeyActions());
                script.AppendSemicolon();
            }


            return(script.ToString());
        }
        public static string ScriptForDropTable(MigrationTable table)
        {
            var script = Script.New();

            script.Append("Drop.Table(\"{0}\")", table.Name);
            script.AppendSemicolon();

            return script.ToString();
        }
        public static string ScriptForDropTable(MigrationTable table)
        {
            var script = Script.New();

            script.Append("Drop.Table(\"{0}\")", table.Name);
            script.AppendSemicolon();

            return(script.ToString());
        }
Beispiel #5
0
        private void SincronizaFabricantes()
        {
            try
            {
                migrationTable  = migrationTableController.SelectOne(3);
                migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId);
                Sql             = "SELECT ";

                foreach (var f in migrationFields)
                {
                    if (migrationFields.Last() == f)
                    {
                        Sql += f.Expresion + " FROM " + migrationTable.Tabla;
                    }
                    else
                    {
                        Sql += f.Expresion + " , ";
                    }
                }
                Sql += " " + migrationTable.Condicion;

                GetDataTable(Sql);
                laboratorio  = null;
                laboratorios = laboratorioController.SelectAll();


                foreach (DataRow row in dataTable.Rows)
                {
                    Ambiente.S1 = row["clave"].ToString().Trim().ToUpper();
                    Ambiente.S2 = row["descrip"].ToString().Trim().ToUpper();

                    laboratorio = laboratorios.FirstOrDefault(x => x.LaboratorioId.ToUpper().Equals(Ambiente.S1));

                    if (laboratorio == null)
                    {
                        laboratorio = new Laboratorio();
                        laboratorio.LaboratorioId = Ambiente.S1;
                        laboratorio.Nombre        = Ambiente.S2;
                        laboratorio.IsDeleted     = false;
                        laboratorioController.InsertOne(laboratorio);
                    }
                    else
                    {
                        laboratorio.Nombre    = Ambiente.S2;
                        laboratorio.IsDeleted = false;
                        laboratorioController.Update(laboratorio);
                    }
                }
                Ambiente.Mensaje("Proceso concluido");
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.ToString());
            }
        }
Beispiel #6
0
        private void SincronizaPresentacion()
        {
            try
            {
                migrationTable  = migrationTableController.SelectOne(1);
                migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId);
                Sql             = "SELECT ";

                foreach (var f in migrationFields)
                {
                    if (migrationFields.Last() == f)
                    {
                        Sql += f.Expresion + " FROM " + migrationTable.Tabla;
                    }
                    else
                    {
                        Sql += f.Expresion + " , ";
                    }
                }
                Sql += " " + migrationTable.Condicion;

                GetDataTable(Sql);
                presentacion   = null;
                presentaciones = presentacionController.SelectAll();


                foreach (DataRow row in dataTable.Rows)
                {
                    Ambiente.S1 = row["clave"].ToString().Trim().ToUpper();
                    Ambiente.S2 = row["descrip"].ToString().Trim().ToUpper();

                    presentacion = presentaciones.FirstOrDefault(x => x.PresentacionId.ToUpper().Equals(Ambiente.S1));

                    if (presentacion == null)
                    {
                        presentacion = new Presentacion();
                        presentacion.PresentacionId = Ambiente.S1;
                        presentacion.Nombre         = Ambiente.S2;
                        presentacion.IsDeleted      = false;
                        presentacionController.InsertOne(presentacion);
                    }
                    else
                    {
                        presentacion.Nombre    = Ambiente.S2;
                        presentacion.IsDeleted = false;
                        presentacionController.Update(presentacion);
                    }
                }
                Ambiente.Mensaje("Proceso concluido");
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.ToString());
            }
        }
Beispiel #7
0
        private void SincronizaComponentes()
        {
            try
            {
                migrationTable  = migrationTableController.SelectOne(5);
                migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId);
                Sql             = "SELECT ";

                foreach (var f in migrationFields)
                {
                    if (migrationFields.Last() == f)
                    {
                        Sql += f.Expresion + " FROM " + migrationTable.Tabla;
                    }
                    else
                    {
                        Sql += f.Expresion + " , ";
                    }
                }
                Sql += " " + migrationTable.Condicion;
                GetDataTable(Sql);
                sustancia  = null;
                sustancias = sustanciaController.SelectAll();


                foreach (DataRow row in dataTable.Rows)
                {
                    Ambiente.S1 = row["clave"].ToString().Trim().ToUpper();
                    Ambiente.S2 = row["descrip"].ToString().Trim().ToUpper();

                    sustancia = sustancias.FirstOrDefault(x => x.SustanciaId.ToUpper().Equals(Ambiente.S1));

                    if (sustancia == null)
                    {
                        sustancia             = new Sustancia();
                        sustancia.SustanciaId = Ambiente.S1;
                        sustancia.Nombre      = Ambiente.S2.Length == 0 ? Ambiente.S1 : Ambiente.S2;
                        sustancia.IsDeleted   = false;
                        sustanciaController.InsertOne(sustancia);
                    }
                    else
                    {
                        sustancia.Nombre    = Ambiente.S2;
                        sustancia.IsDeleted = false;
                        sustanciaController.Update(sustancia);
                    }
                }
                Ambiente.Mensaje("Proceso concluido");
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.ToString());
            }
        }
Beispiel #8
0
 public bool InsertOne(MigrationTable o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Add(o);
             return(db.SaveChanges() > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #9
0
 public bool Update(MigrationTable o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Entry(o).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
             return(db.SaveChanges() > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #10
0
 public bool DeletePartidas(MigrationTable devolucion)
 {
     try
     {
         using (var db = new DymContext())
         {
             var partidas = db.MigrationField.Where(x => x.MigrationTableId == devolucion.MigrationTableId).ToList();
             if (partidas != null)
             {
                 db.RemoveRange(partidas);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
        private void MigrateTable(MigrationTask task, MigrationTable table, out string reason)
        {
            reason = "取消操作";
            if (status.Stopped)
            {
                return;
            }

            if (Connect(task, task.Source, out IDBMSReader source, task.Dest, out IDBMSWriter dest))
            {
                Dictionary <string, object> parms = new Dictionary <string, object>();

                dest.QueryParam(task.Params, parms);
                dest.BeginTransaction();
                try
                {
                    // 迁移数据
                    MigrateTableWithScript(task, table, parms, source, dest, out reason);
                    if (table.Status != DataStates.Error && !status.Stopped)
                    {
                        dest.CommitTransaction();
                        table.Status = DataStates.Done;
                    }
                    else
                    {
                        dest.RollbackTransaction();
                        table.Status = DataStates.Error;
                    }
                }
                catch (Exception ex)
                {
                    dest.RollbackTransaction();
                    table.Status = DataStates.Error;
                    reason       = ex.Message;
                }

                source.Close();
                dest.Close();
            }
 public CreateTableMigration(MigrationTable table)
     :base(table)
 {
    
 }
        public DestructiveMigration(MigrationTable table)
            : base(table)
        {

        }
Beispiel #14
0
 public DropTableMigration(MigrationTable table) : base(table)
 {
 }
 public DestructiveMigration(MigrationTable table)
     : base(table)
 {
 }
Beispiel #16
0
        private void Initialize()
        {
            //Controllers
            productoSustanciaController = new ProductoSustanciaController();
            cierreInventariopController = new CierreInventariopController();
            productoImpuestoController  = new ProductoImpuestoController();
            cierreInventarioController  = new CierreInventarioController();
            migrationTableController    = new MigrationTableController();
            migrationFieldController    = new MigrationFieldController();
            presentacionController      = new PresentacionController();
            laboratorioController       = new LaboratorioController();
            categoriaController         = new CategoriaController();
            sustanciaController         = new SustanciaController();
            productoController          = new ProductoController();
            loteController   = new LoteController();
            movInvController = new MovInvController();
            //Objetos
            productoSustancia = null;
            productoImpuesto  = null;
            cierreInventario  = null;
            cierreInventariop = null;
            migrationTable    = null;
            migrationField    = null;
            presentacion      = null;
            laboratorio       = null;
            categoria         = null;
            sustancia         = null;
            producto          = null;
            lote = null;

            //Listas
            productoSustancias = new List <ProductoSustancia>();
            productoImpuestos  = new List <ProductoImpuesto>();
            migrationTables    = new List <MigrationTable>();
            migrationFields    = new List <MigrationField>();
            presentaciones     = new List <Presentacion>();
            laboratorios       = new List <Laboratorio>();
            categorias         = new List <Categoria>();
            sustancias         = new List <Sustancia>();
            productos          = new List <Producto>();
            lotes = new List <Lote>();


            try
            {
                //Conexion vfpro
                Sql              = "";
                dataTable        = new DataTable();
                connectionstring = "Provider=VFPOLEDB.1;Data Source=" + Ambiente.Empresa.MicroPvdb + ";";
                oleDbConnection  = new OleDbConnection(connectionstring);
                oleDbConnection.Open();


                //Llena combo tablas
                migrationTables        = migrationTableController.SelectAll();
                CboTabla.DataSource    = migrationTables;
                CboTabla.DisplayMember = "Tabla";
                CboTabla.ValueMember   = "MigrationTableId";
                CboTabla.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #17
0
 public CreateTableMigration(MigrationTable table)
     : base(table)
 {
 }
        public void Execute(Instance ins, IStopStatus status)
        {
            this.status = status;

            foreach (Common.Task t in ins.Tasks)
            {
                if (status.Stopped)
                {
                    break;
                }

                if (t is MigrationTask task && task.Tables.Length > 0)
                {
                    task.StartTick = WinAPI.GetTickCount();
                    task.Status    = DataStates.Running;

                    // 构建待迁移表清单:lst[0] = 独立表,lst[1+] = 依赖树
                    List <List <MigrationTable> > lst = new List <List <MigrationTable> >
                    {
                        new List <MigrationTable>(task.Tables[0]),
                        new List <MigrationTable>()
                    };

                    for (int i = 1; i < task.Tables.Length; i++)
                    {
                        for (int j = 0; j < task.Tables[i].Length; j++)
                        {
                            MigrationTable ta = task.Tables[i][j];

                            for (int k = 0; k < ta.References.Length; k++)
                            {
                                for (int l = 0; l < lst[0].Count; l++)
                                {
                                    if (ta.References[k].Equals(lst[0][l].DestName))
                                    {
                                        lst[1].Add(lst[0][l]);
                                        lst[0].RemoveAt(l);
                                        break;
                                    }
                                }
                            }
                        }
                        lst.Add(new List <MigrationTable>(task.Tables[i]));
                    }

                    TableComparer comparer = new TableComparer();

                    foreach (List <MigrationTable> tables in lst)
                    {
                        tables.Sort(comparer);
                    }

                    List <MigrationTable> runList = new List <MigrationTable>();

                    // 开始迁移
                    try
                    {
                        Parallel.ForEach(CreateThreadAction((int)task.Threads), i =>
                        {
                            MigrationTable table = GetTable(lst, runList);

                            while (table != null)
                            {
                                Logger.WriteLog($"{task.Dest.Server}/{task.Dest.DB}.{table.DestName}", "迁移开始...");

                                MigrateTable(task, table, out string reason);
                                if (table.Status == DataStates.Done)
                                {
                                    Logger.WriteLog($"{task.Dest.Server}/{task.Dest.DB}.{table.DestName}", "迁移成功。");
                                    Logger.WriteRpt(task.Dest.Server, task.Dest.DB, table.DestName, "成功",
                                                    table.Progress.ToString("#,##0"));
                                }
                                else
                                {
                                    task.Status    = DataStates.RunningError;
                                    task.ErrorMsg  = reason;
                                    task.Progress -= table.Progress;
                                    Logger.WriteLog($"{task.Dest.Server}/{task.Dest.DB}.{table.DestName}",
                                                    $"迁移失败!{reason}");
                                    Logger.WriteRpt(task.Dest.Server, task.Dest.DB, table.DestName, "失败", reason);
                                }
                                lock (runList) { runList.Remove(table); }

                                table = GetTable(lst, runList);
                            }
                        });

                        if (status.Stopped || task.Status == DataStates.RunningError || task.Status == DataStates.Error)
                        {
                            task.Status = DataStates.Error;
                            Logger.WriteLog($"{task.Dest.Server}/{task.Dest.DB}", "迁移失败!");
                        }
                        else
                        {
                            task.Status = DataStates.Done;
                            Logger.WriteLog($"{task.Dest.Server}/{task.Dest.DB}", "迁移成功!");
                        }
                    }
                    catch (Exception ex)
                    {
                        task.Status   = DataStates.Error;
                        task.ErrorMsg = ex.Message;
                        Logger.WriteLog($"{task.Dest.Server}/{task.Dest.DB}", $"迁移失败!{ex.Message}");
                    }
                    task.StartTick = WinAPI.GetTickCount() - task.StartTick;
                }
            }
        }
 public DropTableMigration(MigrationTable table):base(table)
 {
 }
Beispiel #20
0
 private void CboTabla_SelectedIndexChanged(object sender, EventArgs e)
 {
     migrationTable = CboTabla.SelectedItem as MigrationTable;
     CargaGrid();
 }
Beispiel #21
0
 public Migration(MigrationTable table)
 {
     Table = table;
 }
Beispiel #22
0
        private void SincronizaProductos()
        {
            try
            {
                migrationTable  = migrationTableController.SelectOne(6);
                migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId);
                Sql             = "SELECT ";

                foreach (var f in migrationFields)
                {
                    if (migrationFields.Last() == f)
                    {
                        Sql += f.Expresion + " FROM " + migrationTable.Tabla;
                    }
                    else
                    {
                        Sql += f.Expresion + " , ";
                    }
                }
                Sql += " " + migrationTable.Condicion;
                GetDataTable(Sql);
                producto       = null;
                productos      = productoController.SelectAll();
                categorias     = categoriaController.SelectAll();
                presentaciones = presentacionController.SelectAll();
                laboratorios   = laboratorioController.SelectAll();

                decimal p = 0;
                bool    b = false;
                foreach (DataRow row in dataTable.Rows)
                {
                    Ambiente.S1 = row["clave"].ToString().Trim().ToUpper();
                    Ambiente.S2 = row["descrip"].ToString().Trim().ToUpper();
                    Ambiente.S3 = row["cupo"].ToString().Trim().ToUpper();

                    Ambiente.S4 = row["presenta"].ToString().Trim().ToUpper();
                    Ambiente.S4 = presentaciones.FirstOrDefault(x => x.PresentacionId.ToUpper().Equals(Ambiente.S4)) == null ? "SYS" : Ambiente.S4;

                    Ambiente.S5 = row["unidades"].ToString().Trim().ToUpper();
                    Ambiente.S6 = row["fabricante"].ToString().Trim().ToUpper();
                    Ambiente.S6 = laboratorios.FirstOrDefault(x => x.LaboratorioId.ToUpper().Equals(Ambiente.S6)) == null ? "SYS" : Ambiente.S6;

                    Ambiente.S8 = row["imagen"].ToString().Trim().ToUpper();
                    Ambiente.S8 = Ambiente.Empresa.DirectorioImg + Path.GetFileName(Ambiente.S8);

                    Ambiente.S9 = row["categoria"].ToString().Trim().ToUpper();
                    Ambiente.S9 = categorias.FirstOrDefault(x => x.CategoriaId.ToUpper().Equals(Ambiente.S9)) == null ? "SYS" : Ambiente.S9;

                    Ambiente.Boolean1 = bool.TryParse(row["encatalogo"].ToString(), out b) == true ? b : false;
                    Ambiente.Boolean2 = bool.TryParse(row["cklote"].ToString(), out b) == true ? b : false;
                    Ambiente.Boolean3 = (bool)row["cklote"];


                    Ambiente.Decimal1 = decimal.TryParse(row["pcompra"].ToString().Trim(), out p) == true ? p : 1;
                    Ambiente.Decimal2 = decimal.TryParse(row["pventa"].ToString().Trim(), out p) == true ? p : 1;
                    Ambiente.Decimal3 = decimal.TryParse(row["pmayoreo"].ToString().Trim(), out p) == true ? p : 1;
                    Ambiente.Decimal4 = decimal.TryParse(row["pcaja"].ToString().Trim(), out p) == true ? p : 1;


                    if (row["tasaimp"].ToString().Trim().ToUpper().Equals("E"))
                    {
                        Ambiente.S7 = "SYS";
                    }
                    else if (row["tasaimp"].ToString().Trim().ToUpper().Equals("I"))
                    {
                        Ambiente.S7 = "IVA";
                    }
                    else
                    {
                        Ambiente.S7 = "SYS";
                    }

                    producto = productos.FirstOrDefault(x => x.ProductoId.ToUpper().Equals(Ambiente.S1));

                    if (producto == null)
                    {
                        producto                 = new Producto();
                        producto.ProductoId      = Ambiente.S1;
                        producto.CategoriaId     = Ambiente.S9;
                        producto.PresentacionId  = Ambiente.S4;
                        producto.LaboratorioId   = Ambiente.S6;
                        producto.Descripcion     = Ambiente.S2;
                        producto.Unidades        = Ambiente.S5;
                        producto.Contenido       = Ambiente.S3;
                        producto.Stock           = 0; //atencion
                        producto.PrecioCompra    = Ambiente.Decimal1;
                        producto.PrecioCaja      = Ambiente.Decimal4;
                        producto.Precio1         = Ambiente.Decimal2;
                        producto.Precio2         = Ambiente.Decimal3;
                        producto.Precio3         = 0;
                        producto.Precio4         = 0;
                        producto.Utilidad1       = Ambiente.Margen(producto.Precio1, producto.PrecioCompra);
                        producto.Utilidad2       = Ambiente.Margen(producto.Precio2, producto.PrecioCompra);
                        producto.Utilidad3       = 0;
                        producto.Utilidad4       = 0;
                        producto.TieneLote       = Ambiente.Boolean2;
                        producto.IsDeleted       = false;
                        producto.CratedBy        = "JMENDOZAJ";
                        producto.CratedAt        = DateTime.Now;
                        producto.DeletedBy       = null;
                        producto.UpdatedBy       = "JMENDOZAJ";
                        producto.LoteId          = null; //Atencion
                        producto.UnidadMedidaId  = "PZA";
                        producto.ClaveProdServId = "01010101";
                        producto.ClaveUnidadId   = "H87";
                        producto.RutaImg         = Ambiente.S8;//Atencion
                        producto.ChkCaducidad    = producto.TieneLote;
                        producto.Impuesto1Id     = Ambiente.S7;
                        producto.Impuesto2Id     = "SYS";
                        producto.Impuesto3Id     = "SYS";
                        producto.Ocupado         = false;
                        producto.IsDeleted       = false;
                        producto.Min             = 10;
                        producto.Max             = 20;
                        producto.Costopp         = Ambiente.Decimal1;
                        producto.UltimoCosto     = Ambiente.Decimal1;
                        productoController.InsertOne(producto);
                    }
                    else
                    {
                        // producto.ProductoId = Ambiente.S1;
                        producto.CategoriaId     = Ambiente.S9;
                        producto.PresentacionId  = Ambiente.S4;
                        producto.LaboratorioId   = Ambiente.S6;
                        producto.Descripcion     = Ambiente.S2;
                        producto.Unidades        = Ambiente.S5;
                        producto.Contenido       = Ambiente.S3;
                        producto.Stock           = 0; //atencion
                        producto.PrecioCompra    = Ambiente.Decimal1;
                        producto.PrecioCaja      = Ambiente.Decimal4;
                        producto.Precio1         = Ambiente.Decimal2;
                        producto.Precio2         = Ambiente.Decimal3;
                        producto.Precio3         = 0;
                        producto.Precio4         = 0;
                        producto.Utilidad1       = Ambiente.Margen(producto.Precio1, producto.PrecioCompra);
                        producto.Utilidad2       = Ambiente.Margen(producto.Precio2, producto.PrecioCompra);
                        producto.Utilidad3       = 0;
                        producto.Utilidad4       = 0;
                        producto.TieneLote       = Ambiente.Boolean2;
                        producto.IsDeleted       = false;
                        producto.CratedBy        = "JMENDOZAJ";
                        producto.CratedAt        = DateTime.Now;
                        producto.DeletedBy       = null;
                        producto.UpdatedBy       = "JMENDOZAJ";
                        producto.LoteId          = null; //Atencion
                        producto.UnidadMedidaId  = "PZA";
                        producto.ClaveProdServId = "01010101";
                        producto.ClaveUnidadId   = "H87";
                        producto.RutaImg         = Ambiente.S8; //Atencion
                        producto.ChkCaducidad    = producto.TieneLote;
                        producto.Impuesto1Id     = Ambiente.S7;
                        producto.Impuesto2Id     = "SYS";
                        producto.Impuesto3Id     = "SYS";
                        producto.Ocupado         = false;
                        producto.IsDeleted       = false;
                        producto.Costopp         = Ambiente.Decimal1;
                        producto.UltimoCosto     = Ambiente.Decimal1;
                        productoController.Update(producto);
                    }
                }
                Ambiente.Mensaje("Proceso concluido");
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.ToString());
            }
        }
        private MigrationTable GetTable(List <List <MigrationTable> > lst, List <MigrationTable> runList)
        {
            while (true)
            {
                lock (runList)
                {
                    int dependCount = 0;
                    // 先从依赖树取
                    for (int i = 1; i < lst.Count; i++)
                    {
                        dependCount += lst[i].Count;
                        for (int j = 0; j < lst[i].Count; j++)
                        {
                            // 无外键依赖
                            if (lst[i][j].References.Length == 0)
                            {
                                MigrationTable rst = lst[i][j];

                                lst[i].RemoveAt(j);
                                runList.Add(rst);

                                return(rst);
                            }
                            else
                            {
                                bool inTree = false;

                                foreach (string s in lst[i][j].References)
                                {
                                    for (int k = 1; k < i; k++)
                                    {
                                        for (int l = 0; l < lst[k].Count; l++)
                                        {
                                            if (s.Equals(lst[k][l].DestName))
                                            {
                                                inTree = true;
                                                break;
                                            }
                                        }
                                        if (inTree)
                                        {
                                            break;
                                        }
                                    }
                                    if (inTree)
                                    {
                                        break;
                                    }

                                    for (int k = 0; k < runList.Count; k++)
                                    {
                                        if (s.Equals(runList[k].DestName))
                                        {
                                            inTree = true;
                                            break;
                                        }
                                    }
                                }

                                if (!inTree)
                                {
                                    MigrationTable rst = lst[i][j];

                                    lst[i].RemoveAt(j);
                                    runList.Add(rst);

                                    return(rst);
                                }
                            }
                        }
                    }

                    // 再从独立表取
                    if (lst[0].Count > 0)
                    {
                        MigrationTable rst = lst[0][0];

                        lst[0].RemoveAt(0);
                        runList.Add(rst);

                        return(rst);
                    }
                    else if (dependCount == 0)
                    {
                        return(null);
                    }
                }

                Thread.Sleep(50);
            }
        }
Beispiel #24
0
        private void Sincronizaprodsus()
        {
            try
            {
                migrationTable  = migrationTableController.SelectOne(9);
                migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId);
                Sql             = "SELECT ";

                foreach (var f in migrationFields)
                {
                    if (migrationFields.Last() == f)
                    {
                        Sql += f.Expresion + " FROM " + migrationTable.Tabla;
                    }
                    else
                    {
                        Sql += f.Expresion + " , ";
                    }
                }
                Sql += " " + migrationTable.Condicion;
                GetDataTable(Sql);
                productoSustancia  = null;
                productoSustancias = productoSustanciaController.SelectAll();
                sustancias         = sustanciaController.SelectAll();
                productos          = productoController.SelectAll();

                int p = 0;
                foreach (DataRow row in dataTable.Rows)
                {
                    Ambiente.S1 = row["producto"].ToString().Trim().ToUpper();
                    Ambiente.S2 = row["componen"].ToString().Trim().ToUpper();
                    //Ambiente.Int1 = int.TryParse(row["orden"].ToString().Trim(), out p) == true ? p : 0;

                    productoSustancia = productoSustancias.FirstOrDefault(x => x.ProductoId.ToUpper().Equals(Ambiente.S1) && x.SustanciaId.ToUpper().Equals(Ambiente.S2));

                    if (productoSustancia == null)
                    {
                        if (productos.FirstOrDefault(x => x.ProductoId.Equals(Ambiente.S1)) == null || sustancias.FirstOrDefault(x => x.SustanciaId.Equals(Ambiente.S2)) == null)
                        {
                            continue;
                        }

                        productoSustancia             = new ProductoSustancia();
                        productoSustancia.ProductoId  = Ambiente.S1;
                        productoSustancia.SustanciaId = Ambiente.S2;
                        productoSustancia.Contenido   = productos.FirstOrDefault(x => x.ProductoId.Equals(productoSustancia.ProductoId)) == null ? "" : productos.FirstOrDefault(x => x.ProductoId.Equals(productoSustancia.ProductoId)).Contenido;
                        productoSustanciaController.InsertOne(productoSustancia);
                    }
                    else
                    {
                        productoSustancia.Contenido = productos.FirstOrDefault(x => x.ProductoId.Equals(productoSustancia.ProductoId)) == null ? "" : productos.FirstOrDefault(x => x.ProductoId.Equals(productoSustancia.ProductoId)).Contenido;
                        productoSustanciaController.Update(productoSustancia);
                    }
                }
                Ambiente.Mensaje("Proceso concluido");
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.ToString());
            }
        }
        private void AnalyseTable(string file, MigrationTask task)
        {
            JObject obj               = LoadAndDeserialize(file);
            JArray  tables            = obj["tables"] as JArray;
            List <MigrationTable> buf = new List <MigrationTable>();

            task.Params = obj["params"].ToString();

            // #1: 获取所有表
            for (int i = 0; i < tables.Count; i++)
            {
                JObject        o     = tables[i] as JObject;
                string[]       names = o["name"].ToString().Split(',');
                MigrationTable table = new MigrationTable()
                {
                    SourceName   = Table.AnalyseName(names[0]),
                    SourceSchema = Table.AnalyseSchema(names[0]),
                    DestName     = Table.AnalyseName(names.Length > 1 ? names[1] : names[0]),
                    DestSchema   = Table.AnalyseSchema(names.Length > 1 ? names[1] : names[0]),
                    Order        = int.Parse(o["order"].ToString()),
                    OrderSQL     = o["orderSQL"].ToString(),
                    WhereSQL     = o["whereSQL"].ToString(),
                    PageSize     = uint.Parse(o["pageSize"].ToString()),
                    WriteMode    = "UPDATE".Equals(o["mode"].ToString().ToUpper()) ? WriteModes.Update : WriteModes.Append,
                    KeyFields    = o["keyFields"].ToString().Split(','),
                    SkipFields   = o["skipFields"].ToString().Split(','),
                    Filter       = o["filter"].ToString(),
                    KeepIdentity = true,
                    DestFields   = new string[] { },
                    References   = o.ContainsKey("references") ? o["references"].ToString().Split(',') : new string[] { },
                    Total        = 0,
                    Progress     = 0,
                    Status       = DataStates.Idle
                };

                buf.Add(table);

                if (table.WriteMode == WriteModes.Update && "".Equals(table.KeyFields[0]))
                {
                    throw new Exception($"表 {table.SourceName} 配置有误!更新模式必须指定主键字段(keyFields)。");
                }
                if ("".Equals(table.OrderSQL))
                {
                    throw new Exception($"表 {table.SourceName} 配置有误!必须指定稳定的排序规则(orderSQL)。");
                }
                if (table.PageSize <= 0)
                {
                    throw new Exception($"表 {table.SourceName} 配置有误!批量记录数必须大于零(pageSize)。");
                }
            }

            // #2: 生成结构
            if (buf.Count > 0)
            {
                buf.Sort(new TableComparer());

                int order = buf[0].Order;
                List <MigrationTable> tmpBuf = new List <MigrationTable>()
                {
                    buf[0]
                };
                List <List <MigrationTable> > rstBuf = new List <List <MigrationTable> >()
                {
                    tmpBuf
                };

                for (int i = 1; i < buf.Count; i++)
                {
                    if (buf[i].Order != order)
                    {
                        tmpBuf = new List <MigrationTable>()
                        {
                            buf[i]
                        };
                        rstBuf.Add(tmpBuf);
                        order = buf[i].Order;
                    }
                    else
                    {
                        tmpBuf.Add(buf[i]);
                    }
                }

                task.Tables = new MigrationTable[rstBuf.Count][];
                for (int i = 0; i < task.Tables.Length; i++)
                {
                    task.Tables[i] = rstBuf[i].ToArray();
                }
            }
            else
            {
                task.Tables = new MigrationTable[][] { }
            };
        }
Beispiel #26
0
        private void SincronizaLotes()
        {
            try
            {
                migrationTable  = migrationTableController.SelectOne(8);
                migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId);
                Sql             = "SELECT ";

                foreach (var f in migrationFields)
                {
                    if (migrationFields.Last() == f)
                    {
                        Sql += f.Expresion + " FROM " + migrationTable.Tabla;
                    }
                    else
                    {
                        Sql += f.Expresion + " , ";
                    }
                }
                Sql += " " + migrationTable.Condicion;
                GetDataTable(Sql);
                lote      = null;
                lotes     = loteController.SelectAll();
                productos = productoController.SelectAll();


                decimal  i = 0;
                DateTime dateTime;
                foreach (DataRow row in dataTable.Rows)
                {
                    Ambiente.S1 = row["producto"].ToString().Trim().ToUpper();
                    Ambiente.S2 = row["lote"].ToString().Trim().ToUpper();
                    Ambiente.S3 = "";
                    //var d = row["caducidad"].ToString().Trim();

                    Ambiente.Datetime1 = DateTime.TryParse(row["caducidad"].ToString().Trim(), out dateTime) == true ? dateTime : DateTime.Now;

                    Ambiente.Decimal1 = decimal.TryParse(row["cant"].ToString().Trim(), out i) == true ? i : 0;
                    Ambiente.Decimal2 = decimal.TryParse(row["cant_orig"].ToString().Trim(), out i) == true ? i : 0;
                    Ambiente.Decimal2 = Ambiente.Decimal2 == 0 ? Ambiente.Decimal1 : Ambiente.Decimal2;


                    lote = null;
                    lote = lotes.FirstOrDefault(x => x.ProductoId.ToUpper().Equals(Ambiente.S1) && x.NoLote.ToUpper().Equals(Ambiente.S2.ToUpper()));

                    if (lote == null)
                    {
                        producto = productos.FirstOrDefault(x => x.ProductoId.ToUpper().Equals(Ambiente.S1.ToUpper()));

                        if (producto == null)
                        {
                            Ambiente.S3 += " NO EXISTE PROD, " + Ambiente.S1 + " \n";
                            continue;
                        }


                        lote               = new Lote();
                        lote.ProductoId    = Ambiente.S1;
                        lote.NoLote        = Ambiente.S2.ToUpper();
                        lote.Caducidad     = Ambiente.Datetime1;
                        lote.StockInicial  = Ambiente.Decimal2;
                        lote.StockRestante = Ambiente.Decimal1;
                        lote.CreatedAt     = DateTime.Now;
                        lote.CreatedBy     = "JMENDOZAJ";
                        loteController.InsertOne(lote);
                    }
                    else
                    {
                        lote.ProductoId    = Ambiente.S1;
                        lote.NoLote        = Ambiente.S2.ToUpper();
                        lote.Caducidad     = Ambiente.Datetime1;
                        lote.StockInicial  = Ambiente.Decimal2;
                        lote.StockRestante = Ambiente.Decimal1;
                        lote.CreatedAt     = DateTime.Now;
                        lote.CreatedBy     = "JMENDOZAJ";
                        loteController.Update(lote);
                    }
                }

                //foreach (var l in lotes)
                //{
                //    producto = productos.FirstOrDefault(x => x.ProductoId.Equals(l.ProductoId));
                //}
                Ambiente.Mensaje("Proceso concluido");
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.ToString());
            }
        }
 public Migration(MigrationTable table)
 {
     Table = table;
 }
Beispiel #28
0
        private void Sincronizaprodsalma()
        {
            try
            {
                migrationTable  = migrationTableController.SelectOne(11);
                migrationFields = migrationFieldController.SelectByTableId(migrationTable.MigrationTableId);
                Sql             = "SELECT ";

                foreach (var f in migrationFields)
                {
                    if (migrationFields.Last() == f)
                    {
                        Sql += f.Expresion + " FROM " + migrationTable.Tabla;
                    }
                    else
                    {
                        Sql += f.Expresion + " , ";
                    }
                }
                Sql += " " + migrationTable.Condicion;
                GetDataTable(Sql);

                productos = productoController.SelectAll();

                decimal i = 0;
                int     I = 0;
                Ambiente.S20 = "AJUSTADO X SINCRONIZACION \n";

                cierreInventario = new CierreInventario();
                cierreInventario.FechaInicial      = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                cierreInventario.FechaFinal        = cierreInventario.FechaInicial.AddMonths(1).AddDays(-1);
                cierreInventario.FechaProgramacion = cierreInventario.FechaFinal.AddDays(1);
                cierreInventario.Etapa1Generada    = true;
                cierreInventario.Etapa2Generada    = false;
                cierreInventario.CreatedAt         = DateTime.Now;
                cierreInventario.CreatedBy         = Ambiente.LoggedUser.UsuarioId;
                cierreInventario.EstacionId        = Ambiente.Estacion.EstacionId;
                cierreInventarioController.InsertOne(cierreInventario);


                foreach (DataRow row in dataTable.Rows)
                {
                    Ambiente.S1       = row["producto"].ToString().Trim().ToUpper();
                    Ambiente.Decimal1 = decimal.TryParse(row["existenc"].ToString().Trim(), out i) == true ? i : 0;
                    Ambiente.Int1     = int.TryParse(row["min"].ToString().Trim(), out I) == true ? I : 0;
                    Ambiente.Int2     = int.TryParse(row["max"].ToString().Trim(), out I) == true ? I : 0;

                    producto = productos.FirstOrDefault(x => x.ProductoId.ToUpper().Equals(Ambiente.S1));

                    if (producto != null)
                    {
                        producto.Stock      = Ambiente.Decimal1;
                        producto.Min        = Ambiente.Int1;
                        producto.Max        = Ambiente.Int2;
                        producto.ValorStock = producto.Costopp * producto.Stock;
                        //**********Cierre inventariop****************//

                        cierreInventariop = new CierreInventariop();
                        cierreInventariop.CierreInventarioId = cierreInventario.CierreInventarioId;
                        cierreInventariop.ProductoId         = producto.ProductoId;
                        cierreInventariop.Descripcion        = producto.Descripcion;
                        cierreInventariop.InvInicial         = producto.Stock;
                        cierreInventariop.Entradas           = 0;
                        cierreInventariop.Salidas            = 0;
                        cierreInventariop.UltimoCosto        = producto.UltimoCosto;
                        cierreInventariop.PrevioVta          = producto.Precio1;
                        cierreInventariop.ValorCosto         = 0;
                        cierreInventariop.ValorVenta         = 0;
                        cierreInventariopController.InsertOne(cierreInventariop);

                        if (producto.TieneLote)
                        {
                            var lotes = loteController.SelecByProducConRestanteCeros(producto);
                            Ambiente.Decimal6 = 0;

                            if (lotes != null)
                            {
                                if (lotes.Count > 0)
                                {
                                    Ambiente.Decimal6 = Ambiente.Decimal1 / lotes.Count;
                                    foreach (var l in lotes)
                                    {
                                        l.StockInicial  = Ambiente.Decimal6;
                                        l.StockRestante = Ambiente.Decimal6;
                                        loteController.Update(l);
                                    }
                                }
                                else
                                {
                                    var l = new Lote();
                                    l.CompraId         = 0;
                                    l.NoLote           = "L0001";
                                    l.ProductoId       = producto.ProductoId;
                                    l.StockInicial     = producto.Stock;
                                    l.StockRestante    = producto.Stock;
                                    l.Caducidad        = DateTime.Now.AddDays(365);
                                    l.CreatedBy        = Ambiente.LoggedUser.UsuarioId;
                                    l.CreatedAt        = DateTime.Now;
                                    l.ReferenciaInt    = 0;
                                    l.ReferenciaString = "AJUSTADO X SINCRONIZACION";
                                    loteController.InsertOne(l);

                                    Ambiente.S20 += " PRODUCTOID: " + producto.ProductoId + " STOCK: " + producto.Stock + " CONTROL_LOTE: TRUE LOTES ENCONTRADOS: " + lotes.Count + "\n";
                                }
                            }
                        }
                        //**************MOVIMIENTO DE INVENTARIO****************//
                        var movInv = new MovInv();
                        movInv.FechaOperacion    = DateTime.Now;
                        movInv.ConceptoMovsInvId = "IIN";
                        movInv.ProductoId        = producto.ProductoId;
                        movInv.CreatedBy         = Ambiente.LoggedUser.UsuarioId;
                        movInv.ProveedorId       = "";
                        movInv.ClienteId         = "";
                        movInv.EstacionId        = Ambiente.Estacion.EstacionId;
                        movInv.ReferenciaId      = 0;
                        movInv.ReferenciapId     = 0;
                        movInv.Es             = "E";
                        movInv.Cantidad       = producto.Stock;
                        movInv.UltimoCosto    = producto.UltimoCosto;
                        movInv.Costopp        = producto.Costopp;
                        movInv.Valor          = producto.Stock * producto.UltimoCosto;
                        movInv.StockAlMomento = 0;
                        movInv.PrecioVta      = producto.Precio1;
                        movInv.Afectacion     = movInv.Es.Equals("E") ? 1 : -1;
                        movInv.IsDeleted      = false;
                        movInv.TieneLote      = false;
                        movInv.NoLote         = "";
                        movInv.Caducidad      = DateTime.Now;
                        movInv.CreatedAt      = DateTime.Now;
                        movInvController.InsertOne(movInv);

                        productoController.Update(producto);
                    }
                    else
                    {
                        Ambiente.S2 += " NO EXISTE " + Ambiente.S1 + " \n";
                    }
                }
                Ambiente.Mensaje("Proceso concluido");
                if (Ambiente.S20.Length > 30)
                {
                    Ambiente.Mensaje(Ambiente.S20);
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.ToString());
            }
        }