Exemplo n.º 1
0
        public void readAndSaveBarnamehToDB(long barnameh_no, int cycleNumber)
        {
            try
            {
                Uri uri;
                uri = new Uri(this.v_urlFindBillOfLading);

                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=\"barnameh_no\"\r\n\r\n" + barnameh_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 (billOfLading.Train_No.HasValue)
                                {
                                    PWS0.trainBarryBillOfLadings bill = new trainBarryBillOfLadings();
                                    bill.sb_saveToDB(billOfLading, billOfLading.Train_No.Value, null, cycleNumber, "findBariWagon");
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 2
0
        private void sb_saveToDB(trainBarryJsonModel train, int cycleNumber, bool getLocomotives, bool getBillOfLadings)
        {
            trainBarryBillOfLadings billOfLadings = new trainBarryBillOfLadings();
            trainBarryLocomotives   locos         = new trainBarryLocomotives();

            using (var entityLogestic = new logisticEntities())
            {
                bool            add            = false;
                PWS0TrainsBarry entryPWS0Train = entityLogestic.PWS0TrainsBarry.FirstOrDefault(o =>
                                                                                               o.jCurrent_Station_Code == train.Current_Station_Code &&
                                                                                               o.jDestination_Station_Code == train.Destination_Station_Code
                                                                                               //&& o.jEntrance_Date== train.Entrance_Date
                                                                                               //&& o.jEntrance_DateTime== train.Entrance_DateTime
                                                                                               //&& o.jEntrance_Time== train.Entrance_Time
                                                                                               && o.jF15Rec_ID == train.F15Rec_ID &&
                                                                                               o.jSource_Station_Code == train.Source_Station_Code &&
                                                                                               o.jTashkil_Date == train.Tashkil_Date &&
                                                                                               o.jTashkil_Time == train.Tashkil_Time &&
                                                                                               o.jTrain_No == train.Train_No

                                                                                               //&& o.jUpdate_DateTime == train.Update_DateTime
                                                                                               );
                if (entryPWS0Train == null)
                {
                    add            = true;
                    entryPWS0Train = new PWS0TrainsBarry();
                }
                try
                {
                    entryPWS0Train.CurrentStationId          = stations.fnc_getStationId(train.Current_Station_Code, null, true);
                    entryPWS0Train.DestinationStationId      = stations.fnc_getStationId(train.Destination_Station_Code, null, true);
                    entryPWS0Train.FetchTime                 = DateTime.Now;
                    entryPWS0Train.jCurrent_Station_Code     = train.Current_Station_Code;
                    entryPWS0Train.jDestination_Station_Code = train.Destination_Station_Code;
                    entryPWS0Train.jEntrance_Date            = train.Entrance_Date;
                    entryPWS0Train.jEntrance_DateTime        = train.Entrance_DateTime;
                    entryPWS0Train.jEntrance_Time            = train.Entrance_Time;
                    entryPWS0Train.jF15Rec_ID                = train.F15Rec_ID;
                    entryPWS0Train.jLocomotiveNumbers        = (train.F15Rec_ID.HasValue && getLocomotives ? locos.fnc_getTrainsBarryLocomotives(train.F15Rec_ID.Value) : null);
                    entryPWS0Train.jSource_Station_Code      = train.Source_Station_Code;
                    entryPWS0Train.jTashkil_Date             = train.Tashkil_Date;
                    entryPWS0Train.jTashkil_Time             = train.Tashkil_Time;
                    entryPWS0Train.jTrain_No                 = train.Train_No;
                    entryPWS0Train.jUpdate_DateTime          = train.Update_DateTime;
                    entryPWS0Train.SourceStationId           = stations.fnc_getStationId(train.Source_Station_Code, null, true);
                    entryPWS0Train.TashkilDateTime           = Functions.fnc_convertSolarDateAndTimeToDateTime(train.Tashkil_Date, string.IsNullOrEmpty(train.Tashkil_Time) ? null : (int?)int.Parse(train.Tashkil_Time));
                    entryPWS0Train.CycleNumber               = cycleNumber;
                    if (add)
                    {
                        entityLogestic.PWS0TrainsBarry.Add(entryPWS0Train);
                    }


                    entityLogestic.SaveChanges();
                    if (train.F15Rec_ID.HasValue && train.Train_No.HasValue && getBillOfLadings)
                    {
                        billOfLadings.readAndSaveToDB(train.F15Rec_ID.Value, train.Train_No.Value, entryPWS0Train.Id, cycleNumber, train);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }