Exemple #1
0
        private int?fnc_saveValues(IWebElement element, bool download, out bool stopFetch)
        {
            stopFetch = false;
            Dictionary <string, object> dic = this.fnc_getValues(element, download);
            string whereCondition           = this.fnc_getWhereCondition(dic, this.prp_identifierColumnNames);

            using (var entity = new Model.logisticEntities())
            {
                int?idValue;
                var exists = entity.Database.SqlQuery <int?>("select top 1 1 from " + this.TableName + (string.IsNullOrEmpty(whereCondition) ? "" : " where " + whereCondition)).FirstOrDefault();
                if (exists.HasValue)
                {
                    idValue = this.fnc_update(dic, whereCondition);
                    if (this.prp_stopFetchingWhenGotToExistedRows)
                    {
                        stopFetch = true;
                    }
                    return(idValue);
                }
                else
                {
                    idValue = this.fnc_insert(dic);
                    return(idValue);
                }
            }
        }
Exemple #2
0
        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 entityLogistic = new Model.logisticEntities())
                        {
                            foreach (StateCityJsonModel state in statesJson)
                            {
                                this.sb_saveStateToDB(state, saveCitiesForEachState);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #3
0
        public int fnc_getLastPageIndex()
        {
            int?startPageIndex = 1;

            if (string.IsNullOrEmpty(this.TableName))
            {
                throw new Exception("TableName is not specified");
            }
            if (string.IsNullOrEmpty(this.prp_pageIndexColumnName))
            {
                throw new Exception("prp_columnPageIndexName is not specified");
            }
            string whereCondition = "";

            using (var entityLogistic = new Model.logisticEntities())
            {
                if (this.prp_pageIndexIdentifierColumnNames != null && this.prp_pageIndexIdentifierColumnNames.Length > 0)
                {
                    Dictionary <string, object> dicValues = this.fnc_getValues(null, false, this.prp_pageIndexIdentifierColumnNames);
                    whereCondition = this.fnc_getWhereCondition(dicValues, this.prp_pageIndexIdentifierColumnNames);
                }
                startPageIndex = entityLogistic.Database.SqlQuery <int?>("select max(" + this.prp_pageIndexColumnName + ") from " + this.TableName + (string.IsNullOrEmpty(whereCondition) ? "" : " where " + whereCondition)).FirstOrDefault();

                if (!startPageIndex.HasValue)
                {
                    return(1);
                }
                return(startPageIndex.Value);
            }
        }
 public static int?fnc_getWagonIdCheckWithControlNo(long?wagonNo /*,bool add*/, bool notifNotExist)
 {
     if (!wagonNo.HasValue)
     {
         return(null);
     }
     using (var entityLogistic = new Model.logisticEntities())
     {
         var entryWagon = entityLogistic.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 Model.Wagon();
             //    entryWagon.wagonNo = wagonNo;
             //    entityLogistic.Wagons.Add(entryWagon);
             //    entityLogistic.SaveChanges();
             //    return entryWagon.Id;
             //}
             //else return null;
             return(null);
         }
         else
         {
             return(entryWagon.Id);
         }
     }
 }
Exemple #5
0
        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 entityLogistic = new Model.logisticEntities())
                        {
                            foreach (station_featureJsonModel feature in stationsJson.features)
                            {
                                feature.sb_saveToDB();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #6
0
 public static int?fnc_getBillOfLadingId(long?billOfLadingNo /*,bool add*/, bool notifNotExist)
 {
     if (!billOfLadingNo.HasValue)
     {
         return(null);
     }
     using (var entityLogistic = new Model.logisticEntities())
     {
         var entryBillOfLading = entityLogistic.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 Model.Wagon();
             //    entryWagon.wagonNo = wagonNo;
             //    entityLogistic.Wagons.Add(entryWagon);
             //    entityLogistic.SaveChanges();
             //    return entryWagon.Id;
             //}
             //else return null;
             return(null);
         }
         else
         {
             return(entryBillOfLading.Id);
         }
     }
 }
Exemple #7
0
        public void sb_saveToDB(trainBillOfLadingsJsonModel billOfLading, int train_no, int?trainId, int cycleNumber, string fetchUrl)
        {
            bool add = false;

            using (var entityLogistic = new Model.logisticEntities())
            {
                Model.PWS0BillOfLadings entryPWS0BillOfLading = entityLogistic.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 Model.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)
                    {
                        entityLogistic.PWS0BillOfLadings.Add(entryPWS0BillOfLading);
                    }

                    entityLogistic.SaveChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }
        public static bool fnc_saveWagonFromRWMMS(rwmms.declerationListDataTable dt, int rowIndex)
        {
            if (dt == null)
            {
                throw new Exception("dt is null");
            }
            if (rowIndex < 0 || rowIndex >= dt.Rows.Count)
            {
                throw new Exception("rowIndex " + rowIndex + " is outofbound");
            }
            DataRow dr      = dt.Rows[rowIndex];
            long    wagonNo = long.Parse(dr[rwmms.declerationListDataTable.fld_wagonNo].ToString());

            try
            {
                using (var entityLogistic = new Model.logisticEntities())
                {
                    bool add        = false;
                    var  entryWagon = entityLogistic.Wagons.FirstOrDefault(o => o.wagonNo == wagonNo);

                    if (entryWagon == null)
                    {
                        add        = true;
                        entryWagon = new Model.Wagon();
                    }
                    //entryWagon.capacity ;
                    entryWagon.companyId             = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_ownerName]) ? null : rwmms.vehicleOwners.Fnc_getVehicleOwnerId(dr[rwmms.declerationListDataTable.fld_ownerName].ToString());
                    entryWagon.wagonNo               = wagonNo;
                    entryWagon.wagonTypeId           = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonTypeName]) ? null : trainBarryWagons.fnc_getWagonTypeName(dr[rwmms.declerationListDataTable.fld_wagonTypeName].ToString(), true, true);
                    entryWagon.wrAxisCount           = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonAxisCount]) ? null : (int?)int.Parse(dr[rwmms.declerationListDataTable.fld_wagonAxisCount].ToString());
                    entryWagon.wrBoogieType          = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonBoogieType]) ? null : dr[rwmms.declerationListDataTable.fld_wagonBoogieType].ToString();
                    entryWagon.wrBrakeType           = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonBrakeType]) ? null : dr[rwmms.declerationListDataTable.fld_wagonBrakeType].ToString();
                    entryWagon.wrCapacity            = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonCapacity]) ? null : (double?)double.Parse(dr[rwmms.declerationListDataTable.fld_wagonCapacity].ToString());
                    entryWagon.wrChassisSerial       = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonChassisSerialNo]) ? null : dr[rwmms.declerationListDataTable.fld_wagonChassisSerialNo].ToString();
                    entryWagon.wrCompanyManufacturer = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonCompanyManufacturer]) ? null : dr[rwmms.declerationListDataTable.fld_wagonCompanyManufacturer].ToString();
                    entryWagon.wrCountry             = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonCountry]) ? null : dr[rwmms.declerationListDataTable.fld_wagonCountry].ToString();
                    entryWagon.wrHookType            = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonHookType]) ? null : dr[rwmms.declerationListDataTable.fld_wagonHookType].ToString();
                    entryWagon.wrNetWeight           = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonNetWeight]) ? null : (double?)double.Parse(dr[rwmms.declerationListDataTable.fld_wagonNetWeight].ToString());
                    entryWagon.wrProductionYear      = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonProductionYear]) ? null : (int?)int.Parse(dr[rwmms.declerationListDataTable.fld_wagonProductionYear].ToString());
                    entryWagon.wrRivNo               = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonRIVNo]) ? null : dr[rwmms.declerationListDataTable.fld_wagonRIVNo].ToString();
                    entryWagon.wrWagonTypeName       = Functions.IsNull(dr[rwmms.declerationListDataTable.fld_wagonTypeName]) ? null : dr[rwmms.declerationListDataTable.fld_wagonTypeName].ToString();

                    if (add)
                    {
                        entityLogistic.Wagons.Add(entryWagon);
                    }
                    else
                    {
                        entityLogistic.Entry(entryWagon).State = EntityState.Modified;
                    }
                    entityLogistic.SaveChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Exemple #9
0
        public static int?fnc_getStationId(int?stationCode, string stationName, bool notifNotExist)
        {
            if (!stationCode.HasValue && string.IsNullOrEmpty(stationName))
            {
                return(null);
            }

            using (var entityLogistic = new Model.logisticEntities())
            {
                Model.PWS0Stations station;
                if (stationCode.HasValue)
                {
                    station = entityLogistic.PWS0Stations.FirstOrDefault(o => o.stcode == stationCode);
                }
                else
                {
                    station = entityLogistic.PWS0Stations.FirstOrDefault(o => o.name == stationName);
                    if (station == null)
                    {
                        station = entityLogistic.PWS0Stations.FirstOrDefault(o => o.name2 == stationName);
                        if (station == null)
                        {
                            station = entityLogistic.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 Model.PWS0Goods();
                    //    entryStation.name = stationName;
                    //    entityLogistic.PWS0Stations.Add(entryStation);
                    //    entityLogistic.SaveChanges();
                    //    return entryStation.Id;
                    //}
                    //else return null;

                    return(null);
                }
                else
                {
                    return(station.Id);
                }
            }
        }
Exemple #10
0
        private int?fnc_update(Dictionary <string, object> dic, string whereCondition)
        {
            string cmd = "";
            int    i;
            object value;

            for (i = 0; i <= dic.Count - 1; i++)
            {
                if (this.Columns[dic.ElementAt(i).Key] is htmlControl &&
                    !string.IsNullOrEmpty(((htmlControl)this.Columns[dic.ElementAt(i).Key]).prp_alternateColName))
                {
                    //those columns which have alternate names should not be updated
                    //for example we have companyName ='microsoft' column which has alternatenames = 'micro soft'
                    //now we have 'micro soft' as value so we should not update companyName with 'micro soft'
                    continue;
                }
                if (this.Columns[dic.ElementAt(i).Key] is htmlControl &&
                    !((htmlControl)this.Columns[dic.ElementAt(i).Key]).prp_saveToDB)
                {
                    //some columns like yes/no can be ignored and save as bit via computedcolumn
                    continue;
                }
                value = dic.ElementAt(i).Value;

                if (Functions.IsNull(value))
                {
                    cmd = cmd + dic.ElementAt(i).Key + "=" + " Null " + ",";
                }
                else if (Functions.fnc_isNumeric(value))
                {
                    cmd = cmd + dic.ElementAt(i).Key + "=" + value.ToString() + ",";
                }
                else
                {
                    cmd = cmd + dic.ElementAt(i).Key + "='" + value.ToString() + "',";
                }
            }
            if (!string.IsNullOrEmpty(cmd))
            {
                cmd = cmd.Remove(cmd.Length - 1, 1);
            }
            cmd = " update " + this.TableName + " set " + cmd
                  + " output inserted." + this.prp_columnIdName + (string.IsNullOrEmpty(whereCondition) ? "" : " where " + whereCondition);
            using (var entity = new Model.logisticEntities())
            {
                try
                {
                    int?id = entity.Database.SqlQuery <int?>(cmd).FirstOrDefault();
                    return(id);
                }
                catch (Exception ex)
                {
                    Program.logs.Error("Error in fnc_update", ex);
                    //return null;
                }
                return(null);
            }
        }
        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 entityLogistic = new Model.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)
            {
            }
        }
Exemple #12
0
        /// <summary>
        /// Columns which should be comapred with parentRefcolumns
        /// </summary>

        public object fnc_getColumnValue(Dictionary <string, object> dicValues)
        {
            string whereCondition = this.fnc_getWhereCondition(dicValues);

            using (var entity = new Model.logisticEntities())
            {
                var value = entity.Database.SqlQuery <int?>("select top 1 " + this.prp_parentIdColumnName + " from " + this.prp_parentTableName + " where " + whereCondition).FirstOrDefault();
                return(value);
            }
        }
        private void sb_saveGroupsToDB(wagonPartsGroupsDataTable dt, int?idGroupParent)
        {
            if (dt == null)
            {
                return;
            }
            int    i;
            bool   add;
            string groupName;

            Model.rwmmsWagonPartsGroup entry_wagonPartsGroup;
            using (var entityLogistic = new Model.logisticEntities())
            {
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    add = false;
                    if (Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName]))
                    {
                        continue;
                    }
                    groupName             = dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName].ToString();
                    entry_wagonPartsGroup = entityLogistic.rwmmsWagonPartsGroups.FirstOrDefault(o => o.IdGroupParent == idGroupParent &&
                                                                                                o.wGroupName == groupName);
                    if (entry_wagonPartsGroup == null)
                    {
                        add = true;
                        entry_wagonPartsGroup = new Model.rwmmsWagonPartsGroup();
                    }

                    entry_wagonPartsGroup.FetchTime     = DateTime.Now;
                    entry_wagonPartsGroup.IdGroupParent = idGroupParent;
                    entry_wagonPartsGroup.wGroupName    = Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName]) ? null : dt.Rows[i][wagonPartsGroupsDataTable.fld_groupName].ToString();
                    entry_wagonPartsGroup.wPSID         = Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_psid]) ? null : dt.Rows[i][wagonPartsGroupsDataTable.fld_psid].ToString();
                    entry_wagonPartsGroup.wSerialNo     = Functions.IsNull(dt.Rows[i][wagonPartsGroupsDataTable.fld_serialNo]) ? null : dt.Rows[i][wagonPartsGroupsDataTable.fld_serialNo].ToString().Replace(" ", "").Replace("\r\n", "");

                    if (add)
                    {
                        entityLogistic.rwmmsWagonPartsGroups.Add(entry_wagonPartsGroup);
                    }
                    else
                    {
                        entityLogistic.Entry(entry_wagonPartsGroup).State = System.Data.Entity.EntityState.Modified;
                    }
                    try
                    {
                        entityLogistic.SaveChanges();
                        dt.Rows[i][wagonPartsGroupsDataTable.fld_id] = entry_wagonPartsGroup.Id;
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
        }
Exemple #14
0
        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 entityLogistic = new Model.logisticEntities())
                        {
                            foreach (StateCityJsonModel city in cities)
                            {
                                this.sb_saveCityToDB(city, stateId, parentId);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
        private void sb_saveOwnersDetailsToDB(DataTable dt, int cycleNumber)
        {
            if (dt == null)
            {
                return;
            }
            int i;

            Model.rwmmsVehicleOwnersDetail entry_vehicleOwnersDetail;
            bool   add;
            string meliNo;

            using (var entityLogistic = new Model.logisticEntities())
            {
                for (i = 0; i <= dt.Rows.Count - 1; i++)
                {
                    add = false;
                    if (!Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo]))
                    {
                        meliNo = dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo].ToString();
                        entry_vehicleOwnersDetail = entityLogistic.rwmmsVehicleOwnersDetails.FirstOrDefault(o => o.wMeliNo == meliNo);
                        if (entry_vehicleOwnersDetail == null)
                        {
                            add = true;
                            entry_vehicleOwnersDetail = new Model.rwmmsVehicleOwnersDetail();
                        }
                    }
                    else
                    {
                        entry_vehicleOwnersDetail = new Model.rwmmsVehicleOwnersDetail();
                        add = true;
                    }
                    //entry_vehicleOwnersDetail.companyId = companyId;
                    entry_vehicleOwnersDetail.CycleNumber   = cycleNumber;
                    entry_vehicleOwnersDetail.FetchTime     = DateTime.Now;
                    entry_vehicleOwnersDetail.Source        = "rwmms";
                    entry_vehicleOwnersDetail.wEmail        = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_email]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_email].ToString();
                    entry_vehicleOwnersDetail.wFName        = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_fname]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_fname].ToString();
                    entry_vehicleOwnersDetail.wLName        = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_lname]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_lname].ToString();
                    entry_vehicleOwnersDetail.wMeliNo       = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_meliNo].ToString();
                    entry_vehicleOwnersDetail.wMobileNumber = Functions.IsNull(dt.Rows[i][vehicleOwnersDetailDataTable.fld_mobileNumber]) ? null : dt.Rows[i][vehicleOwnersDetailDataTable.fld_mobileNumber].ToString();
                    if (add)
                    {
                        entityLogistic.rwmmsVehicleOwnersDetails.Add(entry_vehicleOwnersDetail);
                    }
                    else
                    {
                        entityLogistic.Entry(entry_vehicleOwnersDetail).State = System.Data.Entity.EntityState.Modified;
                    }
                    entityLogistic.SaveChanges();
                }
            }
        }
Exemple #16
0
        private int?fnc_insert(Dictionary <string, object> dic)
        {
            string columnNames  = "";
            string columnValues = "";
            string cmd;
            int    i;
            object value;

            for (i = 0; i <= dic.Count - 1; i++)
            {
                if (this.Columns[dic.ElementAt(i).Key] is htmlControl &&
                    !((htmlControl)this.Columns[dic.ElementAt(i).Key]).prp_saveToDB)
                {
                    //some columns like yes/no can be ignored and save as bit via computedcolumn
                    continue;
                }
                value = dic.ElementAt(i).Value;
                if (Functions.IsNull(value))
                {
                    columnValues = columnValues + " Null " + ",";
                }
                else if (Functions.fnc_isNumeric(value))
                {
                    columnValues = columnValues + value + ",";
                }
                else
                {
                    columnValues = columnValues + "'" + value + "',";
                }

                columnNames = columnNames + dic.ElementAt(i).Key + ",";
            }
            if (!string.IsNullOrEmpty(columnNames))
            {
                columnNames  = columnNames.Remove(columnNames.Length - 1, 1);
                columnValues = columnValues.Remove(columnValues.Length - 1, 1);
            }
            cmd = " insert into " + this.TableName + "(" + columnNames + ")" + " OUTPUT inserted." + this.prp_columnIdName + " values(" + columnValues + ")";
            using (var entity = new Model.logisticEntities())
            {
                try
                {
                    int?id = entity.Database.SqlQuery <int?>(cmd).FirstOrDefault();
                    return(id);
                }
                catch (Exception ex)
                {
                    Program.logs.Error("Error in fnc_insert", ex);
                }
                return(null);
            }
        }
 public static int?fnc_getTrainIdFromDB(int train_no, DateTime?enteranceDateTime)
 {
     using (var entityLogistic = new Model.logisticEntities())
     {
         var entryTrainBarry = entityLogistic.PWS0TrainsBarry.FirstOrDefault(o => o.jTrain_No == train_no &&
                                                                             o.jEntrance_DateTime == enteranceDateTime);
         if (entryTrainBarry == null)
         {
             return(null);
         }
         return(entryTrainBarry.Id);
     }
 }
Exemple #18
0
        public Grabber()
        {
            int?temp;

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

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

                temp = entityLogistic.PWS0TrainsPassengers.Where(o => DbFunctions.TruncateTime(o.FetchTime) == dateTime).Max(o => o.CycleNumber);
                this.v_cyleNumberTrainsPassenger = (temp.HasValue ? temp.Value : 0) + 1;
            }
        }
Exemple #19
0
        public bool fnc_insert(Dictionary <string, object> dic)
        {
            string columnNames  = "";
            string columnValues = "";
            string cmd;
            int    i;
            object value;

            for (i = 0; i <= dic.Count - 1; i++)
            {
                value = dic.ElementAt(i).Value;
                if (Functions.IsNull(value))
                {
                    columnValues = columnValues + " Null " + ",";
                }
                else if (Functions.fnc_isNumeric(value))
                {
                    columnValues = columnValues + value + ",";
                }
                else
                {
                    columnValues = columnValues + "'" + value + "',";
                }

                columnNames = columnNames + dic.ElementAt(i).Key + ",";
            }
            if (!string.IsNullOrEmpty(columnNames))
            {
                columnNames  = columnNames.Remove(columnNames.Length - 1, 1);
                columnValues = columnValues.Remove(columnValues.Length - 1, 1);
            }
            cmd = " insert into " + this.TableName + "(" + columnNames + ")values(" + columnValues + ")";
            using (var entity = new Model.logisticEntities())
            {
                try
                {
                    entity.Database.ExecuteSqlCommand(cmd);
                    return(true);
                }
                catch (Exception ex)
                {
                    Program.logs.Error("Error in fnc_insert", ex);
                    return(false);
                }
            }
        }
Exemple #20
0
 public static int?Fnc_getVehicleOwnerId(string ownerName)
 {
     if (string.IsNullOrEmpty(ownerName))
     {
         return(null);
     }
     using (var entityLogistic = new Model.logisticEntities())
     {
         var entry_vehicleOwner = entityLogistic.rwmmsVehicleOwners.FirstOrDefault(o => o.companyName == ownerName ||
                                                                                   o.AlternateNames.Contains(ownerName + ";"));
         if (entry_vehicleOwner == null)
         {
             return(null);
         }
         else
         {
             return(entry_vehicleOwner.Id);
         }
     }
 }
Exemple #21
0
        public bool fnc_update(Dictionary <string, object> dic, string whereCondition)
        {
            string cmd = "";
            int    i;
            object value;

            for (i = 0; i <= dic.Count - 1; i++)
            {
                value = dic.ElementAt(i).Value;
                if (Functions.IsNull(value))
                {
                    cmd = cmd + dic.ElementAt(i).Key + "=" + " Null " + ",";
                }
                else if (Functions.fnc_isNumeric(value))
                {
                    cmd = cmd + dic.ElementAt(i).Key + "=" + value.ToString() + ",";
                }
                else
                {
                    cmd = cmd + dic.ElementAt(i).Key + "='" + value.ToString() + "',";
                }
            }
            if (!string.IsNullOrEmpty(cmd))
            {
                cmd = cmd.Remove(cmd.Length - 1, 1);
            }
            cmd = " update " + this.TableName + " set " + cmd + " where " + whereCondition;
            using (var entity = new Model.logisticEntities())
            {
                try
                {
                    entity.Database.ExecuteSqlCommand(cmd);
                    return(true);
                }
                catch (Exception ex)
                {
                    Program.logs.Error("Error in fnc_update", ex);
                    return(false);
                }
            }
        }
Exemple #22
0
 public static int?fnc_getGoodsId(string goodsName, bool add, bool notifNotExist)
 {
     if (string.IsNullOrEmpty(goodsName))
     {
         return(null);
     }
     if (goodsName == "واگن بدون بار")
     {
         return(-1);
     }
     using (var entityLogistic = new Model.logisticEntities())
     {
         var entryGoods = entityLogistic.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 Model.PWS0Goods();
                 entryGoods.goodsName = goodsName;
                 entityLogistic.PWS0Goods.Add(entryGoods);
                 entityLogistic.SaveChanges();
                 return(entryGoods.Id);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(entryGoods.Id);
         }
     }
 }
Exemple #23
0
        public bool fnc_save(System.Collections.ObjectModel.ReadOnlyCollection <IWebElement> items)
        {
            int    i;
            string whereCondition = "";
            Dictionary <string, object> dic;
            bool retVal = true;

            for (i = prp_skipRowTop; i <= items.Count - 1 - prp_skipRowBottom; i++)
            {
                if (this.prp_skipRowIndecies != null && this.prp_skipRowIndecies.Contains(i))
                {
                    continue;
                }

                whereCondition = this.fnc_getWhereCondition(items[i]);
                dic            = this.fnc_getColumnsValue(items[i]);

                using (var entity = new Model.logisticEntities())
                {
                    var exists = entity.Database.SqlQuery <int?>("select top 1 1 from " + this.TableName + " where " + whereCondition).FirstOrDefault();
                    if (exists.HasValue)
                    {
                        if (!this.fnc_update(dic, whereCondition))
                        {
                            retVal = false;
                        }
                    }
                    else
                    {
                        if (!this.fnc_insert(dic))
                        {
                            retVal = false;
                        }
                    }
                }
            }
            return(retVal);
        }
Exemple #24
0
        /// <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 entityLogistic = new Model.logisticEntities())
            {
                if (!parentIdInDB.HasValue)
                {
                    var entryState = entityLogistic.PWS0StateCities.FirstOrDefault(o => o.ParentStateIdInJson == parentStateIdInJson && (o.isState.HasValue && o.isState.Value));
                    if (entryState != null)
                    {
                        parentIdInDB = entryState.Id;
                    }
                }
                bool add = false;
                Model.PWS0StateCities entryPWS0City = entityLogistic.PWS0StateCities.FirstOrDefault(o => o.CityId == cityJson.CityID &&
                                                                                                    (!o.isState.HasValue || !o.isState.Value));

                if (entryPWS0City == null)
                {
                    add           = true;
                    entryPWS0City = new Model.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)
                {
                    entityLogistic.PWS0StateCities.Add(entryPWS0City);
                }

                entityLogistic.SaveChanges();
            }
        }
 public static int?fnc_getWagonTypeName(string wagonTypeName, bool add, bool notifNotExist)
 {
     if (string.IsNullOrEmpty(wagonTypeName))
     {
         return(null);
     }
     using (var entityLogistic = new Model.logisticEntities())
     {
         var entryWagonType = entityLogistic.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 Model.WagonsType();
                 entryWagonType.typeName = wagonTypeName;
                 entityLogistic.WagonsTypes.Add(entryWagonType);
                 entityLogistic.SaveChanges();
                 return(entryWagonType.Id);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(entryWagonType.Id);
         }
     }
 }
Exemple #26
0
        private void sb_saveStateToDB(StateCityJsonModel stateJson, bool saveCitiesForEachState)
        {
            using (var entityLogistic = new Model.logisticEntities())
            {
                bool add = false;
                Model.PWS0StateCities entryPWS0State = entityLogistic.PWS0StateCities.FirstOrDefault(o => o.StateId == stateJson.StateID &&
                                                                                                     o.isState.HasValue && o.isState.Value);

                if (entryPWS0State == null)
                {
                    add            = true;
                    entryPWS0State = new Model.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)
                {
                    entityLogistic.PWS0StateCities.Add(entryPWS0State);
                }

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

                if (saveCitiesForEachState && stateJson.StateID.HasValue)
                {
                    this.sb_readAndSaveCitiesToDB(stateJson.StateID.Value, parentIdInDB);
                }
            }
        }
Exemple #27
0
 public static int?fnc_getAreaId(string areaName, bool add, bool notifNotExist)
 {
     if (string.IsNullOrEmpty(areaName))
     {
         return(null);
     }
     //if (areaName == "واگن بدون بار") return -1;
     using (var entityLogistic = new Model.logisticEntities())
     {
         var entryArea = entityLogistic.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 Model.Area();
                 entryArea.areaName = areaName;
                 entityLogistic.Areas.Add(entryArea);
                 entityLogistic.SaveChanges();
                 return(entryArea.Id);
             }
             else
             {
                 return(null);
             }
         }
         else
         {
             return(entryArea.Id);
         }
     }
 }
        public void sb_readAndSaveToDB(bool loginAndLogout, bool getAttach)
        {
            if (loginAndLogout)
            {
                login lg = new login();
                lg.fnc_logoutWithSelenium(this.v_webBrowser);
                if (login.fnc_isLoginPage(this.v_webBrowser.Url, this.v_url))
                {
                    lg.fnc_loginWithSelenium(this.v_webBrowser);
                    this.v_webBrowser.Navigate().GoToUrl(this.v_url);
                    SharedFunctions.sb_waitForReady(this.v_webBrowser);
                }
            }

            int    pageIndex = 1;
            int    rowIndex;
            string html;

            using (var entityLogistic = new Model.logisticEntities())
            {
                for (pageIndex = 1; pageIndex <= this.v_pageCount; pageIndex++)
                {
                    Program.logs.Info("Start of :" + pageIndex);
                    //if we should get extraDetail we should logout and then login again
                    if (pageIndex > 1)
                    {
                        pageIndex = seleniumDownloader.fnc_gotoPage(this.v_webBrowser, this.v_url, this.v_tableId, pageIndex, this.v_pageCount, false);
                        if (pageIndex == -1)
                        {
                            return;
                        }
                    }

                    html = this.v_webBrowser.PageSource;

                    if (!string.IsNullOrEmpty(html))
                    {
                        this.v_dt.Rows.Clear();
                        Functions.sb_fillDatatableWithHtmlTableId(html, v_tableId, this.v_dt);
                        this.sb_fillDatatablePSID(html, v_tableId, 2, this.v_dt);
                        if (this.v_dt.Rows.Count > 0)
                        {
                            this.sb_saveGroupsToDB(this.v_dt, null);
                        }
                    }
                    else
                    {
                        break;
                    }

                    try
                    {
                        int groupId;
                        for (rowIndex = 0; rowIndex <= this.v_dt.Rows.Count - 1; rowIndex++)
                        {
                            if (Functions.IsNull(this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_id]))
                            {
                                continue;
                            }

                            groupId = int.Parse(this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_id].ToString());

                            var el    = this.v_webBrowser.FindElement(By.Id(this.v_tableId));
                            var rows  = el.FindElements(By.TagName("tr"));
                            var cells = rows[rowIndex + this.v_dt.prp_skipRowTop].FindElements(By.TagName("td"));
                            cells[2].Click();
                            SharedFunctions.sb_waitForReady(this.v_webBrowser);

                            var queryString = HttpUtility.ParseQueryString(this.v_webBrowser.Url);
                            if (!Functions.IsNull(queryString["psid"]))
                            {
                                var entryPartGroup = entityLogistic.rwmmsWagonPartsGroups.FirstOrDefault(o => o.Id == groupId);
                                if (entryPartGroup != null)
                                {
                                    entryPartGroup.wPSID = queryString["psid"];
                                    entityLogistic.SaveChanges();
                                }
                            }
                            this.sb_readAndSavePartsToDB(groupId, this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_groupName].ToString(), getAttach
                                                         , this.v_downloadPath);
                            this.sb_readAndSaveSubGroupsToDB(groupId, getAttach, this.v_downloadPath + (this.v_downloadPath.EndsWith("\\") ? "" : "\\") + this.v_dt.Rows[rowIndex][wagonPartsGroupsDataTable.fld_groupName].ToString());

                            var elPath         = this.v_webBrowser.FindElement(By.Id(this.v_pathElementId));
                            var hrefCollection = elPath.FindElements(By.TagName("a"));
                            if (hrefCollection != null && hrefCollection.Count > 0)
                            {
                                hrefCollection[hrefCollection.Count - 1].Click();
                                SharedFunctions.sb_waitForReady(this.v_webBrowser);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    Program.logs.Info("End of :" + pageIndex);
                }
            }
        }
Exemple #29
0
        private void sb_saveToDB(DataTable dt, int cycleNumber)
        {
            if (dt == null)
            {
                return;
            }
            int      i;
            string   solarDate;
            int?     solarTime;
            DateTime?enteranceDateTime;

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



                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_currentStationName]))
                    {
                        entry_raiWagon_Info_Tracking.currentStationId = PWS0.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 = PWS0.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_enteranceDate] != null))
                    {
                        var solarDateArr = dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_enteranceDate].ToString().Split('/');
                        Array.Reverse(solarDateArr);
                        solarDate = string.Join("", solarDateArr);
                        solarDate = solarDate.Replace("/", "");
                    }

                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_enteranceTime]))
                    {
                        solarTime = int.Parse(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_enteranceTime].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_barType]))
                    {
                        entry_raiWagon_Info_Tracking.goodsID = PWS0.goods.fnc_getGoodsId(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_barType].ToString()
                                                                                         , false, true);
                    }

                    entry_raiWagon_Info_Tracking.Source = "History";
                    if (!Functions.IsNull(dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_sourceStationName]))
                    {
                        entry_raiWagon_Info_Tracking.sourceStationId = PWS0.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 = PWS0.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 = PWS0.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_barType]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_barType].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_enteranceDate]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_enteranceDate].ToString());
                    entry_raiWagon_Info_Tracking.wEnteranceTime          = (Functions.IsNull(this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_enteranceTime]) ? null : this.v_dt.Rows[i][wagonInfoSeirHistoryDataTable.fld_enteranceTime].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();
                }
            }
        }
        private void sb_readExtraDetailAndSaveToDB(int cycleNumber, int pageIndex)
        {
            int    rowIndex = 1;
            string htmlEditPage;

            nextRecord : pageIndex = this.fnc_gotoPage(pageIndex, true);
            if (pageIndex == -1)
            {
                return;
            }

            var table = this.v_webBrowser.FindElementById(v_tableId);

            if (table != null)
            {
                var rows = table.FindElements(By.TagName("tr"));
                if (rows != null && rows.Count > 0 && rowIndex <= rows.Count - 2)
                {//first and last row are header and footer
                    using (var entityLogistic = new Model.logisticEntities())
                    {
                        var columns = rows[rowIndex].FindElements(By.TagName("td"));
                        if (columns.Count >= 6)
                        {
                            var href = columns[6].FindElement(By.TagName("a"));
                            if (href != null)
                            {
                                href.Click();
                                SharedFunctions.sb_waitForReady(this.v_webBrowser);
                                htmlEditPage = this.v_webBrowser.PageSource;
                                string firstName    = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtFirstName");
                                string lastName     = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtLastName");
                                string fatherName   = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtFatherName");
                                string certNo       = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtIdentityNumber");
                                string registerCity = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtIdentityRegisterLocation");
                                string meliNo       = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtNationalCode");

                                string postalCode   = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtAgentPostCode");
                                string email        = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtAgentEmail");
                                string mobileNumber = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtMobileNumber");
                                string birthDate    = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtBirthDate");
                                string address      = Functions.fnc_getElementValue(htmlEditPage, "ContentPlaceHolder1_txtAgentAddress");

                                if (!string.IsNullOrEmpty(meliNo))
                                {
                                    var entryOwnerExtraDetail = entityLogistic.rwmmsVehicleOwnersDetails.FirstOrDefault(o => o.wMeliNo == meliNo);
                                    if (entryOwnerExtraDetail != null)
                                    {
                                        //entryOwnerExtraDetail.companyId
                                        entryOwnerExtraDetail.CycleNumber   = cycleNumber;
                                        entryOwnerExtraDetail.FetchTime     = DateTime.Now;
                                        entryOwnerExtraDetail.Source        = "http://rwmms.rai.ir/VehicleOwnerDetailInfo.aspx";
                                        entryOwnerExtraDetail.wAddress      = (Functions.IsNull(address) ? null : address);
                                        entryOwnerExtraDetail.wBirthDate    = (Functions.IsNull(birthDate) ? null : birthDate);
                                        entryOwnerExtraDetail.wCertNo       = (Functions.IsNull(certNo) ? null : certNo);
                                        entryOwnerExtraDetail.wEmail        = (Functions.IsNull(email) ? null : email);
                                        entryOwnerExtraDetail.wFatherName   = (Functions.IsNull(fatherName) ? null : fatherName);
                                        entryOwnerExtraDetail.wFName        = (Functions.IsNull(firstName) ? null : firstName);
                                        entryOwnerExtraDetail.wLName        = (Functions.IsNull(lastName) ? null : lastName);
                                        entryOwnerExtraDetail.wMeliNo       = (Functions.IsNull(meliNo) ? null : meliNo);
                                        entryOwnerExtraDetail.wMobileNumber = (Functions.IsNull(mobileNumber) ? null : mobileNumber);
                                        entryOwnerExtraDetail.wPostalCode   = (Functions.IsNull(postalCode) ? null : postalCode);
                                        entryOwnerExtraDetail.wRegisterCity = (Functions.IsNull(registerCity) ? null : registerCity);
                                        entityLogistic.Entry(entryOwnerExtraDetail).State = System.Data.Entity.EntityState.Modified;
                                        entityLogistic.SaveChanges();
                                    }
                                }

                                rowIndex++;
                                goto nextRecord;
                            }
                        }
                    }
                }
            }
        }