//Devuelve el valor de los elementos Otros sumados. /* private void getTotalOtros() * { * this.TotalesOtros = 0; * object misValue = System.Reflection.Missing.Value; * Excel.Application xlApp = new Excel.Application(); * Excel.Workbook xlWorkbook; * Excel._Worksheet xlWorksheet; * xlWorkbook = xlApp.Workbooks.Open(this.Archivo, Type.Missing, true, Type.Missing, Global.Connect()); * xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); * * Excel.Range xlRange = xlWorksheet.get_Range("A1:H150"); * int rowNumber = xlRange.Rows.Count; * * * for (var i = 1; i < rowNumber; i++) * { * if (xlRange.Cells[i, "C"].Value != null & xlRange.Cells[i, "E"].Value == null) * { * this.TotalesOtros += xlRange.Cells[i, "F"].Value; * } * } * * xlWorkbook.Close(); * xlApp.Quit(); * * Marshal.ReleaseComObject(xlWorksheet); * Marshal.ReleaseComObject(xlWorkbook); * Marshal.ReleaseComObject(xlApp); * }*/ private void getProfesor() { List <ProfesorCorto> auxprofe = new List <ProfesorCorto>(); var client = new MongoClient(Global.Path_DataBase); var database = client.GetDatabase("app_pago"); var collection = database.GetCollection <BsonDocument>("profesor"); var filter = Builders <BsonDocument> .Filter.Empty; var result = collection.Find(filter).ToList(); foreach (var doc in result) { ProfesorCorto aux = new ProfesorCorto(); aux.ProfeNombre = (doc.GetValue("name").AsString); aux.Porcentaje = (doc.GetValue("porcentaje").AsString); auxprofe.Add(aux); } int flag = 0; var collection2 = database.GetCollection <BsonDocument>("cursos"); var result2 = collection2.Find(filter).ToList(); foreach (var doc in result2) { ProfesorCorto aux2 = new ProfesorCorto(); aux2.ProfeNombre = (doc.GetValue("profesor").AsString); aux2.Porcentaje = (doc.GetValue("porcentaje").AsString); bool containsItem = auxprofe.Any(item => item.ProfeNombre == "Profesor Aldo"); if (aux2.ProfeNombre == "Aldo" && flag == 0) { aux2.ProfeNombre = "Profesor Aldo"; auxprofe.Add(aux2); flag = 1; } else if (!(aux2.ProfeNombre == "Aldo")) { auxprofe.Add(aux2); } } ProfesoresCortos = auxprofe; }
private void cierreProfesor(string excel, ProfesorCorto profesor, List <Comprobante_Especial> comprobantesEspeciales) { string carpeta = Global.getDire(); int valorRecaudado = 0; Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook; Excel._Worksheet xlWorksheet; string save = excel + ".xlsx"; try { File.Copy(Global.LiquidacionesLibrosServer + Path.GetFileName(save), Global.Liquidaciones + Path.GetFileName(save), true); } catch (System.IO.FileNotFoundException) { } if (System.IO.File.Exists(save)) { xlWorkbook = xlApp.Workbooks.Open(excel, Type.Missing, Type.Missing, Type.Missing, Global.Connect()); xlWorksheet = (Excel.Worksheet)xlWorkbook.Worksheets.get_Item(1); Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; xlRange.FormulaHidden = true; for (var i = 2; i <= rowCount && xlRange.Cells[rowCount + 2, "E"].Value != "Total"; i++) { valorRecaudado += Convert.ToInt32(xlRange.Cells[i, "F"].Value); } xlRange.Cells[rowCount + 2, "E"] = "Total"; xlRange.Cells[rowCount + 2, "F"] = valorRecaudado; profesor.Total = valorRecaudado; if (!(profesor.ProfeNombre == "Profesor Diego")) { xlRange.Cells[rowCount + 3, "E"] = profesor.Porcentaje + "%"; int porcentaje = Convert.ToInt32(profesor.Porcentaje); xlRange.Cells[rowCount + 3, "F"] = ((valorRecaudado * porcentaje) / 100); } else { xlRange.Cells[rowCount + 3, "E"] = profesor.Porcentaje + "%"; int porcentaje = Convert.ToInt32(profesor.Porcentaje); int porcentaje2 = ((valorRecaudado * porcentaje) / 100); xlRange.Cells[rowCount + 3, "F"] = porcentaje2; xlRange.Cells[rowCount + 4, "F"] = ((porcentaje2 * 66) / 100); xlRange.Cells[rowCount + 5, "F"] = ((porcentaje2 * 33) / 100); } xlRange.Cells[rowCount + 7, "A"] = "Casos Especiales"; int LastPlace = rowCount + 8; foreach (var particular in comprobantesEspeciales) { xlRange.Cells[LastPlace, "A"] = particular.Fecha; xlRange.Cells[LastPlace, "B"] = particular.Nombre; xlRange.Cells[LastPlace, "C"] = particular.Clase_Curso; xlRange.Cells[LastPlace, "D"] = particular.Motivo; xlRange.Cells[LastPlace, "E"] = particular.ComprobanteTalonario; xlRange.Cells[LastPlace, "F"] = particular.Monto; xlRange.Cells[LastPlace, "G"] = particular.Usuario; LastPlace = LastPlace + 1; } xlWorksheet.Range[xlWorksheet.Cells[2, "A"], xlWorksheet.Cells[2, "G"]].Borders.LineStyle = Excel.XlLineStyle.xlContinuous; xlWorksheet.Range[xlWorksheet.Cells[2, "A"], xlWorksheet.Cells[2, "G"]].Borders.Weight = Excel.XlBorderWeight.xlMedium; xlWorksheet.Range[xlWorksheet.Cells[1, "A"], xlWorksheet.Cells[1, "G"]].Font.Bold = true; if (!(profesor.ProfeNombre == "Profesor Diego")) { xlWorksheet.Range[xlWorksheet.Cells[rowCount + 3, "E"], xlWorksheet.Cells[rowCount + 3, "F"]].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.GreenYellow); xlWorksheet.Range[xlWorksheet.Cells[3, "A"], xlWorksheet.Cells[rowCount + 3, "G"]].Borders.LineStyle = Excel.XlLineStyle.xlContinuous; xlWorksheet.Range[xlWorksheet.Cells[3, "A"], xlWorksheet.Cells[rowCount + 3, "G"]].Borders.Weight = Excel.XlBorderWeight.xlThin; } else { xlWorksheet.Range[xlWorksheet.Cells[rowCount + 3, "E"], xlWorksheet.Cells[rowCount + 5, "F"]].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.GreenYellow); xlWorksheet.Range[xlWorksheet.Cells[3, "A"], xlWorksheet.Cells[rowCount + 5, "G"]].Borders.LineStyle = Excel.XlLineStyle.xlContinuous; xlWorksheet.Range[xlWorksheet.Cells[3, "A"], xlWorksheet.Cells[rowCount + 5, "G"]].Borders.Weight = Excel.XlBorderWeight.xlThin; } xlWorksheet.Range[xlWorksheet.Cells[1, "A"], xlWorksheet.Cells[1, "A"]].HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter; xlWorksheet.Range[xlWorksheet.Cells[1, "A"], xlWorksheet.Cells[1, "G"]].Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.GreenYellow); xlWorkbook.Password = Global.Connect(); xlApp.DisplayAlerts = false; xlWorkbook.SaveAs(excel); xlWorkbook.Close(); xlApp.Quit(); Marshal.ReleaseComObject(xlWorksheet); Marshal.ReleaseComObject(xlWorkbook); Marshal.ReleaseComObject(xlApp); File.Copy(Global.Liquidaciones + Path.GetFileName(save), Global.LiquidacionesServer + Path.GetFileName(save), true); } }