private void button3_Click(object sender, RoutedEventArgs e)
{
string sql;
sql = "";
List listPk = new List();
PiketListItem npkt;
foreach (PiketListItem pkt in dataGrid1.ItemsSource as List)
{
npkt = new PiketListItem();
npkt.ID = pkt.ID;
if (pkt.FROM != null)
npkt.FROM = pkt.FROM.Trim();
if (pkt.TO != null)
npkt.TO = pkt.TO.Trim();
if (pkt.BEARING != null)
npkt.BEARING = pkt.BEARING.Trim();
if (pkt.INC != null)
npkt.INC = pkt.INC.Trim();
if (pkt.LENGTH != null)
npkt.LENGTH = pkt.LENGTH.Trim();
if (pkt.LEFT != null)
npkt.LEFT = pkt.LEFT.Trim();
if (pkt.UP != null)
npkt.UP = pkt.UP.Trim();
if (pkt.DOWN != null)
npkt.DOWN = pkt.DOWN.Trim();
if (pkt.RIGHT != null)
npkt.RIGHT = pkt.RIGHT.Trim();
if (pkt.COMMENTS != null)
npkt.COMMENTS = pkt.COMMENTS.Trim();
npkt.IsPiket = pkt.IsPiket;
npkt.IsPiketWall = pkt.IsPiketWall;
listPk.Add(npkt);
}
blocks = new List();
BlockGet bl = new BlockGet();
string s;
foreach (PiketListItem pkt in listPk)
{
string sIsPiket = "0";
if (pkt.IsPiket) sIsPiket = "1";
string sIsPiketWall = "0";
if (pkt.IsPiketWall) sIsPiketWall = "1";
s = "insert into wp_pkt_bf(p_FROM,p_TO,p_AZIMUT,p_INC,p_LENGTH,p_LEFT,p_UP,p_DOWN,p_RIGHT,p_COMMENTS,p_IsPiket,p_IsPiketWall,sessionid) values "
+ "(\"" + pkt.FROM + "\",\"" + pkt.TO + "\",\"" + pkt.BEARING + "\",\"" + pkt.INC + "\",\"" + pkt.LENGTH +"\","
+ "\"" + pkt.LEFT + "\",\"" + pkt.UP + "\",\"" + pkt.DOWN + "\",\"" + pkt.RIGHT + "\",\"" + pkt.COMMENTS + "\","
+ "\"" + sIsPiket + "\",\"" + sIsPiketWall + "\",\""+sessionID+"\""
+ ");" + "\r\n";
if (bl.blockText.Length + s.Length < 1000)
{
bl.blockText += s;
}
else
{
sql+=bl.blockText;
bl.blockId=DateTime.Now.Hour.ToString()+DateTime.Now.Minute.ToString()
+DateTime.Now.Second.ToString()+DateTime.Now.Millisecond.ToString();
blocks.Add(bl);
bl=new BlockGet();
bl.blockText = s;
}
}
//textBoxLog.Text += "SQL:" + "\r\n" + sql + "\r\n";
// http://aks.m-ten.ru/webpiket/datagetway.php
#region Отправить методом GET
//метод не совсем подходящий, но рабочий POST пока не нашел как заставить работать
//Установил ограничение длины строки get = 1000 символа + ~100(http://aks.m-ten.ru/webpiket/datagetway.php?act=insertpkt&blockid=114440901&sessionid=0&sql=)
Uri uri;
WebClient wc;
foreach (BlockGet blk in blocks)
{
uri = new Uri(getwayURL.Text + "?act=insertpkt&blockid=" + blk.blockId + "&sessionid=" + sessionID + "&sql=" + blk.blockText, UriKind.Absolute);
textBoxLog.Text += "uri.OriginalString = " + uri.OriginalString + "\r\n";
wc = new WebClient();
textBoxLog.Text += "DownloadStringCompleted... blockid=" + blk.blockId + "\r\n";
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompletedHndlr);
textBoxLog.Text += "DownloadStringAsync... \r\n";
wc.DownloadStringAsync(uri, "POST");
}
#endregion Отправить методом GET
}