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(); }
private static void AddGroups(int idTeacher, LIVEX.UserControls.NominaMaestros nom, string[] ciclo) { livexEntities context = new livexEntities(); List <grupo> lstg = new List <grupo>(); int numCycle = Int32.Parse(ciclo[1]); string cycleside = ciclo[2]; string startDate = ciclo[4]; string endDate = ciclo[6]; DateTime date1 = Convert.ToDateTime(startDate); DateTime date2 = Convert.ToDateTime(endDate); ciclo c = context.ciclo.FirstOrDefault(x => x.ciclo_num == numCycle && x.ciclo_side == cycleside && x.Fecha_inicio == startDate && x.Fecha_fin == endDate); List <ciclo> lstCyclesC = context.ciclo.Where(x => x.ciclo_side == "C" && x.year == date1.Year).ToList();// all the 1:1 and enterprise cycles of the year List <ciclo> lstCs = new List <LIVEX.ciclo>(); if (c != null) { lstg = context.grupo.Where(x => x.teacher.idteacher == idTeacher && x.CicloID == c.idciclo).ToList(); foreach (ciclo iC in lstCyclesC) { bool addCycle = false; DateTime d1 = Convert.ToDateTime(iC.Fecha_inicio); DateTime d2 = Convert.ToDateTime(iC.Fecha_fin); if (date1 >= d1 && date1 <= d2) { addCycle = true; } if (addCycle) { //lstCs.Add(iC); grupo g = context.grupo.FirstOrDefault(x => x.teacher.idteacher == idTeacher && x.CicloID == iC.idciclo); if (g != null) { lstg.Add(g); } } } } if (lstg != null) { for (int x = 0; x < lstg.Count; x++) { Grid grdGroup = new Grid(); Thickness margin = grdGroup.Margin; margin.Top = 20; grdGroup.Margin = margin; //Columns ColumnDefinition col1 = new ColumnDefinition(); ColumnDefinition col2 = new ColumnDefinition(); ColumnDefinition col3 = new ColumnDefinition(); ColumnDefinition col4 = new ColumnDefinition(); ColumnDefinition col5 = new ColumnDefinition(); ColumnDefinition col6 = new ColumnDefinition(); ColumnDefinition col7 = new ColumnDefinition(); grdGroup.ColumnDefinitions.Add(col1); grdGroup.ColumnDefinitions.Add(col2); grdGroup.ColumnDefinitions.Add(col3); grdGroup.ColumnDefinitions.Add(col4); grdGroup.ColumnDefinitions.Add(col5); grdGroup.ColumnDefinitions.Add(col6); grdGroup.ColumnDefinitions.Add(col7); //Row RowDefinition row1 = new RowDefinition(); RowDefinition row2 = new RowDefinition(); row2.Height = new GridLength(48); RowDefinition row3 = new RowDefinition(); grdGroup.RowDefinitions.Add(row1); grdGroup.RowDefinitions.Add(row2); grdGroup.RowDefinitions.Add(row3); //Column Header Border myborderGrupo = new Border(); Border myborderHorario = new Border(); Border myborderHr = new Border(); Border myborderLevel = new Border(); Border myborderNivel = new Border(); Border myborderHoras = new Border(); Border myborderHrs = new Border(); myborderGrupo.Background = Brushes.White; myborderGrupo.BorderBrush = Brushes.Black; myborderGrupo.BorderThickness = new Thickness(2, 2, 1, 0); myborderHrs.BorderThickness = new Thickness(0, 2, 2, 0); myborderHorario.BorderThickness = new Thickness(0, 2, 1, 0); myborderHoras.BorderThickness = myborderNivel.BorderThickness = myborderLevel.BorderThickness = myborderHr.BorderThickness = myborderHorario.BorderThickness; myborderHrs.BorderBrush = myborderHoras.BorderBrush = myborderNivel.BorderBrush = myborderLevel.BorderBrush = myborderHr.BorderBrush = myborderHorario.BorderBrush = myborderGrupo.BorderBrush; myborderHrs.Background = myborderHoras.Background = myborderNivel.Background = myborderLevel.Background = myborderHr.Background = myborderHorario.Background = myborderGrupo.Background; TextBlock txtGrupo = new TextBlock(); txtGrupo.Text = "GRUPO " + (x + 1); txtGrupo.TextAlignment = TextAlignment.Center; txtGrupo.FontWeight = FontWeights.Bold; myborderGrupo.Child = txtGrupo; Grid.SetRow(myborderGrupo, 0); Grid.SetColumn(myborderGrupo, 0); TextBlock txtHorario = new TextBlock(); txtHorario.Text = "HORARIO"; txtHorario.FontWeight = FontWeights.Bold; txtHorario.TextAlignment = TextAlignment.Center; myborderHorario.Child = txtHorario; Grid.SetRow(myborderHorario, 0); Grid.SetColumn(myborderHorario, 1); TextBlock txtHr = new TextBlock(); txtHr.Text = lstg[x].Horario_inicio; txtHr.TextAlignment = TextAlignment.Center; txtHr.FontWeight = FontWeights.Bold; myborderHr.Child = txtHr; Grid.SetRow(myborderHr, 0); Grid.SetColumn(myborderHr, 2); TextBlock txtLevel = new TextBlock(); txtLevel.Text = "NIVEL"; txtLevel.TextAlignment = TextAlignment.Center; txtLevel.FontWeight = FontWeights.Bold; myborderLevel.Child = txtLevel; Grid.SetRow(myborderLevel, 0); Grid.SetColumn(myborderLevel, 3); TextBlock txtNivel = new TextBlock(); txtNivel.Text = lstg[x].nombre_nivel; txtNivel.TextAlignment = TextAlignment.Center; txtNivel.FontWeight = FontWeights.Bold; myborderNivel.Child = txtNivel; Grid.SetRow(myborderNivel, 0); Grid.SetColumn(myborderNivel, 4); TextBlock txtHoras = new TextBlock(); txtHoras.Text = "HORAS"; txtHoras.FontWeight = FontWeights.Bold; txtHoras.TextAlignment = TextAlignment.Center; myborderHoras.Child = txtHoras; Grid.SetRow(myborderHoras, 0); Grid.SetColumn(myborderHoras, 5); TextBox txtHrs = new TextBox(); txtHrs.Text = "0"; txtHrs.TextAlignment = TextAlignment.Center; txtHrs.FontWeight = FontWeights.Bold; myborderHrs.Child = txtHrs; txtHrs.KeyUp += new KeyEventHandler(txtHrs_KeyUp); Grid.SetRow(myborderHrs, 0); Grid.SetColumn(myborderHrs, 6); //Add columns header grdGroup.Children.Add(myborderGrupo); grdGroup.Children.Add(myborderHorario); grdGroup.Children.Add(myborderHr); grdGroup.Children.Add(myborderLevel); grdGroup.Children.Add(myborderNivel); grdGroup.Children.Add(myborderHoras); grdGroup.Children.Add(myborderHrs); //Middle Row Border myborderAlumnos = new Border(); Border myborder_SalBase = new Border(); Border myborderComAl = new Border(); Border myborderBAsiP = new Border(); Border myborderBExe = new Border(); Border myborderTotByHr = new Border(); Border myborderTot = new Border(); myborderAlumnos.Background = new SolidColorBrush(Color.FromRgb(25, 156, 174)); myborderAlumnos.BorderBrush = Brushes.Black; myborderAlumnos.BorderThickness = new Thickness(2, 1, 1, 0); myborderTot.BorderThickness = new Thickness(0, 1, 2, 0); myborder_SalBase.BorderThickness = new Thickness(0, 1, 1, 0); myborderTotByHr.BorderThickness = myborderBExe.BorderThickness = myborderBAsiP.BorderThickness = myborderComAl.BorderThickness = myborder_SalBase.BorderThickness; myborderTot.BorderBrush = myborderTotByHr.BorderBrush = myborderBExe.BorderBrush = myborderBAsiP.BorderBrush = myborderComAl.BorderBrush = myborder_SalBase.BorderBrush = myborderAlumnos.BorderBrush; myborderTot.Background = myborderTotByHr.Background = myborderBExe.Background = myborderBAsiP.Background = myborderComAl.Background = myborder_SalBase.Background = myborderAlumnos.Background; TextBlock txtAlumnos = new TextBlock(); txtAlumnos.Text = "# Alumnos "; txtAlumnos.TextAlignment = TextAlignment.Center; myborderAlumnos.Child = txtAlumnos; Grid.SetRow(myborderAlumnos, 1); Grid.SetColumn(myborderAlumnos, 0); TextBlock txtSalBase = new TextBlock(); txtSalBase.Text = "Salario base"; txtSalBase.TextAlignment = TextAlignment.Center; myborder_SalBase.Child = txtSalBase; Grid.SetRow(myborder_SalBase, 1); Grid.SetColumn(myborder_SalBase, 1); TextBlock txtComAl = new TextBlock(); txtComAl.Text = "Comision por\nAlumno"; txtComAl.TextAlignment = TextAlignment.Center; myborderComAl.Child = txtComAl; Grid.SetRow(myborderComAl, 1); Grid.SetColumn(myborderComAl, 2); TextBlock txtBAsiP = new TextBlock(); txtBAsiP.Text = "Bono\nAsistencia y\npuntualidad"; txtBAsiP.TextAlignment = TextAlignment.Center; myborderBAsiP.Child = txtBAsiP; Grid.SetRow(myborderBAsiP, 1); Grid.SetColumn(myborderBAsiP, 3); TextBlock txtBExe = new TextBlock(); txtBExe.Text = "Bono de\nExcelencia "; txtBExe.TextAlignment = TextAlignment.Center; myborderBExe.Child = txtBExe; Grid.SetRow(myborderBExe, 1); Grid.SetColumn(myborderBExe, 4); TextBlock txtTotByHr = new TextBlock(); txtTotByHr.Text = "TOTAL POR\nHORA"; txtTotByHr.TextAlignment = TextAlignment.Center; myborderTotByHr.Child = txtTotByHr; Grid.SetRow(myborderTotByHr, 1); Grid.SetColumn(myborderTotByHr, 5); TextBlock txtTot = new TextBlock(); txtTot.Text = "TOTAL"; txtTot.TextAlignment = TextAlignment.Center; myborderTot.Child = txtTot; Grid.SetRow(myborderTot, 1); Grid.SetColumn(myborderTot, 6); //Add Middle row grdGroup.Children.Add(myborderAlumnos); grdGroup.Children.Add(myborder_SalBase); grdGroup.Children.Add(myborderComAl); grdGroup.Children.Add(myborderBAsiP); grdGroup.Children.Add(myborderBExe); grdGroup.Children.Add(myborderTotByHr); grdGroup.Children.Add(myborderTot); //Last Row Border myborderNoAlumnos = new Border(); Border myborderSalBase = new Border(); Border myborderCComAl = new Border(); Border myborderCBAsiP = new Border(); Border myborderCBExe = new Border(); Border myborderCTotByHr = new Border(); Border mybordercTot = new Border(); myborderNoAlumnos.Background = Brushes.White; myborderCTotByHr.Background = mybordercTot.Background = Brushes.LightBlue; myborderNoAlumnos.BorderBrush = Brushes.Black; myborderNoAlumnos.BorderThickness = new Thickness(2, 1, 1, 2); mybordercTot.BorderThickness = new Thickness(0, 1, 2, 2); myborderCComAl.BorderThickness = new Thickness(0, 1, 1, 2); mybordercTot.BorderBrush = myborderCTotByHr.BorderBrush = myborderCBExe.BorderBrush = myborderCBAsiP.BorderBrush = myborderCComAl.BorderBrush = myborderSalBase.BorderBrush = myborderNoAlumnos.BorderBrush; myborderCBExe.BorderThickness = myborderCBAsiP.BorderThickness = myborderCTotByHr.BorderThickness = myborderSalBase.BorderThickness = myborderCComAl.BorderThickness; myborderCBExe.Background = myborderCBAsiP.Background = myborderCComAl.Background = myborderSalBase.Background = myborderNoAlumnos.Background; TextBlock txtNoAlumnos = new TextBlock(); txtNoAlumnos.Text = lstg[x].numero_alumnos.ToString(); txtNoAlumnos.TextAlignment = TextAlignment.Center; myborderNoAlumnos.Child = txtNoAlumnos; Grid.SetRow(myborderNoAlumnos, 2); Grid.SetColumn(myborderNoAlumnos, 0); TextBlock txtCSalBase = new TextBlock(); txtCSalBase.Text = lstg[x].teacher.salary_base.ToString(); txtCSalBase.TextAlignment = TextAlignment.Center; myborderSalBase.Child = txtCSalBase; Grid.SetRow(myborderSalBase, 2); Grid.SetColumn(myborderSalBase, 1); TextBlock txtCComAl = new TextBlock(); txtCComAl.Text = ((lstg[x].numero_alumnos) * (lstg[x].teacher.salary_base) * (0.15)).ToString(); txtCComAl.TextAlignment = TextAlignment.Center; myborderCComAl.Child = txtCComAl; Grid.SetRow(myborderCComAl, 2); Grid.SetColumn(myborderCComAl, 2); TextBlock txtCBAsiP = new TextBlock(); Decimal bono_asis = (lstg[x].teacher.salary_base + Decimal.Parse(txtCComAl.Text)); txtCBAsiP.TextAlignment = TextAlignment.Center; Decimal Prop_bonoAsis = Decimal.Multiply(bono_asis, 0.2M); txtCBAsiP.Text = Prop_bonoAsis.ToString(); myborderCBAsiP.Child = txtCBAsiP; Grid.SetRow(myborderCBAsiP, 2); Grid.SetColumn(myborderCBAsiP, 3); TextBlock txtCBExe = new TextBlock(); txtCBExe.Text = Prop_bonoAsis.ToString(); txtCBExe.TextAlignment = TextAlignment.Center; myborderCBExe.Child = txtCBExe; Grid.SetRow(myborderCBExe, 2); Grid.SetColumn(myborderCBExe, 4); TextBlock txtCTotByHr = new TextBlock(); txtCTotByHr.Text = (lstg[x].teacher.salary_base + Decimal.Parse(txtCComAl.Text) + Decimal.Parse(txtCBAsiP.Text) + Decimal.Parse(txtCBExe.Text)).ToString(); txtCTotByHr.TextAlignment = TextAlignment.Center; myborderCTotByHr.Child = txtCTotByHr; Grid.SetRow(myborderCTotByHr, 2); Grid.SetColumn(myborderCTotByHr, 5); TextBlock txtcTot = new TextBlock(); txtcTot.Text = Decimal.Multiply(Decimal.Parse(txtCTotByHr.Text), Decimal.Parse(txtHrs.Text)).ToString(); txtcTot.TextAlignment = TextAlignment.Center; txtcTot.FontWeight = FontWeights.Bold; mybordercTot.Child = txtcTot; Grid.SetRow(mybordercTot, 2); Grid.SetColumn(mybordercTot, 6); //Add Last row grdGroup.Children.Add(myborderNoAlumnos); grdGroup.Children.Add(myborderSalBase); grdGroup.Children.Add(myborderCComAl); grdGroup.Children.Add(myborderCBAsiP); grdGroup.Children.Add(myborderCBExe); grdGroup.Children.Add(myborderCTotByHr); grdGroup.Children.Add(mybordercTot); nom.stkContainer.Children.Add(grdGroup); } } }
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()); }