//Constructor public Control() { Factory = new DaoFactory(); DocMngr = new DocumentMngr(); LabelMngr = new LabelMngr(); TranMngr = new TransactionMngr(); ErpMngr = new ErpDataMngr(); RptMngr = new ReportMngr(); BasicMngr = new BasicMngr(); MsgMngr = new MessageMngr(); WType = new WmsTypes(); }
public void CreateScheduledCount() { DocumentType docType = new DocumentType { DocClass = new DocumentClass { DocClassID = SDocClass.Task } }; docType.DocTypeID = SDocType.CountTask; // search for the Scheduled counts... IList <CountSchedule> list = Factory.DaoCountSchedule().Select(new CountSchedule { NextDateRun = DateTime.Today, IsDone = false }); foreach (CountSchedule sch in list) { Document document = new Document { Comment = "Scheduled Counting : " + sch.Title, DocType = docType, CrossDocking = false, IsFromErp = false, Location = sch.Location, Company = sch.Location.Company, Date1 = DateTime.Today, CreationDate = DateTime.Now, CreatedBy = WmsSetupValues.SystemUser, Notes = sch.CountOption.ToString() }; document = DocMngr.CreateNewDocument(document, true); // parametros para ejecutar el query DataSet paramsQuery = BasicMngr.GetDataSet(sch.Parameters); // ejecuta el query q trae los productos/bines DataSet dataSet = Factory.DaoIqReport().GetReportObject(sch.Query, paramsQuery); bool useProduct = true; if (sch.CountOption == 0) //Only BIN { useProduct = false; } foreach (DataRow row in dataSet.Tables[0].Rows) { // siempre deben enviar los alias "producto" "binCode" en el reporte !!! Product prod = null; try { if (!string.IsNullOrEmpty(row["Product"].ToString()) && useProduct) { prod = Factory.DaoProduct().Select(new Product { ProductCode = row["Product"].ToString() }, 0)[0]; } } catch { } Bin bin = null; try { if (!string.IsNullOrEmpty(row["BinCode"].ToString())) { bin = Factory.DaoBin().Select(new Bin { BinCode = row["BinCode"].ToString() })[0]; } } catch { } //Crea el BinTask x prod/bin BinByTask binByTask = new BinByTask { CreatedBy = WmsSetupValues.SystemUser, CreationDate = DateTime.Now, Bin = bin, Product = prod, TaskDocument = document, Status = new Status { StatusID = DocStatus.New } }; try { Factory.DaoBinByTask().Save(binByTask); } catch (Exception e) { continue; } } // programamos sgte fecha de conteo (si no se pasa de la fecha final) if (sch.NextDateRun.Value.AddDays(double.Parse(sch.RepeatEach.ToString())) <= sch.Finish.Value) { sch.NextDateRun = sch.NextDateRun.Value.AddDays(double.Parse(sch.RepeatEach.ToString())); } else // ya finaliza el conteo repetitivo { sch.IsDone = true; } sch.ModDate = DateTime.Now; sch.ModifiedBy = WmsSetupValues.SystemUser; Factory.DaoCountSchedule().Update(sch); } }
public static void DataBaseRoutines() { Connection localSQL = null; BasicMngr BasicMngr = new BasicMngr(); DaoFactory Factory = new DaoFactory(); try { localSQL = Factory.DaoConnection().Select(new Connection { Name = "MY" }).First(); } catch { } try { //BasicMngr.DirectSQLNonQuery("EXEC WMS30.dbo.spRoutines", localSQL); Console.WriteLine("\tRoutines OK."); } catch (Exception ex) { Console.WriteLine("\tRoutines Fail. " + ex.Message); } //REcorre los rtProcess que este pendientes por actulizar las tablas de consulta y las actuliza //1. Consultar lo procesosa //Aqui obtiene los registros XML que tiene que procesar IList <DataInformation> list = Factory.DaoDataInformation().Select( new DataInformation { ModTerminal = "T" }).Where(f => f.EntityRowID > 0).ToList(); if (list != null && list.Count > 0) { Document Document; Label Label; string NombreTabla = ""; string updQuery = ""; IList <ShowData> metaData; foreach (DataInformation di in list.Where(f => !string.IsNullOrEmpty(f.XmlData))) { try { if (di.Entity.ClassEntityID == EntityID.Document) { //Obtengo los datos del documento para tener el nombre de la bodega Document = Factory.DaoDocument().Select(new Document { DocID = di.EntityRowID }).First(); //Obtengo el nombre de la bodega que pertenece el registro y creo el nombre de la tabla NombreTabla = "Datos_" + Document.Location.ErpCode; } else if (di.Entity.ClassEntityID == EntityID.Label) { //Obtengo los datos del label para tener el nombre de la bodega Label = Factory.DaoLabel().Select(new Label { LabelID = di.EntityRowID }).First(); try { Location location = Factory.DaoLocation().Select(new Location { LocationID = int.Parse(Label.CreTerminal) }).First(); NombreTabla = "Datos_" + location.ErpCode; } catch { //Obtengo el nombre de la bodega que pertenece el registro y creo el nombre de la tabla NombreTabla = "Datos_" + Label.Bin.Location.ErpCode; } } //Parte incial del update updQuery = "UPDATE dbo." + NombreTabla + " SET ModDate = GETDATE(), RowID = " + di.EntityRowID.ToString() + " "; //Obtiene la lista de campos a actualizar segun la bodega //Es decir los codgios de campos que son tus nombres de columna metaData = DeserializeMetaDataWF(di.XmlData); if (metaData.Count == 0) { di.ModTerminal = null; Factory.DaoDataInformation().Update(di); continue; } //Crear el Update //Aqui va contacenando nombre columna y valor para el update List <string> sColumns = new List <string>(); for (int i = 0; i < metaData.Count; i++) { if (metaData[i].DataKey.ToLower().Equals("id")) { continue; } if (metaData[i].DataKey.ToLower().Equals("productid")) { continue; } if (metaData[i].DataKey.ToLower().Equals("producto")) { continue; } if (metaData[i].DataKey.ToLower().Equals("cantidad")) { continue; } if (!sColumns.Contains(metaData[i].DataKey)) { updQuery += "," + metaData[i].DataKey + " = '" + metaData[i].DataValue + "' \n"; sColumns.Add(metaData[i].DataKey); } } //parte final del update updQuery += " WHERE InstanceID = " + di.RowID.ToString(); //Intenta crear el ID por si no existe //Esto lo hace por si el registro que vpy a actualizar no existe, entonces ///primero se crea un registro en blano en la tabla para que el update funcione ///el ID del registro deberia ser el LabelID para elc aso de los labels y el docuemntid en los docuemntos try { BasicMngr.DirectSQLNonQuery("EXEC dbo.spAdminDynamicData 2, " + di.RowID.ToString() + ",'" + NombreTabla + "'," + di.Entity.ClassEntityID.ToString(), localSQL); } catch { } //Ejecutando el query BasicMngr.DirectSQLNonQuery(updQuery, localSQL); //POniendo la entidad como actualizada di.ModTerminal = null; Factory.DaoDataInformation().Update(di); Console.WriteLine("OK => " + di.EntityRowID + ". " + di.RowID); } catch (Exception ex) { //report the mistake. ExceptionMngr.WriteEvent("Routines: ", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business); Console.WriteLine(" ERR => " + di.EntityRowID + ". " + di.RowID + ". " + ex.Message); } } } try { //Missing process, si pasadas dos horas falta label o proceso el proceso se recrea a partir del dato recibido. //MissingProcess(localSQL); } catch (Exception ex) { //report the mistake. ExceptionMngr.WriteEvent("Routines: MissingProcess", ListValues.EventType.Fatal, ex, null, ListValues.ErrorCategory.Business); } }