public void sb_readAndSaveStatesToDB(bool saveCitiesForEachState)
        {
            try
            {
                Uri uri = new Uri(this.v_urlState);
                StateCityJsonModel[] statesJson = null;
                WebRequest           webRequest = WebRequest.Create(uri);
                webRequest.Proxy  = null;
                webRequest.Method = "GET";
                WebResponse webResponse = webRequest.GetResponse();
                if (webResponse != null)
                {
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        string result = rd.ReadToEnd();
                        statesJson = Newtonsoft.Json.JsonConvert.DeserializeObject <StateCityJsonModel[]>(result);
                    }
                    webResponse.Close();

                    if (statesJson != null)
                    {
                        using (var entityLogestic = new logisticEntities())
                        {
                            foreach (StateCityJsonModel state in statesJson)
                            {
                                this.sb_saveStateToDB(state, saveCitiesForEachState);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        public void sb_readAndSaveToDB()
        {
            try
            {
                Uri uri = new Uri(this.v_url);
                stationsJsonModel stationsJson = null;
                WebRequest        webRequest   = WebRequest.Create(uri);
                webRequest.Proxy  = null;
                webRequest.Method = "GET";
                WebResponse webResponse = webRequest.GetResponse();
                if (webResponse != null)
                {
                    using (StreamReader rd = new StreamReader(webResponse.GetResponseStream()))
                    {
                        string result = rd.ReadToEnd();
                        stationsJson = Newtonsoft.Json.JsonConvert.DeserializeObject <stationsJsonModel>(result);
                    }
                    webResponse.Close();

                    if (stationsJson != null && stationsJson.features != null)
                    {
                        using (var entityLogestic = new logisticEntities())
                        {
                            foreach (station_featureJsonModel feature in stationsJson.features)
                            {
                                feature.sb_saveToDB();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #3
0
 public static int?fnc_getBillOfLadingId(long?billOfLadingNo /*,bool add*/, bool notifNotExist)
 {
     if (!billOfLadingNo.HasValue)
     {
         return(null);
     }
     using (var entityLogestic = new logisticEntities())
     {
         var entryBillOfLading = entityLogestic.PWS0BillOfLadings.FirstOrDefault(o => o.jBarnameh_NO == billOfLadingNo.ToString());
         if (entryBillOfLading == null)
         {
             string strNotif = "";
             if (notifNotExist)
             {
                 strNotif = "BillOfLading = " + billOfLadingNo + " does not exist in BillOfLadings table.";// + (add ? "? It will be created" : "");
             }
             //if (add)
             //{
             //    entryWagon = new Wagon();
             //    entryWagon.wagonNo = wagonNo;
             //    entityLogestic.Wagons.Add(entryWagon);
             //    entityLogestic.SaveChanges();
             //    return entryWagon.Id;
             //}
             //else return null;
             return(null);
         }
         else
         {
             return(entryBillOfLading.Id);
         }
     }
 }
Exemple #4
0
 public static int?fnc_getWagonIdCheckWithControlNo(long?wagonNo /*,bool add*/, bool notifNotExist)
 {
     if (!wagonNo.HasValue)
     {
         return(null);
     }
     using (var entityLogestic = new logisticEntities())
     {
         var entryWagon = entityLogestic.Wagons.FirstOrDefault(o => o.wagonControlNo == wagonNo.ToString());
         if (entryWagon == null)
         {
             string strNotif = "";
             if (notifNotExist)
             {
                 strNotif = "WagonNo = " + wagonNo + " does not exist in Wagons table.";// + (add ? "? It will be created" : "");
             }
             //if (add)
             //{
             //    entryWagon = new Wagon();
             //    entryWagon.wagonNo = wagonNo;
             //    entityLogestic.Wagons.Add(entryWagon);
             //    entityLogestic.SaveChanges();
             //    return entryWagon.Id;
             //}
             //else return null;
             return(null);
         }
         else
         {
             return(entryWagon.Id);
         }
     }
 }
Exemple #5
0
        public void sb_saveToDB(trainBillOfLadingsJsonModel billOfLading, int train_no, int?trainId, int cycleNumber, string fetchUrl)
        {
            bool add = false;

            using (var entityLogestic = new logisticEntities())
            {
                PWS0BillOfLadings entryPWS0BillOfLading = entityLogestic.PWS0BillOfLadings.FirstOrDefault(o =>
                                                                                                          o.jBarnameh_NO == billOfLading.Barnameh_NO &&
                                                                                                          o.jBar_Type == billOfLading.Bar_Type
                                                                                                          //&& o.jDestination_Station_Name == trainWagon.Destination_Station_Name
                                                                                                          //&& o.jSource_Station_Name== trainWagon.Source_Station_Name
                                                                                                          && o.jWagon_NO == billOfLading.Wagon_NO);
                if (entryPWS0BillOfLading == null)
                {
                    add = true;
                    entryPWS0BillOfLading = new PWS0BillOfLadings();
                }
                try
                {
                    entryPWS0BillOfLading.CurrentStationId     = stations.fnc_getStationId(billOfLading.Current_Station_Code, billOfLading.Current_Station_Name, true);;
                    entryPWS0BillOfLading.CycleNumber          = cycleNumber;
                    entryPWS0BillOfLading.DestinationStationId = stations.fnc_getStationId(null, billOfLading.Destination_Station_Name, true);
                    entryPWS0BillOfLading.FetchTime            = DateTime.Now;
                    entryPWS0BillOfLading.FetchUrl             = fetchUrl;
                    entryPWS0BillOfLading.goodsId                   = goods.fnc_getGoodsId(billOfLading.Bar_Type, false, true);
                    entryPWS0BillOfLading.jBarnameh_NO              = billOfLading.Barnameh_NO;
                    entryPWS0BillOfLading.jBar_Type                 = billOfLading.Bar_Type;
                    entryPWS0BillOfLading.jCurrent_Station_Code     = billOfLading.Current_Station_Code;
                    entryPWS0BillOfLading.jCurrent_Station_Name     = billOfLading.Current_Station_Name;
                    entryPWS0BillOfLading.jDestination_Station_Name = billOfLading.Destination_Station_Name;
                    entryPWS0BillOfLading.jEntrance_Date            = billOfLading.Entrance_Date;
                    entryPWS0BillOfLading.jEntrance_Date_M          = billOfLading.Entrance_Date_M;
                    entryPWS0BillOfLading.jEntrance_Time            = billOfLading.Entrance_Time;
                    entryPWS0BillOfLading.jF15Rec_ID                = billOfLading.F15Rec_ID;
                    entryPWS0BillOfLading.jSource_Station_Code      = billOfLading.Source_Station_Code;
                    entryPWS0BillOfLading.jSource_Station_Name      = billOfLading.Source_Station_Name;
                    entryPWS0BillOfLading.jTashkil_Date             = billOfLading.Tashkil_Date;
                    entryPWS0BillOfLading.jTashkil_Time             = billOfLading.Tashkil_Time;
                    entryPWS0BillOfLading.jTrain_No                 = billOfLading.Train_No;
                    entryPWS0BillOfLading.jWagon_NO                 = billOfLading.Wagon_NO;

                    entryPWS0BillOfLading.SourceStationId = stations.fnc_getStationId(billOfLading.Source_Station_Code, billOfLading.Source_Station_Name, true);
                    entryPWS0BillOfLading.TashkilDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(entryPWS0BillOfLading.jTashkil_Date, string.IsNullOrEmpty(billOfLading.Tashkil_Time) ? null : (int?)int.Parse(billOfLading.Tashkil_Time));
                    entryPWS0BillOfLading.TrainId         = (trainId.HasValue ? trainId.Value : (billOfLading.Entrance_Date_M.HasValue ? (int?)trainBarry.fnc_getTrainIdFromDB(train_no, billOfLading.Entrance_Date_M.Value) : null));
                    entryPWS0BillOfLading.WagonId         = trainBarryWagons.fnc_getWagonIdCheckWithControlNo(billOfLading.Wagon_NO, true);



                    if (add)
                    {
                        entityLogestic.PWS0BillOfLadings.Add(entryPWS0BillOfLading);
                    }

                    entityLogestic.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }
        public static int?fnc_getStationId(int?stationCode, string stationName, bool notifNotExist)
        {
            if (!stationCode.HasValue && string.IsNullOrEmpty(stationName))
            {
                return(null);
            }

            using (var entityLogestic = new logisticEntities())
            {
                PWS0Stations station;
                if (stationCode.HasValue)
                {
                    station = entityLogestic.PWS0Stations.FirstOrDefault(o => o.stcode == stationCode);
                }
                else
                {
                    station = entityLogestic.PWS0Stations.FirstOrDefault(o => o.name == stationName);
                    if (station == null)
                    {
                        station = entityLogestic.PWS0Stations.FirstOrDefault(o => o.name2 == stationName);
                        if (station == null)
                        {
                            station = entityLogestic.PWS0Stations.FirstOrDefault(o => o.alternateNames.Contains(stationName + ";"));
                        }
                    }
                }

                if (station == null)
                {
                    string strNotif = "";
                    if (notifNotExist)
                    {
                        if (stationCode.HasValue)
                        {
                            strNotif = "stationCode = " + stationCode + " does not exist in PWS0Stations table.";//+ (add ? "? It will be created" : "");
                        }
                        else
                        {
                            strNotif = "stationName1  or stationName2 = " + stationName + " does not exist in PWS0Stations table."; //+ (add ? "? It will be created" : "");
                        }
                    }
                    //if (add)
                    //{
                    //    entryStation = new PWS0Goods();
                    //    entryStation.name = stationName;
                    //    entityLogestic.PWS0Stations.Add(entryStation);
                    //    entityLogestic.SaveChanges();
                    //    return entryStation.Id;
                    //}
                    //else return null;

                    return(null);
                }
                else
                {
                    return(station.Id);
                }
            }
        }
Exemple #7
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)
            {
            }
        }
        public void sb_readAndSaveCitiesToDB(int stateId, int?parentId)
        {
            try
            {
                Uri uri;
                uri = new Uri(this.v_urlCity);

                StateCityJsonModel[] cities     = 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=\"ostanid\"\r\n\r\n" + stateId.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();
                    cities = Newtonsoft.Json.JsonConvert.DeserializeObject <StateCityJsonModel[]>(result);

                    if (cities != null)
                    {
                        using (var entityLogestic = new logisticEntities())
                        {
                            foreach (StateCityJsonModel city in cities)
                            {
                                this.sb_saveCityToDB(city, stateId, parentId);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #9
0
 public static int?fnc_getTrainIdFromDB(int train_no, DateTime?enteranceDateTime)
 {
     using (var entityLogestic = new logisticEntities())
     {
         var entryTrainBarry = entityLogestic.PWS0TrainsBarry.FirstOrDefault(o => o.jTrain_No == train_no &&
                                                                             o.jEntrance_DateTime == enteranceDateTime);
         if (entryTrainBarry == null)
         {
             return(null);
         }
         return(entryTrainBarry.Id);
     }
 }
Exemple #10
0
        public Grabber()
        {
            int?temp;

            using (var entityLogestic = new logisticEntities())
            {
                DateTime dateTime = DateTime.Now.Date;
                temp = entityLogestic.PWS0BillOfLadings.Where(o => DbFunctions.TruncateTime(o.FetchTime) == dateTime).Max(o => o.CycleNumber);
                this.v_cyleNumberBillOfLadings = (temp.HasValue ? temp.Value : 0) + 1;

                temp = entityLogestic.PWS0TrainsBarry.Where(o => DbFunctions.TruncateTime(o.FetchTime) == dateTime).Max(o => o.CycleNumber);
                this.v_cyleNumberTrainsBarry = (temp.HasValue ? temp.Value : 0) + 1;

                temp = entityLogestic.PWS0TrainsPassengers.Where(o => DbFunctions.TruncateTime(o.FetchTime) == dateTime).Max(o => o.CycleNumber);
                this.v_cyleNumberTrainsPassenger = (temp.HasValue ? temp.Value : 0) + 1;
            }
        }
Exemple #11
0
 public static int?fnc_getGoodsId(string goodsName, bool add, bool notifNotExist)
 {
     if (string.IsNullOrEmpty(goodsName))
     {
         return(null);
     }
     if (goodsName == "واگن بدون بار")
     {
         return(-1);
     }
     using (var entityLogestic = new logisticEntities())
     {
         var entryGoods = entityLogestic.PWS0Goods.FirstOrDefault(o => o.goodsName == goodsName);
         if (entryGoods == null)
         {
             string strNotif = "";
             if (notifNotExist)
             {
                 strNotif = "goodsName = " + goodsName + " does not exist in PWS0Goods table." + (add ? "? It will be created" : "");
             }
             if (add)
             {
                 entryGoods           = new PWS0Goods();
                 entryGoods.goodsName = goodsName;
                 entityLogestic.PWS0Goods.Add(entryGoods);
                 entityLogestic.SaveChanges();
                 return(entryGoods.Id);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(entryGoods.Id);
         }
     }
 }
Exemple #12
0
 public static int?fnc_getWagonTypeName(string wagonTypeName, bool add, bool notifNotExist)
 {
     if (string.IsNullOrEmpty(wagonTypeName))
     {
         return(null);
     }
     using (var entityLogestic = new logisticEntities())
     {
         var entryWagonType = entityLogestic.WagonsTypes.FirstOrDefault(o => o.typeName == wagonTypeName.ToString() ||
                                                                        o.alternateNames.Contains(wagonTypeName + ";"));
         if (entryWagonType == null)
         {
             string strNotif = "";
             if (notifNotExist)
             {
                 strNotif = "WagonTypeName = " + wagonTypeName + " does not exist in WagonsType table." + (add ? "? It will be created" : "");
             }
             if (add)
             {
                 entryWagonType          = new WagonsType();
                 entryWagonType.typeName = wagonTypeName;
                 entityLogestic.WagonsTypes.Add(entryWagonType);
                 entityLogestic.SaveChanges();
                 return(entryWagonType.Id);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(entryWagonType.Id);
         }
     }
 }
Exemple #13
0
 public static int?fnc_getAreaId(string areaName, bool add, bool notifNotExist)
 {
     if (string.IsNullOrEmpty(areaName))
     {
         return(null);
     }
     //if (areaName == "واگن بدون بار") return -1;
     using (var entityLogestic = new logisticEntities())
     {
         var entryArea = entityLogestic.Areas.FirstOrDefault(o => o.areaName == areaName);
         if (entryArea == null)
         {
             string strNotif = "";
             if (notifNotExist)
             {
                 strNotif = "areaName = " + areaName + " does not exist in Areas table." + (add ? "? It will be created" : "");
             }
             if (add)
             {
                 entryArea          = new Area();
                 entryArea.areaName = areaName;
                 entityLogestic.Areas.Add(entryArea);
                 entityLogestic.SaveChanges();
                 return(entryArea.Id);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(entryArea.Id);
         }
     }
 }
        private void sb_saveStateToDB(StateCityJsonModel stateJson, bool saveCitiesForEachState)
        {
            using (var entityLogestic = new logisticEntities())
            {
                bool            add            = false;
                PWS0StateCities entryPWS0State = entityLogestic.PWS0StateCities.FirstOrDefault(o => o.StateId == stateJson.StateID &&
                                                                                               o.isState.HasValue && o.isState.Value);

                if (entryPWS0State == null)
                {
                    add            = true;
                    entryPWS0State = new PWS0StateCities();
                }
                entryPWS0State.CityId              = null;
                entryPWS0State.CityName            = null;
                entryPWS0State.isState             = true;
                entryPWS0State.ParentIdInDB        = null;
                entryPWS0State.ParentStateIdInJson = null;
                entryPWS0State.StateId             = stateJson.StateID;
                entryPWS0State.StateName           = stateJson.StateName;

                if (add)
                {
                    entityLogestic.PWS0StateCities.Add(entryPWS0State);
                }

                entityLogestic.SaveChanges();
                //to get id of stationid
                int parentIdInDB = entryPWS0State.Id;

                if (saveCitiesForEachState && stateJson.StateID.HasValue)
                {
                    this.sb_readAndSaveCitiesToDB(stateJson.StateID.Value, parentIdInDB);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="cityJson"></param>
        /// <param name="parentIdInDB">refer to Id which is saved automatically in db</param>
        /// <param name="parentStateIdInJson">refer to stateId which comes from JSON</param>
        private void sb_saveCityToDB(StateCityJsonModel cityJson, int parentStateIdInJson, int?parentIdInDB)
        {
            using (var entityLogestic = new logisticEntities())
            {
                if (!parentIdInDB.HasValue)
                {
                    var entryState = entityLogestic.PWS0StateCities.FirstOrDefault(o => o.ParentStateIdInJson == parentStateIdInJson && (o.isState.HasValue && o.isState.Value));
                    if (entryState != null)
                    {
                        parentIdInDB = entryState.Id;
                    }
                }
                bool            add           = false;
                PWS0StateCities entryPWS0City = entityLogestic.PWS0StateCities.FirstOrDefault(o => o.CityId == cityJson.CityID &&
                                                                                              (!o.isState.HasValue || !o.isState.Value));

                if (entryPWS0City == null)
                {
                    add           = true;
                    entryPWS0City = new PWS0StateCities();
                }
                entryPWS0City.CityId              = cityJson.CityID;
                entryPWS0City.CityName            = cityJson.CityName;
                entryPWS0City.isState             = false;
                entryPWS0City.ParentIdInDB        = parentIdInDB;
                entryPWS0City.ParentStateIdInJson = parentStateIdInJson;
                entryPWS0City.StateId             = null;
                entryPWS0City.StateName           = null;
                if (add)
                {
                    entityLogestic.PWS0StateCities.Add(entryPWS0City);
                }

                entityLogestic.SaveChanges();
            }
        }
Exemple #16
0
        public bool readAndSaveWagonToDB(long wagonNo, string solarDateFrom, string solarDateTo, int cycleNumber)
        {
            SharedVariables.logs.Info("Start Fetch " + wagonNo + " from " + solarDateFrom + " to " + solarDateTo);

            using (var entityLogistics = new logisticEntities())
            {
                customersHistoryFetchLog entryCustomersHistoryFetchLog = new customersHistoryFetchLog();
                entryCustomersHistoryFetchLog.endDate        = solarDateTo;
                entryCustomersHistoryFetchLog.fetchTimeEnd   = null;
                entryCustomersHistoryFetchLog.fetchTimeStart = DateTime.Now;
                entryCustomersHistoryFetchLog.startDate      = solarDateFrom;
                entryCustomersHistoryFetchLog.state          = 0;
                entryCustomersHistoryFetchLog.wagonNo        = wagonNo.ToString();
                entityLogistics.customersHistoryFetchLogs.Add(entryCustomersHistoryFetchLog);
                entityLogistics.SaveChanges();

                wagonInfoTrackingDetail wagonDetail = new wagonInfoTrackingDetail();
                try
                {
                    DateTime dateFrom, dateTo;
                    dateFrom = DateTime.MinValue;
                    dateTo   = DateTime.MaxValue;
                    try
                    {
                        dateFrom = Functions.solarToMiladi(solarDateFrom);
                    }
                    catch (Exception ex)
                    {
                        SharedVariables.logs.Error("wagonInfoSeirHistory.readAndSaveWagonToDB.solarToMiladi,solarDateFrom", ex);
                        entryCustomersHistoryFetchLog.state        = -1;
                        entryCustomersHistoryFetchLog.fetchTimeEnd = DateTime.Now;
                        entityLogistics.SaveChanges();
                        return(false);
                    }
                    if (solarDateFrom.Length == 10)
                    {
                        solarDateFrom = solarDateFrom.Remove(0, 2);
                    }
                    solarDateFrom = solarDateFrom.Replace("/", "");

                    try
                    {
                        dateTo = Functions.solarToMiladi(solarDateTo);
                    }
                    catch (Exception ex)
                    {
                        SharedVariables.logs.Error("wagonInfoSeirHistory.readAndSaveWagonToDB.solarToMiladi,solarDateTo", ex);
                        entryCustomersHistoryFetchLog.state        = -1;
                        entryCustomersHistoryFetchLog.fetchTimeEnd = DateTime.Now;
                        entityLogistics.SaveChanges();
                        return(false);
                    }
                    if (solarDateTo.Length == 10)
                    {
                        solarDateTo = solarDateTo.Remove(0, 2);
                    }
                    solarDateTo = solarDateTo.Replace("/", "");

                    if (dateFrom > dateTo)
                    {
                        SharedVariables.logs.Error("wagonInfoSeirHistory.readAndSaveWagonToDB.solarToMiladi, SolarDateFrom should be lower than SolarDateTo");
                        entryCustomersHistoryFetchLog.state        = -1;
                        entryCustomersHistoryFetchLog.fetchTimeEnd = DateTime.Now;
                        entityLogistics.SaveChanges();
                        return(false);
                    }
                    login lg = new login();
start:
                    if (login.v_cookieCollection == null)
                    {
                        if (!lg.fnc_login())
                        {
                            //cannot login
                            entryCustomersHistoryFetchLog.state        = -1;
                            entryCustomersHistoryFetchLog.fetchTimeEnd = DateTime.Now;
                            entityLogistics.SaveChanges();
                            return(false);
                        }
                    }
                    Uri uri;
                    uri = new Uri(this.v_url);
                    string postData;
                    int    pageNumber = 1;
                    wagonInfoSeirHistoryDataTable dt = new wagonInfoSeirHistoryDataTable();
                    do
                    {
                        HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

                        //webRequest.Headers.Add("Accept-Language", "en-US,en;q=0.8");
                        webRequest.Proxy  = null;
                        webRequest.Method = "POST";

                        //webRequest.Headers.Add("Cache-Control", "no-cache");
                        webRequest.ContentType = "application/x-www-form-urlencoded";

                        webRequest.CookieContainer = new CookieContainer();
                        foreach (Cookie cookie in login.v_cookieCollection)
                        {
                            webRequest.CookieContainer.Add(cookie);
                        }


                        postData = "WagonNo=" + wagonNo.ToString()
                                   + "&From_Date=" + solarDateFrom.ToString()
                                   + "&To_Date=" + solarDateTo.ToLower()
                                   + "&Page=" + pageNumber.ToString();
                        SharedVariables.logs.Info(postData);
                        byte[] formData = Encoding.ASCII.GetBytes(postData);

                        webRequest.ContentLength = formData.Length;
                        Stream streamRequest = webRequest.GetRequestStream();
                        streamRequest.Write(formData, 0, formData.Length);
                        streamRequest.Flush();
                        streamRequest.Close();

                        HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
                        if (webResponse != null)
                        {
                            if (webResponse.ResponseUri == null || string.IsNullOrEmpty(webResponse.ResponseUri.AbsoluteUri))
                            {
                                webResponse.Close();
                                entryCustomersHistoryFetchLog.state        = -1;
                                entryCustomersHistoryFetchLog.fetchTimeEnd = DateTime.Now;
                                entityLogistics.SaveChanges();
                                return(false);
                            }
                            if (login.fnc_isLoginPage(webResponse, this.v_url))
                            {
                                //we haven't loginned yet
                                if (lg.fnc_login())
                                {
                                    goto start;
                                }
                                else
                                {
                                    //cannot login inform or log !!!!!
                                    webResponse.Close();
                                    entryCustomersHistoryFetchLog.state        = -1;
                                    entryCustomersHistoryFetchLog.fetchTimeEnd = DateTime.Now;
                                    entityLogistics.SaveChanges();
                                    return(false);
                                }
                            }
                            string result;
                            using (StreamReader rd = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("windows-1256")))
                            {
                                result = rd.ReadToEnd();
                            }
                            webResponse.Close();
                            if (!string.IsNullOrEmpty(result))
                            {
                                dt.Rows.Clear();
                                Functions.sb_fillDatatableWithHtmlTableId(result, "AutoNumber2", 2, 0, 0, 0, dt);
                                if (dt.Rows.Count > 0)
                                {
                                    this.sb_saveToDB(dt, cycleNumber);
                                }
                            }
                        }
                        pageNumber++;
                    } while (dt.Rows.Count > 0);
                    SharedVariables.logs.Info("End Fetch " + wagonNo + " from " + solarDateFrom + " to " + solarDateTo);
                    entryCustomersHistoryFetchLog.state        = 1;
                    entryCustomersHistoryFetchLog.fetchTimeEnd = DateTime.Now;
                    entityLogistics.SaveChanges();
                    return(true);
                }
                catch (DbEntityValidationException e)
                {
                    foreach (var eve in e.EntityValidationErrors)
                    {
                        SharedVariables.logs.Error("wagonInfoSeirHistory.readAndSaveWagonToDB.finalException   Entity of type \"" + eve.Entry.Entity.GetType().Name
                                                   + "\" in state \"" + eve.Entry.State + "\" has the following validation errors:");
                        foreach (var ve in eve.ValidationErrors)
                        {
                            SharedVariables.logs.Error("- Property: \"" + ve.PropertyName + "\", Error: \"" + ve.ErrorMessage + "\"");
                        }
                    }
                    return(false);
                }
                catch (Exception ex)
                {
                    SharedVariables.logs.Error("wagonInfoSeirHistory.readAndSaveWagonToDB.finalException", ex);
                    return(false);
                }
            }
        }
        public void sb_saveToDB()
        {
            using (var entityLogestic = new logisticEntities())
            {
                bool         add = false;
                PWS0Stations entryPWS0Station = entityLogestic.PWS0Stations.FirstOrDefault(o => o.stcode == this.properties.stcode &&
                                                                                           o.name == this.properties.name && o.name2 == this.properties.name2 &&
                                                                                           o.areaid == this.properties.areaid &&
                                                                                           o.cityid == this.properties.cityid &&
                                                                                           o.cityname == this.properties.cityname &&
                                                                                           o.statename == this.properties.statename &&
                                                                                           o.stateid == this.properties.stateid);
                if (entryPWS0Station == null)
                {
                    add = true;
                    entryPWS0Station = new PWS0Stations();
                }
                entryPWS0Station.lat              = this.properties.lat;
                entryPWS0Station.lon              = this.properties.lon;
                entryPWS0Station.alt              = this.properties.alt;
                entryPWS0Station.name             = this.properties.name;
                entryPWS0Station.name2            = this.properties.name2;
                entryPWS0Station.stcode           = this.properties.stcode;
                entryPWS0Station.bus              = this.properties.bus;
                entryPWS0Station.metro            = this.properties.metro;
                entryPWS0Station.taxi             = this.properties.taxi;
                entryPWS0Station.other            = this.properties.other;
                entryPWS0Station.cellOffice       = this.properties.cellOffice;
                entryPWS0Station.parkingtim       = this.properties.parkingtim;
                entryPWS0Station.sakohamlkh       = this.properties.sakohamlkh;
                entryPWS0Station.daftarforo       = this.properties.daftarforo;
                entryPWS0Station.kioskkhari       = this.properties.kioskkhari;
                entryPWS0Station.khodpardaz       = this.properties.khodpardaz;
                entryPWS0Station.telephonom       = this.properties.telephonom;
                entryPWS0Station.internetbi       = this.properties.internetbi;
                entryPWS0Station.balabar          = this.properties.balabar;
                entryPWS0Station.ramp             = this.properties.ramp;
                entryPWS0Station.postbehdas       = this.properties.postbehdas;
                entryPWS0Station.ambolans         = this.properties.ambolans;
                entryPWS0Station.vilcher          = this.properties.vilcher;
                entryPWS0Station.masirnabin       = this.properties.masirnabin;
                entryPWS0Station.amanatketa       = this.properties.amanatketa;
                entryPWS0Station.tanaqolat        = this.properties.tanaqolat;
                entryPWS0Station.soqat            = this.properties.soqat;
                entryPWS0Station.mobile           = this.properties.mobile;
                entryPWS0Station.sanayedast       = this.properties.sanayedast;
                entryPWS0Station.reservhote       = this.properties.reservhote;
                entryPWS0Station.irani            = this.properties.irani;
                entryPWS0Station.farangi          = this.properties.farangi;
                entryPWS0Station.bajetahvil       = this.properties.bajetahvil;
                entryPWS0Station.salonentez       = this.properties.salonentez;
                entryPWS0Station.salontashr       = this.properties.salontashr;
                entryPWS0Station.namazkhone       = this.properties.namazkhone;
                entryPWS0Station.restoran         = this.properties.restoran;
                entryPWS0Station.vahedetela       = this.properties.vahedetela;
                entryPWS0Station.ashia            = this.properties.ashia;
                entryPWS0Station.sandoq           = this.properties.sandoq;
                entryPWS0Station.saatkaranb       = this.properties.saatkaranb;
                entryPWS0Station.saatkarbaj       = this.properties.saatkarbaj;
                entryPWS0Station.agency           = this.properties.agency;
                entryPWS0Station.areaid           = this.properties.areaid;
                entryPWS0Station.cityid           = this.properties.cityid;
                entryPWS0Station.cityname         = this.properties.cityname;
                entryPWS0Station.statename        = this.properties.statename;
                entryPWS0Station.stateid          = this.properties.stateid;
                entryPWS0Station.TaghlilStationID = this.properties.TaghlilStationID;
                entryPWS0Station.taghlilid        = this.properties.taghlilid;
                entryPWS0Station.FetchTime        = DateTime.Now;
                if (add)
                {
                    entityLogestic.PWS0Stations.Add(entryPWS0Station);
                }

                entityLogestic.SaveChanges();
                //to get id of stationid
                int StationId = entryPWS0Station.Id;

                add = false;
                PWS0StationsGeos entryPWS0StationsGeos = entityLogestic.PWS0StationsGeos.FirstOrDefault(o => o.StationId == StationId &&
                                                                                                        o.id == this.id);
                if (entryPWS0StationsGeos == null)
                {
                    entryPWS0StationsGeos = new PWS0StationsGeos();
                    add = true;
                }
                entryPWS0StationsGeos.id            = this.id;
                entryPWS0StationsGeos.geometry_name = this.geometry_name;
                if (this.geometry != null)
                {
                    entryPWS0StationsGeos.geometryType = this.geometry.type;
                    if (this.geometry.coordinates != null)
                    {
                        entryPWS0StationsGeos.geometryCoordinates = string.Join(",", this.geometry.coordinates.ToArray());
                    }
                }
                entryPWS0StationsGeos.StationId = StationId;
                entryPWS0StationsGeos.type      = this.type;

                if (add)
                {
                    entityLogestic.PWS0StationsGeos.Add(entryPWS0StationsGeos);
                }
                entityLogestic.SaveChanges();
            }
        }
Exemple #18
0
        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)
            {
            }
        }
Exemple #19
0
        private void sb_saveToDB(DataTable dt, int cycleNumber)
        {
            if (dt == null)
            {
                return;
            }
            int              i;
            string           solarDate;
            string           solarTime;
            DateTime?        entranceDateTime;
            customersHistory entryCustomersHistory;
            bool             add;
            string           currentStationName;
            string           wagonNo;
            string           trainNo;
            string           billOfLadingNo;

            using (var entityLogistic = new logisticEntities())
            {
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    try
                    {
                        wagonNo            = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo].ToString());
                        trainNo            = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo].ToString());
                        currentStationName = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName].ToString());
                        billOfLadingNo     = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_billOfLadingNo]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_billOfLadingNo].ToString());
                        #region enteranceDate
                        solarDate = null;
                        solarTime = null;
                        if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate]))
                        {
                            solarDate = "13" + dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate].ToString().Substring(0, 2) + "/"
                                        + dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate].ToString().Substring(2, 2) + "/"
                                        + dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate].ToString().Substring(4, 2);
                        }

                        if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime]))
                        {
                            solarTime = dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime].ToString();
                        }
                        if (!Functions.IsNull(solarTime))
                        {
                            entranceDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(solarDate, int.Parse(solarTime.Replace(":", "")));
                        }
                        else
                        {
                            entranceDateTime = null;
                        }
                        #endregion

                        add = true;
                        entryCustomersHistory = entityLogistic.customersHistories.Where(o =>
                                                                                        o.wagonControlNo == wagonNo &&
                                                                                        o.trainNo == trainNo &&
                                                                                        o.currentStationName == currentStationName &&
                                                                                        o.entranceSolarDate == solarDate &&
                                                                                        o.entranceTime == solarTime &&
                                                                                        o.billOfLadingNo == billOfLadingNo).FirstOrDefault();
                        if (entryCustomersHistory == null)
                        {
                            add = true;
                            entryCustomersHistory = new customersHistory();
                        }
                        else
                        {
                            add = false;
                        }



                        entryCustomersHistory.wagonControlNo              = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo].ToString());
                        entryCustomersHistory.trainNo                     = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo].ToString());
                        entryCustomersHistory.areaName                    = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_areaName]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_areaName].ToString());
                        entryCustomersHistory.currentStationName          = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName].ToString());
                        entryCustomersHistory.entranceSolarDate           = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate]) ? null : solarDate);
                        entryCustomersHistory.entranceTime                = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime].ToString());
                        entryCustomersHistory.distance                    = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_distance]) ? null : (int?)int.Parse(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_distance].ToString()));
                        entryCustomersHistory.goodsType                   = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_goodsType]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_goodsType].ToString());
                        entryCustomersHistory.sourceStationName           = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_sourceStationName]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_sourceStationName].ToString());
                        entryCustomersHistory.destinationStationName      = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_destinationStationName]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_destinationStationName].ToString());
                        entryCustomersHistory.billOfLadingNo              = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_billOfLadingNo]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_billOfLadingNo].ToString());
                        entryCustomersHistory.trainSourcestationName      = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainSourceStationName]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainDestinationStationName].ToString());
                        entryCustomersHistory.trainDestinationStationName = (Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainDestinationStationName]) ? null : dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainDestinationStationName].ToString());
                        entryCustomersHistory.entranceDateTime            = entranceDateTime;
                        entryCustomersHistory.fetchTime                   = DateTime.Now;

                        if (add)
                        {
                            entityLogistic.customersHistories.Add(entryCustomersHistory);
                        }
                        entityLogistic.SaveChanges();
                    }
                    catch (DbEntityValidationException e)
                    {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            SharedVariables.logs.Error("wagonInfoSeirHistory.sb_savetoDb  Entity of type \"" + eve.Entry.Entity.GetType().Name
                                                       + "\" in state \"" + eve.Entry.State + "\" has the following validation errors:");
                            foreach (var ve in eve.ValidationErrors)
                            {
                                SharedVariables.logs.Error("- Property: \"" + ve.PropertyName + "\", Error: \"" + ve.ErrorMessage + "\"");
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        SharedVariables.logs.Error("wagonInfoSeirHistory.sb_savetoDb", ex);
                    }
                }
            }
        }
Exemple #20
0
        private void sb_saveToDBOld(DataTable dt, int cycleNumber)
        {
            if (dt == null)
            {
                return;
            }
            int      i;
            string   solarDate;
            int?     solarTime;
            DateTime?enteranceDateTime;
            raiWagon_Info_Tracking entry_raiWagon_Info_Tracking;

            using (var entityLogistic = new logisticEntities())
            {
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    entry_raiWagon_Info_Tracking = new raiWagon_Info_Tracking();

                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName]))
                    {
                        entry_raiWagon_Info_Tracking.currentStationId = stations.fnc_getStationId(null, dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName].ToString(), true);
                    }

                    entry_raiWagon_Info_Tracking.CycleNumber = cycleNumber;

                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_destinationStationName]))
                    {
                        entry_raiWagon_Info_Tracking.destinationStationId = stations.fnc_getStationId(null, dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_destinationStationName].ToString(), true);
                    }

                    #region enteranceDate
                    solarDate = null;
                    solarTime = null;
                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate] != null))
                    {
                        var solarDateArr = dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate].ToString().Split('/');
                        Array.Reverse(solarDateArr);
                        solarDate = string.Join("", solarDateArr);
                        solarDate = solarDate.Replace("/", "");
                    }

                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime]))
                    {
                        solarTime = int.Parse(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime].ToString().Replace(":", ""));
                    }
                    entry_raiWagon_Info_Tracking.enteranceDateTime = enteranceDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(solarDate, solarTime);;
                    #endregion

                    entry_raiWagon_Info_Tracking.exitDateTime = null;
                    entry_raiWagon_Info_Tracking.FetchTime    = DateTime.Now;

                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_goodsType]))
                    {
                        entry_raiWagon_Info_Tracking.goodsID = goods.fnc_getGoodsId(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_goodsType].ToString()
                                                                                    , false, true);
                    }

                    entry_raiWagon_Info_Tracking.Source = "History";
                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_sourceStationName]))
                    {
                        entry_raiWagon_Info_Tracking.sourceStationId = stations.fnc_getStationId(null, dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_sourceStationName].ToString(), true);
                    }

                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo]))
                    {
                        entry_raiWagon_Info_Tracking.trainId = trainBarry.fnc_getTrainIdFromDB(int.Parse(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo].ToString()), enteranceDateTime);
                    }

                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo]))
                    {
                        entry_raiWagon_Info_Tracking.wagonId = trainBarryWagons.fnc_getWagonIdCheckWithControlNo(long.Parse(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo].ToString()), true);
                    }

                    entry_raiWagon_Info_Tracking.wAreaName               = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_areaName]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_areaName].ToString());
                    entry_raiWagon_Info_Tracking.wBarType                = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_goodsType]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_goodsType].ToString());
                    entry_raiWagon_Info_Tracking.wBillOfLadingNo         = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_billOfLadingNo]) ? null : (long?)long.Parse(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_billOfLadingNo].ToString()));
                    entry_raiWagon_Info_Tracking.wCurrentStationName     = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName].ToString());
                    entry_raiWagon_Info_Tracking.wDestinationStationName = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_destinationStationName]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_destinationStationName].ToString());
                    entry_raiWagon_Info_Tracking.wDistance               = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_distance]) ? null : (int?)int.Parse(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_distance].ToString()));
                    entry_raiWagon_Info_Tracking.wEnteranceDate          = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceSolarDate].ToString());
                    entry_raiWagon_Info_Tracking.wEnteranceTime          = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_entranceTime].ToString());
                    entry_raiWagon_Info_Tracking.wExitDate               = null;
                    entry_raiWagon_Info_Tracking.wExitTime               = null;
                    entry_raiWagon_Info_Tracking.wRowNo                       = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_rowNo]) ? null : (int?)int.Parse(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_rowNo].ToString()));
                    entry_raiWagon_Info_Tracking.wSourceStationName           = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_sourceStationName]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_sourceStationName].ToString());
                    entry_raiWagon_Info_Tracking.wTrainDestinationStationName = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainDestinationStationName]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainDestinationStationName].ToString());
                    entry_raiWagon_Info_Tracking.wTrainNo                     = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo]) ? null : (int?)int.Parse(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainNo].ToString()));
                    entry_raiWagon_Info_Tracking.wTrainSourceStationName      = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainSourceStationName]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_trainSourceStationName].ToString());
                    entry_raiWagon_Info_Tracking.wWagonNo                     = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo]) ? null : (long?)long.Parse(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_wagonNo].ToString()));

                    entityLogistic.raiWagon_Info_Tracking.Add(entry_raiWagon_Info_Tracking);
                    entityLogistic.SaveChanges();
                }
            }
        }
Exemple #21
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)
                {
                }
            }
        }