/
telefonicasla.cs
141 lines (116 loc) · 4.46 KB
/
telefonicasla.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using DAOLibrary.DTO;
using DAOLibrary.DAO;
namespace CargadeSLA
{
public partial class telefonicasla : Form
{
public telefonicasla()
{
InitializeComponent();
dateTimePicker1.Value = DateTime.Today.AddMonths(-1);
}
private void button1_Click(object sender, EventArgs e)
{
//List<Registro> listaregistro = new List<Registro>();
MessageBox.Show("Comenzamos La Carga, solo tiene que tener columnas CD, Sede, Empresa y Valor Actual. El excel solo debe tener una hoja.");
DAOKpi daok = new DAOKpi();
DAORegistro daor = new DAORegistro();
string Chosen_File = "";
openFileDialog1.Title = "Ingresa la Solicitud";
openFileDialog1.FileName = "";
openFileDialog1.Filter = "Archivos Excel *.xls|*.xls*";
openFileDialog1.ShowDialog();
Chosen_File = openFileDialog1.FileName;
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
if (Chosen_File == "")
{
MessageBox.Show("No ha Seleccionado ningun Archivo");
}
else
{
//Sentencias Excel
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.Application();
xlWorkBook = xlApp.Workbooks.Open(Chosen_File, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
int lastRow = -1;
foreach (Excel.Worksheet element in xlWorkBook.Worksheets)
{
lastRow = element.UsedRange.Rows.Count;
Excel.Range rango = (Excel.Range)element.get_Range("A2", "D" + lastRow);
for (int row = 1; row <= rango.Rows.Count; row++)
{
Registro reg = new Registro();
//reg.Fecha_registro = monthCalendar1.SelectionStart;
reg.Fecha_registro = dateTimePicker1.Value;
reg.Periodo_registro = reg.Fecha_registro.Value.ToString("yyyyMM");
reg.IndCod_KPIDivision = daok.ObtenerKPICodxUnicode(rango.Cells[row, 1].Value2.ToString());
if (reg.IndCod_KPIDivision == -1)
{
MessageBox.Show("El CD " + rango.Cells[row, 1].Value2.ToString() + " no esta registrado");
}
else
{
reg.Valor_registro = (decimal)decimal.Parse(rango.Cells[row, 4].Value2.ToString());
daor.insertRegistro(reg);
}
}
break;
}
MessageBox.Show("Terminado!");
xlWorkBook.Close(false, misValue, misValue);
xlApp.Quit();
releaseObject(xlWorkBook);
releaseObject(xlApp);
}
}
private void releaseObject(object obj)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
obj = null;
}
catch (Exception ex)
{
obj = null;
MessageBox.Show("Unable to release the Object " + ex.ToString());
}
finally
{
GC.Collect();
}
}
private void button2_Click(object sender, EventArgs e)
{
AltaEnlace c = new AltaEnlace();
c.Show();
}
private void button3_Click(object sender, EventArgs e)
{
BajaEnlace c = new BajaEnlace();
c.Show();
}
private void button4_Click(object sender, EventArgs e)
{
SLAComunicaciones c = new SLAComunicaciones(dateTimePicker1.Value);
c.Show();
}
private void button5_Click(object sender, EventArgs e)
{
ModificarEnlace c = new ModificarEnlace();
c.Show();
}
}
}