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
142
143
144
145
146
147
148
| using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Globalization;
using Excel = Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
using System.Xml;
using System.Windows.Forms;
using System.Linq;
namespace DataLoader
{
public class OraclePush
{
private static string ConnectionString = "Data Source=WEB; User ID=DATA; Password=DATA;";
public static string[] hours = new string[] { "00-01", "01-02", "02-03", "03-04", "04-05", "05-06", "06-07", "07-08", "08-09", "09-10", "10-11", "11-12", "12-13", "13-14", "14-15", "15-16", "16-17", "17-18", "18-19", "19-20", "20-21", "21-22", "22-23", "23-00" };
private static OracleConnection connection;
private static bool Connect()
{
try
{
if ((connection == null) || (connection.State != ConnectionState.Open))
{
connection = new OracleConnection(ConnectionString);
connection.Open();
}
}
catch (Exception ex)
{
MainServices.SaveToLog(ex.Message);
return false;
}
return true;
}
public static void DisposeConnection()
{
if (connection != null)
{
connection.Dispose();
}
}
// Парсинг в базу
public static bool PushDataToOracle(string file)
{
if (!Connect()) return false;
var inputstruct = ParseStruct(file);
MainServices.SaveToLog("Подключение удалось");
try
{
/*
var cmdgetid = new OracleCommand("SELECT MAX(AFFILIATE_ID) FROM exchange_reports_sel_buy", connection);
int id = Convert.ToInt32(cmdgetid.ExecuteScalar()); // Определяем мак-ое число id
var objectFromBase = cmdgetid.ExecuteScalar();
string commandId;
if ((objectFromBase == null) || (objectFromBase == DBNull.Value))
{
commandId = "1";
}
else
{
commandId = Convert.ToString(objectFromBase);
}
MainServices.SaveToLog("Max id - " + commandId);
cmdgetid.Dispose();
*/
//---------------------------------------------------------//
// Табличка REPORT_DATA.exchange_reports_sel_buy //
//---------------------------------------------------------//
foreach (var list in inputstruct.FileData)
{
using (var cmd = new OracleCommand(@"INSERT INTO exchange_reports_sel_buy" +
"(FULLDATE, HOUR_NUM, HOUR_TYPE," +
"SW_SWITCH, GTP_ID, AFFILIATE_ID, ZONE_ID, MEASVAL_042001," +
"MEASVAL_042002, MEASVAL_042003, MEASVAL_042004, MEASVAL_042005, MEASVAL_042006, MEASVAL_042007, " +
"MEASVAL_042008, MEASVAL_042009, MEASVAL_042010, MEASVAL_042011, MEASVAL_042012, MEASVAL_042013, " +
"MEASVAL_042014, MEASVAL_042015, MEASVAL_042016, MEASVAL_042017, MEASVAL_042018, MEASVAL_042019, " +
"MEASVAL_042020, MEASVAL_042021, MEASVAL_042022, MEASVAL_042023, MEASVAL_042024, MEASVAL_042025, " +
"MEASVAL_042026, MEASVAL_042027, MEASVAL_042028, MEASVAL_042029, MEASVAL_042030, MEASVAL_042031, " +
"MEASVAL_042032, MEASVAL_042033, MEASVAL_042034, MEASVAL_042035, MEASVAL_042036, MEASVAL_042037, " +
"MEASVAL_042038, MEASVAL_042039, MEASVAL_042040," +
"MEASVAL_042014_1, MEASVAL_042015_1, MEASVAL_042016_1, MEASVAL_042017_1)" +
"VALUES(:FULLDATE, :HOUR_NUM , :HOUR_TYPE," +
":SW_SWITCH, :GTP_ID, :AFFILIATE_ID, :ZONE_ID, :MEASVAL_042001," +
":MEASVAL_042002, :MEASVAL_042003, :MEASVAL_042004, :MEASVAL_042005, :MEASVAL_042006, :MEASVAL_042007," +
":MEASVAL_042008, :MEASVAL_042009, :MEASVAL_042010, :MEASVAL_042011, :MEASVAL_042012, :MEASVAL_042013," +
":MEASVAL_042014, :MEASVAL_042015, :MEASVAL_042016, :MEASVAL_042017, :MEASVAL_042018, :MEASVAL_042019," +
":MEASVAL_042020, :MEASVAL_042021, :MEASVAL_042022, :MEASVAL_042023, :MEASVAL_042024, :MEASVAL_042025," +
":MEASVAL_042026, :MEASVAL_042027, :MEASVAL_042028, :MEASVAL_042029, :MEASVAL_042030, :MEASVAL_042031," +
":MEASVAL_042032, :MEASVAL_042033, :MEASVAL_042034, :MEASVAL_042035, :MEASVAL_042036, :MEASVAL_042037," +
":MEASVAL_042038, :MEASVAL_042039, :MEASVAL_042040," +
":MEASVAL_042014_1, :MEASVAL_042015_1, :MEASVAL_042016_1, :MEASVAL_042017_1",connection))
{
var p1 = new OracleParameter(":FULLDATE", Convert.ToDateTime(inputstruct.for_date, CultureInfo.InvariantCulture));
// for (int i = 0; i < 24; i++)
// {
// var p2 = new OracleParameter(":HOUR_NUM", Convert.ToString(hours, CultureInfo.InvariantCulture)); // здесь ошибка
// }
var p3 = new OracleParameter(":HOUR_TYPE", DBNull.Value); // тип
var p4 = new OracleParameter(":SW_SWITCH", DBNull.Value); //
var p5 = new OracleParameter(":GTP_ID", Convert.ToDecimal(inputstruct.GTP, CultureInfo.InvariantCulture));
var p6 = new OracleParameter(":AFFILIATE_ID", DBNull.Value); // филиал
var p7 = new OracleParameter(":ZONE_ID", DBNull.Value);
var p8 = new OracleParameter(":MEASVAL_042001", Convert.ToDecimal(list.PminTechLine, CultureInfo.InvariantCulture));
var p9 = new OracleParameter(":MEASVAL_042002", Convert.ToDecimal(list.PmaxTechLine, CultureInfo.InvariantCulture));
var p10 = new OracleParameter(":MEASVAL_042003", Convert.ToDecimal(list.VdowsLimitLine, CultureInfo.InvariantCulture));
var p11 = new OracleParameter(":MEASVAL_042004", Convert.ToDecimal(list.VupLimitLine, CultureInfo.InvariantCulture));
var p12 = new OracleParameter(":MEASVAL_042005", Convert.ToDecimal(list.RDValueLine, CultureInfo.InvariantCulture));
var p13 = new OracleParameter(":MEASVAL_042006", Convert.ToDecimal(list.TGValueLine, CultureInfo.InvariantCulture));
var p14 = new OracleParameter(":MEASVAL_042007", Convert.ToDecimal(list.PriceAvgLine, CultureInfo.InvariantCulture));
var p15 = new OracleParameter(":MEASVAL_042008", Convert.ToDecimal(list.RSVSalePriceLine, CultureInfo.InvariantCulture));
var p16 = new OracleParameter(":MEASVAL_042009", Convert.ToDecimal(list.RSVSaleValue, CultureInfo.InvariantCulture));
var p17 = new OracleParameter(":MEASVAL_042010", Convert.ToDecimal(list.RDPurchValue, CultureInfo.InvariantCulture));
var p18 = new OracleParameter(":MEASVAL_042011", Convert.ToDecimal(list.RDPurchPrice, CultureInfo.InvariantCulture));
var p19 = new OracleParameter(":MEASVAL_042012", Convert.ToDecimal(list.SDDPurchValue, CultureInfo.InvariantCulture));
var p20 = new OracleParameter(":MEASVAL_042013", Convert.ToDecimal(list.SDDPurchPrice, CultureInfo.InvariantCulture));
var p22 = new OracleParameter(":MEASVAL_042014", Convert.ToDecimal(list.SDDSaleValue, CultureInfo.InvariantCulture));
var p23 = new OracleParameter(":MEASVAL_042015", Convert.ToDecimal(list.SDDSalePrice, CultureInfo.InvariantCulture));
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
cmd.ExecuteNonQuery(); // commit
cmd.Dispose();
} |