zhanghongzhi1234_VideoAnalysis/VideoManager/Import.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace VideoManager
{
    /// <summary>
    /// Interaction logic for Import.xaml
    /// </summary>
    public partial class Import : Window
    {
        double[] arrayLightening2014 ={68860,61778,69956,69736,71716,68862,70674,69202,68652,69052,68826.2,72955.8,
95588,87972,101116,100030,103022,98248,100864,98032,95944,99688,97868.4,103740.4,
49916,45618,51262,50282,51504,50206,53256,52120,51630,50402,50643.6,53682.2,
127338,110836,127918,115528,124914,122710,127330,125060,124938,124662,122952.6,130329.8,
104784,91168,105294,104186,109114,103592,105424,106528,104856,104550,103882.8,110115.8,
62764,57332,63816,65188,68224,63954,66854,63718,65268,66218,64124.2,67971.6,
71162,65418,71970,72224,75154,72304,73810,73722,71540,72224,71922.6,76238,
55902,51716,57040,55698,55862,52372,51520,51548,51458,53816,53679.6,56900.4,
54734,49580,57100,54582,58672,56570,56300,56598,56644,55172,55642.2,58980.8,
64070,56976,66222,65176,68226,65470,69672,71748,69518,65176,66342,70322.6,
68182,63702,70044,68252,70274,67368,72152,75852,70554,68706,69597.6,73773.4,
49748,43228,48110,44346,49072,47570,47458,47484,47306,47500,47147,49975.8,
43688,37854,43010,43044,45500,44318,45074,41946,42472,43158,42989.6,45569,
64674,73088,76552.6,110341.4,95718,88906,99024,91736,85884,91736,91141.6,96610
                           };
        double[] arrayECS2014 ={275440,247112,279824,278944,286864,275448,282696,276808,274608,276208,275304.8,291823.2,
382352,351888,404464,400120,412088,392992,403456,392128,383776,398752,391473.6,414961.6,
199664,182472,205048,201128,206016,200824,213024,208480,206520,201608,202574.4,214728.8,
509352,443344,511672,462112,499656,490840,509320,500240,499752,498648,491810.4,521319.2,
419136,364672,421176,416744,436456,414368,421696,426112,419424,418200,415531.2,440463.2,
251056,229328,255264,260752,272896,255816,267416,254872,261072,264872,256496.8,271886.4,
284648,261672,287880,288896,300616,289216,295240,294888,286160,288896,287690.4,304952,
223608,206864,228160,222792,223448,209488,206080,206192,205832,215264,214718.4,227601.6,
218936,198320,228400,218328,234688,226280,225200,226392,226576,220688,222568.8,235923.2,
256280,227904,264888,260704,272904,261880,278688,286992,278072,260704,265368,281290.4,
272728,254808,280176,273008,281096,269472,288608,303408,282216,274824,278390.4,295093.6,
198992,172912,192440,177384,196288,190280,189832,189936,189224,190000,188588,199903.2,
174752,151416,172040,172176,182000,177272,180296,167784,169888,172632,171958.4,182276,
258696,292352,306210.4,441365.6,382872,355624,396096,366944,343536,366944,364566.4,386440
                           };
        double[] arrayRolling2014 ={276290,243750,280620,279310,297360,298370,311330,297140,294330,294330,286500,303690,
459060,402220,461890,458450,488550,487530,513630,508650,509210,487530,476577,505172,
337790,308725,374025,366080,388250,385510,409980,410250,397620,385510,375359,397881,
311600,284210,328060,326170,424430,424430,285540,369070,360110,328060,345958,366715,
309720,284010,331330,326250,320530,362830,366720,362080,348270,331330,334638,354716,
257290,246260,290920,292390,310560,312600,335580,337150,323850,310560,300733,318777,
137530,126830,151060,145950,142870,143020,150700,145450,139760,143020,142574,151128,
189500,175130,213190,205030,207680,209110,222630,211620,211870,209110,205084,217389,
250550,232190,279250,270840,277610,279230,302560,292300,290020,279230,274950,291447,
231660,214150,339205,332470,351720,352280,375570,376900,366010,351720,326663,346263,
250800,231600,270500,267500,279500,280700,297800,300500,293800,279500,274744,291229,
202010,189460,194989.9,223830.3,236795.7,238467.8,245732.5,235532.6,236176,235532.6,222555,235908,
197960,181060,202570,199980,179470,179470,217720,206910,208720,199980,197096,208922,
83950,67190,83080,81490,85490,91800,88330,85160,84610,84610,83456,88463
                           };
        double[] arrayLightening2015 ={67981,61099,69389,70159,71284,68319,69891,68338,67978,68178,68394.2,72302.8,
95267,87630,101437,99597,102347,98014,100076,97934,95767,99254,97415.4,103953.4,
49380,45296,51033,49499,51547,49313,52824,51898,51506,50078,49965.6,53289.2,
127549,110713,127773,115207,124567,122257,127353,124386,124392,124230,122541.6,129997.8,
104553,91379,104751,104074,108800,102950,105504,106294,104645,104207,103329.8,109574.8,
62443,57209,63033,65246,67789,63743,66731,62930,64505,65765,63363.2,67318.6,
70820,65273,71106,71550,74713,72382,73665,73624,71329,72079,71575.6,75596,
55991,51395,56366,54824,55299,51811,51199,51371,51335,53495,52805.6,56980.4,
54301,49233,56226,54150,58708,56140,55953,56164,55856,54825,55210.2,58746.8,
63395,56523,65790,64523,67445,65259,69219,71295,68755,64723,66378,70111.6,
67948,63725,69391,67928,69842,67025,71699,76065,70101,68783,69167.6,73644.4,
49437,42554,47246,44248,48850,46896,47224,46696,47072,46607,46694,50018.8,
43899,37731,42865,42723,45153,43865,45097,41604,41819,43035,42201.6,44806,
63891,72300,76120.6,110364.4,95929,88783,98879,91415,85537,91283,91164.6,95936
                           };
        double[] arrayECS2015 ={274657,246566,279613,278181,286653,274795,281908,276685,274155,275974,274651.8,291502.2,
381564,351546,404785,399687,411413,392211,402668,391345,383599,398318,391020.6,414087.6,
199232,182150,204819,200345,206059,200613,212592,208538,206396,201284,201896.4,214808.8,
509375,442891,511527,461791,499309,490387,509343,499805,499206,498216,491399.4,520987.2,
419347,364695,420633,416632,436142,413580,421776,425878,419213,417857,414978.2,439922.2,
250735,228986,254481,260810,272461,255582,267293,254084,260309,264419,255735.8,271233.4,
284306,261019,287016,288222,300175,289294,295095,294790,285949,288751,287343.4,304310,
223697,206741,227296,222694,223226,209055,205846,206015,205709,214943,213844.4,227681.6,
218503,197532,227526,217896,234724,225933,224853,225958,225788,220341,222136.8,235689.2,
255605,227451,264456,260051,272123,261006,278235,286539,277309,260251,265404,281079.4,
272494,254831,279523,272684,280664,269040,288155,303621,281763,274901,277960.4,294964.6,
198681,172238,192008,176731,195507,190069,189379,189148,188990,189107,188135,199946.2,
174963,151293,171895,171855,181653,176819,180319,167442,169235,172509,171170.4,181513,
257913,291564,305778.4,441388.6,383083,355501,395951,366623,343189,366491,364589.4,385766
                           };
        double[] arrayRolling2015 ={276379,243627,279756,279212,297138,297937,311096,296963,294207,294009,285626,302902,
458277,401356,461543,458103,488116,486742,513283,508218,508863,486978,475956,504384,
337848,308627,373237,365957,387467,384857,409633,410126,397186,385057,374485,397704,
311165,283988,327736,325738,424087,423977,285395,368749,359676,327607,346035,366592,
309486,283577,331119,325462,320406,362653,366596,361956,347923,331543,333985,353935,
256502,246026,290137,292043,310213,311812,335457,336367,323069,310349,300280,318566,
137432,126653,151083,145608,142217,142897,149912,144997,139328,142346,142451,150675,
189323,175007,212961,204247,207723,208899,222198,211678,211746,208786,204406,217047,
250116,231409,278903,270493,277176,278442,302213,291868,289896,278608,274329,290583,
231207,213939,338417,332123,351288,352156,375446,376468,365663,351596,326229,345389,
251013,231147,270266,266712,279402,280523,297366,300047,294013,278712,274402,290797,
201222,188672,194812.9,223707.3,236014.7,238256.8,245279.5,235190.6,235393,235185.6,222208,235561,
197618,180407,202027,199197,178606,178606,216846,206478,208067,199548,196425,208798,
83639,66516,82648,80837,84709,91589,87877,84372,84376,83717,83003,88042
                           };
        public Import()
        {
            InitializeComponent();
        }

        private void btnImport_Click(object sender, RoutedEventArgs e)
        {
            //save power to db
            string sqlstr = "insert into power_archive(stationkey,subsystemkey,year_index,month_index,value) values";
            //sqlstr += ParseData(arrayLightening2014, 1, 2014);
            sqlstr += ParseData(arrayECS2014, 2, 2014);
            sqlstr += ParseData(arrayRolling2014, 3, 2014);
            sqlstr += ParseData(arrayLightening2015, 1, 2015);
            sqlstr += ParseData(arrayECS2015, 2, 2015);
            sqlstr += ParseData(arrayRolling2015, 3, 2015);
            sqlstr = sqlstr.Trim(',');
            //int nRet = Core.DAIHelper.Instance.ExecuteNonQuery(sqlstr);
            MessageBox.Show("Import Finished.");
        }

        private string ParseData(double[] arr, int subsystemkey, int year_index)
        {
            string sqlstr = "";
            int stationkey = 1;
            int month_index = 1;
            foreach (double num in arr)
            {
                sqlstr += "(" + stationkey + "," + subsystemkey + "," + year_index + "," + month_index + "," + (int)num + "),";
                month_index++;
                if (month_index > 12)
                {
                    month_index = 1;
                    stationkey++;
                }
            }
            
            return sqlstr;
        }
    }
}
