public static void EditSelected(LIVEX.UserControls.AsistenciaMaestros am) { string uid = am.cmbUID.Text; livexEntities context = new livexEntities(); asistencia_maestros teacherAtt = context.asistencia_maestros.FirstOrDefault(x => x.UID == uid); string hour = am.cmbHour.Text; var time = hour.Split(':'); teacherAtt.Name = am.cmbName.Text; teacherAtt.hour = Int32.Parse(time[0]); teacherAtt.min = Int32.Parse(time[1]); if (time.Count() > 2) { teacherAtt.sec = Int32.Parse(time[2]); } else { teacherAtt.sec = 0; } teacherAtt.date = Convert.ToDateTime(am.dpDate.Text); int result = context.SaveChanges(); if (result >= 0) { MessageBox.Show("El registro se guardó exitosamente"); } else { MessageBox.Show("El registro NO se guardó"); } }
public static int uploadTimerFile(string path, string filename) { try { livexEntities context = new livexEntities(); int result = 0; using (var reader = new StreamReader(path))//(@"C:\Users\Tania\Documents\NewCo\Proyectos\LIVEX\Docs\LogData\HisGLog_0001_20171201.csv")) { int isduplicated = context.asistencia_maestros.Count(x => x.filename == filename); if (isduplicated > 0) { MessageBox.Show("El archivo ya ha sido cargado"); return(0); } int i = 0; while (!reader.EndOfStream) { asistencia_maestros am = new asistencia_maestros(); var line = reader.ReadLine(); var values = line.Split('\t'); if (i > 0) { am.No = Int32.Parse(values[0]); am.DN = Int32.Parse(values[1]); am.UID = values[2]; am.Name = values[3]; am.Status = values[4]; am.Action = Int32.Parse(values[5]); am.APB = Int32.Parse(values[6]); am.JobCode = Int32.Parse(values[7]); am.date = Convert.ToDateTime(Convert.ToDateTime(values[8]).ToShortDateString()); am.hour = Convert.ToDateTime(values[8]).Hour; am.min = Convert.ToDateTime(values[8]).Minute; am.sec = Convert.ToDateTime(values[8]).Second; am.filename = filename; context.asistencia_maestros.Add(am); } i++; } result = context.SaveChanges(); } if (result > 0) { MessageBox.Show("Archivo cargado exitosamente"); return(1); } return(0); } catch (Exception e) { MessageBox.Show(e.Message); return(0); } }
public static List <alumno> DeleteTeacher(object row) { alumno a = (alumno)row; livexEntities context = new livexEntities(); alumno aToDelete = context.alumno.FirstOrDefault(x => x.idalumno == a.idalumno); context.alumno.Remove(aToDelete); context.SaveChanges(); List <alumno> lstStudents = context.alumno.ToList(); return(lstStudents); }
public static void DeleteTeacher(object dataRow) { teacher_skillsView ts = (teacher_skillsView)dataRow; livexEntities context = new livexEntities(); List <teacher_skills> ls = new List <teacher_skills>(); teacher t = context.teacher.First(x => x.idteacher == ts.ID); ls = context.teacher_skills.Where(x => x.teacherID == ts.ID).ToList(); foreach (teacher_skills s in ls) { context.teacher_skills.Remove(s); } context.teacher.Remove(t); context.SaveChanges(); }
public static void DeleteRow(LIVEX.UserControls.AsistenciaMaestros am, object attRow) { TeacherAttendanceView row = (TeacherAttendanceView)attRow; livexEntities context = new livexEntities(); asistencia_maestros teacherDelete = context.asistencia_maestros.FirstOrDefault(x => x.asistencia_maestrosID == row.id); if (teacherDelete != null) { context.asistencia_maestros.Remove(teacherDelete); int result = context.SaveChanges(); if (result > 0) { MessageBox.Show("El registro se borró exitosamente"); } else { MessageBox.Show("Error al borrar el registro"); } } }
public static void AddAttendaceRow(LIVEX.UserControls.AsistenciaMaestros am) { livexEntities context = new livexEntities(); asistencia_maestros newAtt = new asistencia_maestros(); DateTime date = Convert.ToDateTime(am.dpDate.Text); string hour = am.cmbHour.Text; var time = hour.Split(':'); newAtt.DN = 1; newAtt.UID = am.cmbUID.Text; newAtt.Name = am.cmbName.Text; newAtt.Status = "0"; newAtt.Action = 3; newAtt.APB = 0; newAtt.JobCode = 0; newAtt.date = Convert.ToDateTime(date.ToShortDateString()); newAtt.No = 0; newAtt.filename = "LIVEX_Sys"; newAtt.hour = Int32.Parse(time[0]); newAtt.min = Int32.Parse(time[1]); if (time.Count() > 2) { newAtt.sec = Int32.Parse(time[2]); } else { newAtt.sec = 0; } context.asistencia_maestros.Add(newAtt); int result = context.SaveChanges(); if (result > 0) { MessageBox.Show("El registro se guardó exitosamente"); } else { MessageBox.Show("El registro NO se guardó"); } }
public static void DeleteGroup(object datarow) { livexEntities context = new livexEntities(); grupo g = (grupo)datarow; ciclo c = context.ciclo.FirstOrDefault(x => x.idciclo == g.CicloID); grupo_categoria gc = context.grupo_categoria.FirstOrDefault(x => x.idgrupo_categoria == g.CategoriaID); grupo grp = context.grupo.FirstOrDefault(x => x.idgrupo == g.idgrupo); if (c != null && c.ciclo_side == "C") { context.ciclo.Remove(c); } if (gc != null) { context.grupo_categoria.Remove(gc); } if (grp != null) { context.grupo.Remove(grp); } context.SaveChanges(); }
public static int SaveSkills(LIVEX.UserControls.AddTeacher teacher_form_values, int teacherID) { livexEntities context = new livexEntities(); //List<teacher_skills> lts = new List<teacher_skills>(); List <int> skID = new List <int>(); if (teacher_form_values.chkTOEFL.IsChecked == true) { skID.Add(1); } if (teacher_form_values.chkExp.IsChecked == true) { skID.Add(2); } if (teacher_form_values.chkTraining.IsChecked == true) { skID.Add(3); } if (teacher_form_values.chkSimilar.IsChecked == true) { skID.Add(4); } foreach (int s in skID) { teacher_skills ts = new teacher_skills(); ts.teacherID = teacherID; ts.skillID = s; context.teacher_skills.Add(ts); } int result = context.SaveChanges(); return(result); }
/// <summary> /// this function creates a new teacher in teachers's table and also adds the list of skills into skill's table /// </summary> /// <param name="teacher_form_values"></param> /// <param name="skills_Values"></param> /// <returns>0-if the DB was updated successfully 1-if there was an exception</returns> public static int SaveTeacher(LIVEX.UserControls.AddTeacher teacher_form_values, int[] skills_Values) { livexEntities context = new livexEntities(); teacher teacher_ = new teacher(); int t_sSaved = 0; int result = 0; //int maxTeacherID = context.teacher.Count(); //int maxTeacher_skillID = context.teacher_skills.Count(); //teacher_.idteacher = maxTeacherID + 1; teacher_.teacher_names = teacher_form_values.txtNewTeacherName.Text; teacher_.teacher_lastname = teacher_form_values.txtNewTeacherApellidos.Text; teacher_.RFC = teacher_form_values.txtTeacherRFC.Text; teacher_.CURP = teacher_form_values.txtTeacherCURP.Text; teacher_.phone = teacher_form_values.txtAddressPhone.Text; teacher_.celphone = teacher_form_values.txtCelPhone.Text; teacher_.email = teacher_form_values.txtEmail.Text; teacher_.birthday = teacher_form_values.dpBirthday.Text; teacher_.street_address = teacher_form_values.txtAddress.Text; teacher_.neighborhood = teacher_form_values.txtNeighbordhood.Text; teacher_.zip_code = teacher_form_values.txtZipCode.Text; teacher_.state = teacher_form_values.txtState.Text; teacher_.sub_state = teacher_form_values.txtSubState.Text; teacher_.emergency_contact_name = teacher_form_values.txtEmergencyName.Text; teacher_.emergency_contact_number = teacher_form_values.txtEmergencyPhone.Text; teacher_.start_date = teacher_form_values.dpStartDate.Text; teacher_.uid = teacher_form_values.txtUID.Text; if (teacher_form_values.imgTeacher.ImageSource != null) { teacher_.picture = teacher_form_values.imgTeacher.ImageSource.ToString(); } else { teacher_.picture = ""; } if (teacher_form_values.rbtnTeacherFemenio.IsChecked == true)//Femenino { teacher_.teacher_gender = "F"; } else if (teacher_form_values.rbtnTeacherMasculino.IsChecked == true)//Masculino { teacher_.teacher_gender = "M"; } teacher_.salary_base = Int32.Parse(teacher_form_values.txtSalarioBase.Text); if (teacher_form_values.rbtnIngles.IsChecked == true)//Ingles { teacher_.language = "Ingles"; } else if (teacher_form_values.rbtnFrances.IsChecked == true)//Frances { teacher_.language = "Frances"; } for (int i = 0; i < skills_Values.Count(); i++) { if (skills_Values[i] == 1) { teacher_skills teacher_Skill = new teacher_skills(); teacher_Skill.skillID = i + 1; teacher_Skill.teacherID = teacher_.idteacher; teacher_Skill.teacher = teacher_; teacher_.teacher_skills.Add(teacher_Skill); //context.teacher_skills.Add(teacher_Skill); //t_sSaved = context.SaveChanges(); } } context.teacher.Add(teacher_); int teachersaved = context.SaveChanges(); //if (teachersaved > 0) //{ // //teacher_Skill.idteacher_skills = maxTeacher_skillID + 1; // teacher_Skill.teacherID = teacher_.idteacher; // for(int i=0; i<skills_Values.Count();i++) // { // if (skills_Values[i] == 1) // { // teacher_Skill.skillID = i+1; // context.teacher_skills.Add(teacher_Skill); // t_sSaved = context.SaveChanges(); // } // } //} //if (t_sSaved > 0 && teachersaved > 0) // result = 0; //else // result = -1; return(result); }
public static int SaveEditTeacher(LIVEX.UserControls.AddTeacher teacher_form_values, int teacherID) { livexEntities context = new livexEntities(); teacher t = new teacher(); bool[] skills = new bool[4]; List <teacher_skills> sl = new List <teacher_skills>(); int result = 0; int resultS = 0; t = context.teacher.FirstOrDefault(x => x.idteacher == teacherID); //sl = context.teacher_skills.Where(x => x.teacherID == teacherID).ToList(); //foreach (teacher_skills s in sl) foreach (teacher_skills s in t.teacher_skills) { switch (s.skillID) { case 1: skills[0] = true; break; case 2: skills[1] = true; break; case 3: skills[2] = true; break; case 4: skills[3] = true; break; } } if (teacher_form_values.chkTOEFL.IsChecked == true) { if (!skills[0]) { teacher_skills ts = new teacher_skills(); ts.skillID = 1; ts.teacher = t; t.teacher_skills.Add(ts); } } if (teacher_form_values.chkExp.IsChecked == true) { if (!skills[1]) { teacher_skills ts = new teacher_skills(); ts.skillID = 2; ts.teacher = t; t.teacher_skills.Add(ts); } } if (teacher_form_values.chkTraining.IsChecked == true) { if (!skills[2]) { teacher_skills ts = new teacher_skills(); ts.skillID = 3; ts.teacher = t; t.teacher_skills.Add(ts); } } if (teacher_form_values.chkSimilar.IsChecked == true) { if (!skills[3]) { teacher_skills ts = new teacher_skills(); ts.skillID = 4; ts.teacher = t; t.teacher_skills.Add(ts); } } t.teacher_names = teacher_form_values.txtNewTeacherName.Text; t.teacher_lastname = teacher_form_values.txtNewTeacherApellidos.Text; t.RFC = teacher_form_values.txtTeacherRFC.Text; t.CURP = teacher_form_values.txtTeacherCURP.Text; t.phone = teacher_form_values.txtAddressPhone.Text; t.celphone = teacher_form_values.txtCelPhone.Text; t.email = teacher_form_values.txtEmail.Text; t.birthday = teacher_form_values.dpBirthday.Text; t.street_address = teacher_form_values.txtAddress.Text; t.neighborhood = teacher_form_values.txtNeighbordhood.Text; t.zip_code = teacher_form_values.txtZipCode.Text; t.state = teacher_form_values.txtState.Text; t.sub_state = teacher_form_values.txtSubState.Text; t.emergency_contact_name = teacher_form_values.txtEmergencyName.Text; t.emergency_contact_number = teacher_form_values.txtEmergencyPhone.Text; t.start_date = teacher_form_values.dpStartDate.Text; t.uid = teacher_form_values.txtUID.Text; if (teacher_form_values.imgTeacher.ImageSource != null) { t.picture = teacher_form_values.imgTeacher.ImageSource.ToString(); } else { t.picture = ""; } if (teacher_form_values.rbtnTeacherFemenio.IsChecked == true) { t.teacher_gender = "F"; } else { t.teacher_gender = "M"; } if (teacher_form_values.rbtnIngles.IsChecked == true) { t.language = "Ingles"; } else { t.language = "Frances"; } t.salary_base = Int32.Parse(teacher_form_values.txtSalarioBase.Text); int resultT = context.SaveChanges(); //if(resultT>=0) //{ // resultS = SaveSkills(teacher_form_values,teacherID); //} if (resultS >= 0 && resultT >= 0) { result = 0; } else { result = -1; } return(result); }
public static int saveEditStudent(LIVEX.UserControls.AddStudent s) { livexEntities context = new livexEntities(); int id = Int32.Parse(s.txtID.Text); alumno a = context.alumno.FirstOrDefault(x => x.idalumno == id); a.alumno_nombre = s.txtName.Text; a.alumno_apellido_p = s.txtLastName.Text; a.alumno_apellido_m = s.txtMotherName.Text; a.fecha_nac = s.dtpBirthDay.Text; a.telefono_casa = s.txtPhoneHome.Text; a.telefono_celular = s.txtCellPhone.Text; a.domicilio_calle = s.txtStreet.Text; a.domicilio_no = s.txtNumExt.Text; a.domicilio_col = s.txtCol.Text; a.domicilio_mun = s.cmbMunicipio.Text; a.domicilio_cp = s.txtZipCode.Text; a.domicilio_edo = s.cmbState.Text; string levelnum = ""; string leveltype = ""; if (s.cmbNivel12.Visibility == Visibility.Visible) { levelnum = s.cmbNivel12.Text; } else { levelnum = s.cmbNivel4.Text; } if (s.cmbTipo.Visibility == Visibility.Visible) { leveltype = s.cmbTipo.Text; } else { leveltype = s.cmbTipo2.Text; } a.curso_inicial = s.cmbCategoria.Text + " " + levelnum + " " + leveltype; if (s.imgStudent.ImageSource != null) { a.picture = s.imgStudent.ImageSource.ToString(); } else { a.picture = ""; } if (s.chkInvoicing.IsChecked == true) { alumno_factura af = new alumno_factura(); af.nombre = s.txtNameInvo.Text; af.rfc = s.txtRfc.Text; af.estado = s.cmbStateInv.Text; af.ciudad = s.cmbCiudadInv.Text; af.direccion = s.txtAdressInv.Text; af.direccion_no = s.txtNumAddinv.Text; af.colonia = s.txtNeighInv.Text; af.cp = s.txtZipCode.Text; a.alumno_factura = af; } int result = context.SaveChanges(); return(result); }
public static int SaveEditGroup(LIVEX.UserControls.NewGroup editGroup, int idGroupCat, grupo grupo) { livexEntities context = new livexEntities(); grupo g = context.grupo.FirstOrDefault(x => x.idgrupo == grupo.idgrupo); //grupo_categoria gc = context.grupo_categoria.FirstOrDefault(x => x.idgrupo_categoria == idGroupCat); //grupo g = context.grupo.FirstOrDefault(x =>x.idgrupo==gc.grupo_ID); //ciclo c = context.ciclo.FirstOrDefault(x => x.idciclo == g.CicloID); string catname = editGroup.cmbCategoria.SelectionBoxItem.ToString(); string cycle = "", cycleSide = ""; if (editGroup.cmbCicloEscolar.Visibility == Visibility.Visible) { cycle = editGroup.cmbCicloEscolar.SelectedValue.ToString(); cycleSide = "A"; } else { cycle = editGroup.cmbCiclo.SelectedValue.ToString(); cycleSide = "C"; } int cycleNum = Int32.Parse(cycle); ciclo idCiclo = context.ciclo.FirstOrDefault(x => x.ciclo_num == cycleNum && x.year == DateTime.Today.Year && x.ciclo_side == cycleSide); string nivel, dias = "", idioma = ""; ComboBox cmb = new ComboBox(); if (editGroup.chkingles.IsChecked == true) { idioma = "Inglés"; } else { idioma = "Francés"; } string l = "", m = "", mi = "", j = "", v = "", s = ""; foreach (ListBoxItem i in editGroup.lstDias.SelectedItems) { switch (i.Content) { case "L": l = "L "; break; case "M": m = "M "; break; case "Mi": mi = "Mi "; break; case "J": j = "J "; break; case "V": v = "V "; break; case "S": s = "S "; break; } } dias = l + m + mi + j + v + s; if (editGroup.cmbTipo.Visibility == Visibility.Visible) { cmb = editGroup.cmbTipo; } else { cmb = editGroup.cmbTipo2; } if (editGroup.cmbNivel4.Visibility == Visibility.Visible) { nivel = editGroup.cmbNivel4.SelectionBoxItem.ToString(); } else { nivel = editGroup.cmbNivel12.SelectionBoxItem.ToString(); } //c.Fecha_inicio = editGroup.dtpFechaInicio.Text; //c.Fecha_fin = editGroup.dtpFechaFin.Text; //c.ciclocol = editGroup.cmbCiclo.Text; if (g != null) { //g.ciclo.Fecha_inicio = editGroup.dtpFechaInicio.Text; //g.ciclo.Fecha_fin = editGroup.dtpFechaFin.Text; //g.ciclo.ciclocol = editGroup.cmbCiclo.Text; g.CicloID = idCiclo.idciclo; if (editGroup.dtpFechaFinEscolar.Visibility == Visibility.Visible) { //g.ciclo.Fecha_inicio = editGroup.dtpFechaInicioEscolar.Text; //g.ciclo.Fecha_fin = editGroup.dtpFechaFinEscolar.Text; } else { g.ciclo.Fecha_inicio = editGroup.dtpFechaInicio.Text; g.ciclo.Fecha_fin = editGroup.dtpFechaFin.Text; } g.nombre_nivel = catname + " " + nivel + " " + cmb.SelectionBoxItem.ToString(); g.Horario_inicio = editGroup.cmbHrInicio.SelectionBoxItem.ToString(); g.Horario_fin = editGroup.cmbHrFin.SelectionBoxItem.ToString(); g.Dias = dias; g.MaestroID = Int32.Parse(editGroup.cmbTeacher.SelectedValue.ToString()); g.Idioma = idioma; g.numero_alumnos = Int32.Parse(editGroup.txtCantAlumnos.Text); g.grupo_categoria.nivel = Int32.Parse(nivel); g.grupo_categoria.tipo = cmb.SelectionBoxItem.ToString(); g.grupo_categoria.nivel = Int32.Parse(nivel); g.grupo_categoria.tipo = cmb.SelectionBoxItem.ToString(); g.grupo_categoria.grupo_ID = g.idgrupo; //gc.nivel = Int32.Parse(nivel); //gc.tipo = cmb.SelectionBoxItem.ToString(); context.SaveChanges(); } return(0); }
public static int SaveGroup(LIVEX.UserControls.NewGroup newGroup) { livexEntities context = new livexEntities(); grupo g = new grupo(); //grupo_categoria gc = new grupo_categoria(); //ciclo c = new ciclo(); string catname = newGroup.cmbCategoria.SelectionBoxItem.ToString(); //int maxg = context.grupo.Count(); //int maxc = context.ciclo.Count(); //int maxgc = 0; string clasificacion = ""; string nivel, dias = "", idioma = ""; ComboBox cmb = new ComboBox(); //maxgc = context.grupo_categoria.Count(); if (newGroup.cmbTipo.Visibility == Visibility.Visible) { cmb = newGroup.cmbTipo; } else { cmb = newGroup.cmbTipo2; } if (cmb.Text == "A" || cmb.Text == "B") { clasificacion = "semi-Intensivo"; } else { clasificacion = "Intensivo"; } foreach (ListBoxItem i in newGroup.lstDias.SelectedItems) { dias = dias + " " + i.Content; } if (newGroup.chkingles.IsChecked == true) { idioma = "Inglés"; } else { idioma = "Francés"; } if (newGroup.cmbNivel4.Visibility == Visibility.Visible) { nivel = newGroup.cmbNivel4.SelectionBoxItem.ToString(); } else { nivel = newGroup.cmbNivel12.SelectionBoxItem.ToString(); } //c.Fecha_inicio = newGroup.dtpFechaInicio.Text; //c.Fecha_fin = newGroup.dtpFechaFin.Text; //c.ciclo_nombre = newGroup.cmbCiclo.SelectionBoxItem.ToString(); //context.ciclo.Add(c); //context.SaveChanges(); categoria catid = context.categoria.FirstOrDefault(x => x.categoria_nombre == catname && x.clasificacion == clasificacion); //gc.grupo_ID = maxg + 1; //gc.categoria_ID = catid.idcategoria; //gc.nivel = Int32.Parse(nivel); //gc.tipo = cmb.SelectionBoxItem.ToString(); //context.grupo_categoria.Add(gc); //context.SaveChanges(); g.nombre_nivel = catname + " " + nivel + " " + cmb.SelectionBoxItem.ToString(); g.Horario_inicio = newGroup.cmbHrInicio.SelectionBoxItem.ToString(); g.Horario_fin = newGroup.cmbHrFin.SelectionBoxItem.ToString(); g.Dias = dias; g.MaestroID = Int32.Parse(newGroup.cmbTeacher.SelectedValue.ToString()); teacher t = context.teacher.FirstOrDefault(x => x.idteacher == g.MaestroID); g.teacher = t; g.Idioma = idioma; if (newGroup.cmbCicloEscolar.SelectedValue != null) { g.CicloID = Int32.Parse(newGroup.cmbCicloEscolar.SelectedValue.ToString()); if (newGroup.dtpFechaInicioEscolar.Text != "") { g.year = Convert.ToDateTime(newGroup.dtpFechaInicioEscolar.Text).Year; } } if (newGroup.cmbCiclo.SelectedValue != null) { g.CicloID = Int32.Parse(newGroup.cmbCiclo.SelectedValue.ToString()); if (newGroup.dtpFechaInicio.Text != "" && newGroup.dtpFechaFin.Text != "") { ciclo c = new ciclo(); c.ciclo_num = (int)g.CicloID; c.Fecha_inicio = newGroup.dtpFechaInicio.Text; c.Fecha_fin = newGroup.dtpFechaFin.Text; c.ciclo_side = "C"; c.ciclocol = "C" + " " + g.nombre_nivel; c.year = Convert.ToDateTime(newGroup.dtpFechaInicio.Text).Year; //context.ciclo.Add(c); g.ciclo = c; g.year = Convert.ToDateTime(newGroup.dtpFechaInicio.Text).Year; } } //g.CategoriaID = maxgc + 1; //g.CicloID = maxc + 1; g.numero_alumnos = Int32.Parse(newGroup.txtCantAlumnos.Text); g.grupo_categoria = new grupo_categoria(); g.grupo_categoria.categoria_ID = catid.idcategoria; g.grupo_categoria.nivel = Int32.Parse(nivel); g.grupo_categoria.tipo = cmb.SelectionBoxItem.ToString(); context.grupo.Add(g); //context.SaveChanges(); return(context.SaveChanges()); }