public void sb_startGrab() { //stations stations = new stations(); //stations.sb_readAndSaveToDB(); //agencies agencies = new agencies(); //agencies.sb_readAndSaveToDB(); //trainPassenger trainPs = new trainPassenger(); //trainPs.sb_readAndSaveToDB(this.v_cyleNumberTrainsPassenger); trainBarry trainBs = new trainBarry(); trainBs.sb_readAndSaveToDB(this.v_cyleNumberTrainsBarry, true, true); }
public void readAndSaveToDB(int F15Rec_ID, int train_no, int?trainId, int cycleNumber, trainBarryJsonModel trainBarryJson) { try { Uri uri; uri = new Uri(this.v_url); trainBillOfLadingsJsonModel[] trainBillOfLadingsListJson = null; WebRequest webRequest = WebRequest.Create(uri); webRequest.Proxy = null; webRequest.Method = "POST"; webRequest.Headers.Add("Cache-Control", "no-cache"); webRequest.Headers.Add("Cookie", "__RequestVerificationToken=Gm4hoEFS8RkxaSfJxpaeorLztRy6-rfjyKm1pRyPYQP-4dGSPAKrHWG62K3vaJOz_k7xEJBWigJHetij4ID_TmbP-27KPhaINnSun-IMnZc1;"); webRequest.ContentType = "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW"; // "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"__RequestVerificationToken\"\r\n\r\nGJKWN0U0ndGyC5fAKEdhhosJMhpjLmtfvNIieri7YR8Q37_BUn-lmEg6ucZPrWPefAcxG1-5TPMtYPZsa6fFIigJBBICLcfUlMrufrpIV6U1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--" string postData; postData = "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"__RequestVerificationToken\"\r\n\r\nGJKWN0U0ndGyC5fAKEdhhosJMhpjLmtfvNIieri7YR8Q37_BUn-lmEg6ucZPrWPefAcxG1-5TPMtYPZsa6fFIigJBBICLcfUlMrufrpIV6U1\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW" + "\r\nContent-Disposition: form-data; name=\"f15rec_id\"\r\n\r\n" + F15Rec_ID.ToString() + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW" + "\r\nContent-Disposition: form-data; name=\"train_no\"\r\n\r\n" + train_no.ToString() + "\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"; byte[] formData = Encoding.UTF8.GetBytes(postData); Stream streamRequest = webRequest.GetRequestStream(); streamRequest.Write(formData, 0, formData.Length); streamRequest.Flush(); streamRequest.Close(); WebResponse webResponse = webRequest.GetResponse(); if (webResponse != null) { string result; using (StreamReader rd = new StreamReader(webResponse.GetResponseStream())) { result = rd.ReadToEnd(); } webResponse.Close(); trainBillOfLadingsListJson = Newtonsoft.Json.JsonConvert.DeserializeObject <trainBillOfLadingsJsonModel[]>(result); if (trainBillOfLadingsListJson != null) { using (var entityLogestic = new logisticEntities()) { foreach (trainBillOfLadingsJsonModel billOfLading in trainBillOfLadingsListJson) { if (trainBarryJson != null) { //billOfLading.Barnameh_NO= it has it already //billOfLading.Bar_Type = it has it already billOfLading.Current_Station_Code = trainBarryJson.Current_Station_Code; //billOfLading.Current_Station_Name= //billOfLading.Destination_Station_Name = it has it already billOfLading.Entrance_Date = trainBarryJson.Entrance_Date; billOfLading.Entrance_Date_M = trainBarryJson.Entrance_DateTime; billOfLading.Entrance_Time = trainBarryJson.Entrance_Time; billOfLading.F15Rec_ID = trainBarryJson.F15Rec_ID; billOfLading.Source_Station_Code = trainBarryJson.Source_Station_Code; //billOfLading.Source_Station_Name = it has it already billOfLading.Tashkil_Date = trainBarryJson.Tashkil_Date; billOfLading.Tashkil_Time = trainBarryJson.Tashkil_Time; billOfLading.Train_No = trainBarryJson.Train_No; //billOfLading.Wagon_NO = it has it already } else { trainBarry train = new trainBarry(); trainBarryJsonModel[] jModel = train.fnc_findTrainBarry(train_no); if (jModel != null) { trainBarryJson = jModel.OrderByDescending(o => o.Entrance_DateTime).FirstOrDefault(); if (trainBarryJson != null) { //billOfLading.Barnameh_NO= it has it already //billOfLading.Bar_Type = it has it already billOfLading.Current_Station_Code = trainBarryJson.Current_Station_Code; //billOfLading.Current_Station_Name= //billOfLading.Destination_Station_Name = it has it already billOfLading.Entrance_Date = trainBarryJson.Entrance_Date; billOfLading.Entrance_Date_M = trainBarryJson.Entrance_DateTime; billOfLading.Entrance_Time = trainBarryJson.Entrance_Time; billOfLading.F15Rec_ID = trainBarryJson.F15Rec_ID; billOfLading.Source_Station_Code = trainBarryJson.Source_Station_Code; //billOfLading.Source_Station_Name = it has it already billOfLading.Tashkil_Date = trainBarryJson.Tashkil_Date; billOfLading.Tashkil_Time = trainBarryJson.Tashkil_Time; billOfLading.Train_No = trainBarryJson.Train_No; //billOfLading.Wagon_NO = it has it already } } } this.sb_saveToDB(billOfLading, train_no, trainId, cycleNumber, "getBariWgonList"); } } } } } catch (Exception ex) { } }