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); } }
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) { } } } }
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(); } } }
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); } } }
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); } } }
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); } } }
/// <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_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); } } }
private void sb_saveToDB(DataTable dt, int cycleNumber, string introductionFilePath, out Model.rwmmsVehicleOwner entry_vehicleOwner) { entry_vehicleOwner = null; if (dt == null) { return; } int i; //Model.rwmmsVehicleOwner entry_company; bool add; string companyName; using (var entityLogistic = new Model.logisticEntities()) { for (i = 0; i <= dt.Rows.Count - 1; i++) { add = false; if (Functions.IsNull(dt.Rows[i][vehicleOwnersDataTable.fld_companyName])) { continue; } companyName = dt.Rows[i][vehicleOwnersDataTable.fld_companyName].ToString(); var ownerId = Fnc_getVehicleOwnerId(companyName); if (!ownerId.HasValue) { add = true; entry_vehicleOwner = new Model.rwmmsVehicleOwner(); } else { entry_vehicleOwner = entityLogistic.rwmmsVehicleOwners.FirstOrDefault(o => o.Id == ownerId); } //if (entry_vehicleOwner == null) //{ // add = true; // entry_vehicleOwner = new Model.rwmmsVehicleOwner(); //} //entry_company.AlternateNames = //entry_company.companyName = entry_vehicleOwner.CycleNumber = cycleNumber; //entry_company.Description entry_vehicleOwner.FetchTime = DateTime.Now; //entry_company.PostalCode entry_vehicleOwner.registerDate = Functions.IsNull(dt.Rows[i][vehicleOwnersDataTable.fld_registerPersianDate]) ? null : (DateTime?)Functions.solarToMiladi(dt.Rows[i][vehicleOwnersDataTable.fld_registerPersianDate].ToString()); //entry_company.ShenaseMeli= entry_vehicleOwner.Source = "rwmms"; entry_vehicleOwner.wCompanyName = companyName; entry_vehicleOwner.wIntroductionFile = Functions.IsNull(introductionFilePath) ? null : introductionFilePath; entry_vehicleOwner.wRegisterCityName = Functions.IsNull(dt.Rows[i][vehicleOwnersDataTable.fld_registerCityName]) ? null : dt.Rows[i][vehicleOwnersDataTable.fld_registerCityName].ToString(); entry_vehicleOwner.wRegisterNo = Functions.IsNull(dt.Rows[i][vehicleOwnersDataTable.fld_registerNo]) ? null : dt.Rows[i][vehicleOwnersDataTable.fld_registerNo].ToString(); entry_vehicleOwner.wRegsiterPersianDate = Functions.IsNull(dt.Rows[i][vehicleOwnersDataTable.fld_registerPersianDate]) ? null : dt.Rows[i][vehicleOwnersDataTable.fld_registerPersianDate].ToString(); if (add) { entityLogistic.rwmmsVehicleOwners.Add(entry_vehicleOwner); } else { entityLogistic.Entry(entry_vehicleOwner).State = System.Data.Entity.EntityState.Modified; } entityLogistic.SaveChanges(); //companyId = entry_company.Id; } } }
public void sb_readAndSaveToDB(bool getOwners, bool getIntroductionFiles, int cycleNumber) { try { int i; login lg = new login(); start: if (login.v_cookieCollection == null) { if (!lg.fnc_login()) { //cannot login return; } } Uri uri; Model.rwmmsVehicleOwner entry_company; uri = new Uri(this.v_url); string postData; string introductionFilePath; 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 (System.Net.Cookie cookie in login.v_cookieCollection) { webRequest.CookieContainer.Add(cookie); } postData = "__EVENTTARGET=" + "&__EVENTARGUMENT=" + "&__VIEWSTATE=19gB2KPXunfoY1KhdzKAuxbd%2FOoFmZ3EhsltmoK2s2VkBDy6lwwZr7rC25jXm%2BQIJEpBZnx2gjOlf8C0mpGh%2FkEaSfPTf9k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Q3Gbweb%2FjyluhnUg%2Bf%2Fqr%2B00ktLcMIzKZICWoaPt3KT1bGaoQO3IjbC%2Ftb1pryMwgK8uyP81SN0Ysc8baiEvwM%2FeNZlA9jwr8o4TILSN7YE6On%2BfzKH4p8fLT7NeWOtG5%2BpgORP7isVvm1RHrvXXoxIfkXn7lsvW3QdvxdCBnnYWMN%2FE3GOcLnEoirJt%2BS31cn0uRPIpApDODga1Jig2%2B8lx7GdUlucWMxmOrXFzU1pBBLn8QKYIDxgn7UgSySyyfWVNthiZokkEsWsZyONzDg%2Fr9OD563xqw9hkHuLb1ba4y4eL9XzcnguO2XAZgNteGjDB62iXHdaO8evAuHazGDGcqbdhz2H1dMen1n%2B31%2B57NXNLGSsOZoQf3aI14g3nA9%2FZ6ch2UDu2yD8vURW7HnihCH6XfzWwgz89z4W0bvdyW0AipjMV%2BbZYvHjsRXo8ewuRvvnPeTKaupWsPFJXZsZs7H2Qi92pFFkr%2BGeFDWaHnQ50Vm3KAHn2Fl7HX6Ch9sgw57SUz4jDowNyaSYZBx3vKB%2BLmy1DY%2B8iueprOqM0mbn9Zpgfh23%2BvFR3%2FBaqrDUx9xk34l4Bt7RJPvAzvmLsesA8aGrwT7npF2N0bTN4y5uOQpQWX3BpbhNJi1VuM%2F7PlN5apaEXnSQUVUrwnZKd3bw5h4eF0BLUYlli1XmK%2BdCj3MwSsWF%2Fl9YS03wCvKvU2oeWyv%2Fyd49t7BJupZWp1YyXb6OpUb9HQxeHb7xg6YNHDuiMkJYmsLQB0IZMp%2FUYM%2BoBpl2wbq1AvK4c0Q1KEaMK" + "&ctl00%24ContentPlaceHolder1%24txtRegisterDate=" + "&ctl00%24ContentPlaceHolder1%24txtRegisterNumber=" + "&ctl00%24ContentPlaceHolder1%24txtNationalCode=" + "&ctl00%24ContentPlaceHolder1%24txtRegisterLocation=" + "&ctl00%24ContentPlaceHolder1%24btnSearch=%D8%AC%D8%B3%D8%AA%D8%AC%D9%88"; 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(); return; } 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(); return; } } string result; using (StreamReader rd = new StreamReader(webResponse.GetResponseStream(), Encoding.GetEncoding("utf-8"))) { result = rd.ReadToEnd(); } webResponse.Close(); if (!string.IsNullOrEmpty(result)) { this.v_dt.Rows.Clear(); Functions.sb_fillDatatableWithHtmlTableId(result, "ContentPlaceHolder1_dgVehicleOwners", 1, 1, 0, 0, this.v_dt); for (i = 0; i <= this.v_dt.Rows.Count - 1; i++) { introductionFilePath = null; this.sb_saveToDB(this.v_dt, cycleNumber, introductionFilePath, out entry_company); if (getIntroductionFiles && entry_company != null) { introductionFilePath = this.fnc_getIntroductionFile(entry_company.Id, entry_company.wCompanyName, i); entry_company.wIntroductionFile = introductionFilePath; using (var entityLogistic = new Model.logisticEntities()) { entityLogistic.Entry(entry_company).State = System.Data.Entity.EntityState.Modified; entityLogistic.SaveChanges(); } } if (getOwners && entry_company != null) { this.sb_readOwnerDetail(entry_company.Id, cycleNumber); //this.readAndSaveOwnerDetailToDB(entry_company.Id, cycleNumber); } } } } } catch (Exception ex) { } }
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); } } }
private void sb_saveToDB(declerationListDataTable dt, int cycleNumber, int pageIndex, string ownerName, string typeName , bool getDetail, bool getAttachment) { if (dt == null) { return; } int i; bool add; long wagonNo; Model.rwmmsDeclerationList entry_declerationList; using (var entityLogistic = new Model.logisticEntities()) { for (i = 0; i <= dt.Rows.Count - 1; i++) { add = false; if (!Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_wagonNo])) { wagonNo = long.Parse(dt.Rows[i][declerationListDataTable.fld_wagonNo].ToString()); entry_declerationList = entityLogistic.rwmmsDeclerationLists.FirstOrDefault(o => o.wWagonNo == wagonNo && o.wOwnerName == ownerName && o.wTypeName == typeName); if (entry_declerationList == null) { add = true; entry_declerationList = new Model.rwmmsDeclerationList(); } } else { entry_declerationList = new Model.rwmmsDeclerationList(); add = true; } entry_declerationList.CycleNumber = cycleNumber; entry_declerationList.FetchTime = DateTime.Now; entry_declerationList.PageIndex = pageIndex; entry_declerationList.Source = this.v_url; entry_declerationList.vehicleOwnerId = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_ownerName]) ? null : vehicleOwners.Fnc_getVehicleOwnerId(dt.Rows[i][declerationListDataTable.fld_ownerName].ToString()); entry_declerationList.wDeclerationNo = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_declerationNo]) ? null : dt.Rows[i][declerationListDataTable.fld_declerationNo].ToString(); entry_declerationList.wOwnerName = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_ownerName]) ? null : dt.Rows[i][declerationListDataTable.fld_ownerName].ToString(); entry_declerationList.wOwnerRepresentativeName = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_ownerRepresentativeName]) ? null : dt.Rows[i][declerationListDataTable.fld_ownerRepresentativeName].ToString(); entry_declerationList.wRowNo = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_rowNo]) ? null : (int?)int.Parse(dt.Rows[i][declerationListDataTable.fld_rowNo].ToString()); entry_declerationList.wStatus = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_status]) ? null : dt.Rows[i][declerationListDataTable.fld_status].ToString(); entry_declerationList.wWagonNo = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_wagonNo]) ? null : (long?)long.Parse(dt.Rows[i][declerationListDataTable.fld_wagonNo].ToString()); entry_declerationList.wTypeName = Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_typeName]) ? null : dt.Rows[i][declerationListDataTable.fld_typeName].ToString(); if (getDetail) { entry_declerationList.issueDate = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_issueDate]) ? null : (DateTime?)Functions.solarToMiladi(dt.Rows[i][declerationListDataTable.fld_issueDate].ToString())); entry_declerationList.wConfirmEdareBazargani = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmEdareBazargani]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmEdareBazargani])); entry_declerationList.wConfirmEdareBazarganiDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmEdareBazargani]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmEdareBazarganiDescription].ToString()); entry_declerationList.wConfirmEdareSeir = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmEdareSeir]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmEdareSeir])); entry_declerationList.wConfirmEdareSeirDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmEdareSeirDescription]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmEdareSeirDescription].ToString()); entry_declerationList.wConfirmEdareWagon = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmEdareWagon]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmEdareWagon])); entry_declerationList.wConfirmEdareWagonDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmEdareWagonDescription]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmEdareWagonDescription].ToString()); entry_declerationList.wConfirmFinal = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmFinal]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmFinal])); entry_declerationList.wConfirmFinalDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmFinalDescription]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmFinalDescription].ToString()); entry_declerationList.wConfirmHoghoghi = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmHoghoghi]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmHoghoghi])); entry_declerationList.wConfirmHoghoghiDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmHoghoghi]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmHoghoghiDescription].ToString()); entry_declerationList.wConfirmMali = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmMali]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmMali])); entry_declerationList.wConfirmMaliDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmMaliDescription]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmMaliDescription].ToString()); entry_declerationList.wConfirmOwner = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmOwner]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmOwner])); entry_declerationList.wConfirmOwnerDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmOwnerDescription]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmOwnerDescription].ToString()); entry_declerationList.wConfirmSarmaye = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmSarmaye]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmSarmaye])); entry_declerationList.wConfirmSarmayeDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmSarmayeDescription]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmSarmayeDescription].ToString()); entry_declerationList.wConfirmTajhiz = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmTajhiz]) ? null : (bool?)(dt.Rows[i][declerationListDataTable.fld_confirmTajhiz])); entry_declerationList.wConfirmTajhizDescription = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_confirmTajhizDescription]) ? null : dt.Rows[i][declerationListDataTable.fld_confirmTajhizDescription].ToString()); entry_declerationList.wIssueDate = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_issueDate]) ? null : dt.Rows[i][declerationListDataTable.fld_issueDate].ToString()); entry_declerationList.wNoteNo = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_noteNo]) ? null : dt.Rows[i][declerationListDataTable.fld_noteNo].ToString()); entry_declerationList.wOtherRights = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_otherRights]) ? null : dt.Rows[i][declerationListDataTable.fld_otherRights].ToString()); entry_declerationList.wOwnerDocuments = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_ownerDocuments]) ? null : dt.Rows[i][declerationListDataTable.fld_ownerDocuments].ToString()); entry_declerationList.wPageNo = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_pageNo]) ? null : dt.Rows[i][declerationListDataTable.fld_pageNo].ToString()); entry_declerationList.wRegisterNo = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_registerNo]) ? null : dt.Rows[i][declerationListDataTable.fld_registerNo].ToString()); } if (getAttachment) { entry_declerationList.wAttachmentPath = (Functions.IsNull(dt.Rows[i][declerationListDataTable.fld_attachmentPath]) ? null : dt.Rows[i][declerationListDataTable.fld_attachmentPath].ToString()); } if (add) { entityLogistic.rwmmsDeclerationLists.Add(entry_declerationList); } else { entityLogistic.Entry(entry_declerationList).State = System.Data.Entity.EntityState.Modified; } entityLogistic.SaveChanges(); PWS0.trainBarryWagons.fnc_saveWagonFromRWMMS(dt, i); } } }
private void sb_saveToDB(trainBarryJsonModel train, int cycleNumber, bool getLocomotives, bool getBillOfLadings) { trainBarryBillOfLadings billOfLadings = new trainBarryBillOfLadings(); trainBarryLocomotives locos = new trainBarryLocomotives(); using (var entityLogistic = new Model.logisticEntities()) { bool add = false; Model.PWS0TrainsBarry entryPWS0Train = entityLogistic.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 Model.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) { entityLogistic.PWS0TrainsBarry.Add(entryPWS0Train); } entityLogistic.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) { } } }
public void sb_saveToDB() { using (var entityLogistic = new Model.logisticEntities()) { bool add = false; Model.PWS0Stations entryPWS0Station = entityLogistic.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 Model.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) { entityLogistic.PWS0Stations.Add(entryPWS0Station); } entityLogistic.SaveChanges(); //to get id of stationid int StationId = entryPWS0Station.Id; add = false; Model.PWS0StationsGeos entryPWS0StationsGeos = entityLogistic.PWS0StationsGeos.FirstOrDefault(o => o.StationId == StationId && o.id == this.id); if (entryPWS0StationsGeos == null) { entryPWS0StationsGeos = new Model.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) { entityLogistic.PWS0StationsGeos.Add(entryPWS0StationsGeos); } entityLogistic.SaveChanges(); } }
private void sb_saveToDB(DataTable dt, int cycleNumber) { if (dt == null) { return; } int i; string solarDate; int? solarTime; DateTime?enteranceDateTime; Model.raiTrainPassengersLastStatu entry_raiTrainPassengersLastStatus; using (var entityLogistic = new Model.logisticEntities()) { for (i = 0; i <= dt.Rows.Count - 1; i++) { entry_raiTrainPassengersLastStatus = new Model.raiTrainPassengersLastStatu(); entry_raiTrainPassengersLastStatus.areaId = (Functions.IsNull(dt.Rows[i][trainPassengersLastStatusDataTable.fld_areaName]) ? null : PWS0.areas.fnc_getAreaId(dt.Rows[i][trainPassengersLastStatusDataTable.fld_areaName].ToString(), false, true)); entry_raiTrainPassengersLastStatus.currentStationId = (Functions.IsNull(dt.Rows[i][trainPassengersLastStatusDataTable.fld_currentStationName]) ? null : PWS0.stations.fnc_getStationId(null, dt.Rows[i][trainPassengersLastStatusDataTable.fld_currentStationName].ToString(), true)); entry_raiTrainPassengersLastStatus.CycleNumber = cycleNumber; entry_raiTrainPassengersLastStatus.destinationStationId = (Functions.IsNull(dt.Rows[i][trainPassengersLastStatusDataTable.fld_destinationStationName]) ? null : PWS0.stations.fnc_getStationId(null, dt.Rows[i][trainPassengersLastStatusDataTable.fld_destinationStationName].ToString(), true)); #region enteranceDate solarDate = null; solarTime = null; if (!Functions.IsNull(dt.Rows[i][trainPassengersLastStatusDataTable.fld_enteranceDate])) { var solarDateTime = dt.Rows[i][trainPassengersLastStatusDataTable.fld_enteranceDate].ToString(); if (solarDateTime.Length == 13) { solarTime = int.Parse(solarDateTime.Substring(8, 5).Replace(":", "")); var solarDateArr = solarDateTime.Substring(0, 8).Split('/'); Array.Reverse(solarDateArr); solarDate = string.Join("", solarDateArr); solarDate = solarDate.Replace("/", ""); } } entry_raiTrainPassengersLastStatus.enteranceDateTime = enteranceDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(solarDate, solarTime);; #endregion #region exitDate solarDate = null; solarTime = null; if (!Functions.IsNull(dt.Rows[i][trainPassengersLastStatusDataTable.fld_exitDate])) { var solarDateTime = dt.Rows[i][trainPassengersLastStatusDataTable.fld_exitDate].ToString(); if (solarDateTime.Length == 13) { solarTime = int.Parse(solarDateTime.Substring(8, 5).Replace(":", "")); var solarDateArr = solarDateTime.Substring(0, 8).Split('/'); Array.Reverse(solarDateArr); solarDate = string.Join("", solarDateArr); solarDate = solarDate.Replace("/", ""); } } entry_raiTrainPassengersLastStatus.exitDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(solarDate, solarTime);; #endregion entry_raiTrainPassengersLastStatus.FetchTime = DateTime.Now; entry_raiTrainPassengersLastStatus.sourceStationId = (Functions.IsNull(dt.Rows[i][trainPassengersLastStatusDataTable.fld_sourceStationName]) ? null : PWS0.stations.fnc_getStationId(null, dt.Rows[i][trainPassengersLastStatusDataTable.fld_sourceStationName].ToString(), true)); entry_raiTrainPassengersLastStatus.trainId = (Functions.IsNull(dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainNo]) ? null : PWS0.trainBarry.fnc_getTrainIdFromDB(int.Parse(dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainNo].ToString()), enteranceDateTime)); entry_raiTrainPassengersLastStatus.wAreaName = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_areaName]) ? null : this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_areaName].ToString()); entry_raiTrainPassengersLastStatus.wCurrentStationName = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_currentStationName]) ? null : this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_currentStationName].ToString()); entry_raiTrainPassengersLastStatus.wDestinationStationName = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_destinationStationName]) ? null : this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_destinationStationName].ToString()); entry_raiTrainPassengersLastStatus.wEnteranceDateTime = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_enteranceDate]) ? null : this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_enteranceDate].ToString()); entry_raiTrainPassengersLastStatus.wExitDateTime = null; entry_raiTrainPassengersLastStatus.wRowNo = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_rowNo]) ? null : (int?)int.Parse(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_rowNo].ToString())); entry_raiTrainPassengersLastStatus.wSourceStationName = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_sourceStationName]) ? null : this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_sourceStationName].ToString()); entry_raiTrainPassengersLastStatus.wTrainBossName = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainBossName]) ? null : this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainBossName].ToString()); entry_raiTrainPassengersLastStatus.wTrainNo = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainNo]) ? null : (int?)int.Parse(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainNo].ToString())); entry_raiTrainPassengersLastStatus.wTrainType = (Functions.IsNull(this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainType]) ? null : this.v_dt.Rows[i][trainPassengersLastStatusDataTable.fld_trainType].ToString()); entityLogistic.raiTrainPassengersLastStatus.Add(entry_raiTrainPassengersLastStatus); entityLogistic.SaveChanges(); } } }
private void sb_savePartsToDB(wagonPartsDataTable dt, int?idGroup) { if (dt == null) { return; } int i; bool add; string partName; Model.rwmmsWagonPart entry_wagonParts; using (var entityLogistic = new Model.logisticEntities()) { for (i = 0; i <= dt.Rows.Count - 1; i++) { add = false; if (!Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_partName]) && idGroup.HasValue) { partName = dt.Rows[i][wagonPartsDataTable.fld_partName].ToString(); entry_wagonParts = entityLogistic.rwmmsWagonParts.FirstOrDefault(o => o.IdGroup == idGroup && o.wPartName == partName); if (entry_wagonParts == null) { add = true; entry_wagonParts = new Model.rwmmsWagonPart(); } } else { entry_wagonParts = new Model.rwmmsWagonPart(); } entry_wagonParts.FetchTime = DateTime.Now; entry_wagonParts.IdGroup = idGroup; entry_wagonParts.wCountInGroup = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_countInGroup]) ? null : (int?)int.Parse(dt.Rows[i][wagonPartsDataTable.fld_countInGroup].ToString()); entry_wagonParts.wCountInWagon = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_countInWagon]) ? null : (int?)int.Parse(dt.Rows[i][wagonPartsDataTable.fld_countInWagon].ToString()); entry_wagonParts.wMapNumber = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_mapNumber]) ? null : dt.Rows[i][wagonPartsDataTable.fld_mapNumber].ToString(); entry_wagonParts.wMapPic1Path = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_mapPic1Path]) ? null : dt.Rows[i][wagonPartsDataTable.fld_mapPic1Path].ToString(); entry_wagonParts.wMapPic2Path = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_mapPic2Path]) ? null : dt.Rows[i][wagonPartsDataTable.fld_mapPic2Path].ToString(); entry_wagonParts.wMapPic3Path = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_mapPic3Path]) ? null : dt.Rows[i][wagonPartsDataTable.fld_mapPic3Path].ToString(); entry_wagonParts.wMapPic4Path = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_mapPic4Path]) ? null : dt.Rows[i][wagonPartsDataTable.fld_mapPic4Path].ToString(); entry_wagonParts.wMapPicPath = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_mapPicPath]) ? null : dt.Rows[i][wagonPartsDataTable.fld_mapPicPath].ToString(); entry_wagonParts.wPartName = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_partName]) ? null : dt.Rows[i][wagonPartsDataTable.fld_partName].ToString(); entry_wagonParts.wPartNameLatin = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_partNameLatin]) ? null : dt.Rows[i][wagonPartsDataTable.fld_partNameLatin].ToString(); entry_wagonParts.wWeight = Functions.IsNull(dt.Rows[i][wagonPartsDataTable.fld_weight]) ? null : (decimal?)decimal.Parse(dt.Rows[i][wagonPartsDataTable.fld_weight].ToString()); if (add) { entityLogistic.rwmmsWagonParts.Add(entry_wagonParts); } else { entityLogistic.Entry(entry_wagonParts).State = System.Data.Entity.EntityState.Modified; } try { entityLogistic.SaveChanges(); } catch (Exception ex) { } } } }
private void sb_saveToDB(trainPassengerJsonModel jmodel, int cycleNumber) { using (var entityLogistic = new Model.logisticEntities()) { bool add = false; Model.PWS0TrainsPassengers entryPWS0TrainPassenger = entityLogistic.PWS0TrainsPassengers.FirstOrDefault( o => o.jTrain_No == jmodel.Train_No && o.jCurrent_Station_Code == jmodel.Current_Station_Code //&& o.jEntrance_Date == this.Entrance_Date //&& o.jEntrance_Time == this.Entrance_Time //&& o.jExit_Date == this.Exit_Date //&& o.jExit_Time == this.Exit_Time && o.jDeparture_Date == jmodel.Departure_Date && o.jDeparture_Time == jmodel.Departure_Time && o.jSource_Station_Code == jmodel.Source_Station_Code && o.jDestination_Station_Code == jmodel.Destination_Station_Code //&& o.jDestination_Program_Time_In == this.Destination_Program_Time_In //&& o.jCurrent_Program_Time_In == this.Current_Program_Time_In //&& o.jDeparture_Program_Time_Out == this.Departure_Program_Time_Out //&& o.jUpdate_DateTime == this.Update_DateTime //&& o.jDelayMinute == this.DelayMinute //&& o.jArivalHours == this.ArivalHours ); if (entryPWS0TrainPassenger == null) { add = true; entryPWS0TrainPassenger = new Model.PWS0TrainsPassengers(); } try { entryPWS0TrainPassenger.CurrentProgramTimeIn = string.IsNullOrEmpty(jmodel.Current_Program_Time_In) ? null : Functions.fnc_convertTimeLongToTimespan(int.Parse(jmodel.Current_Program_Time_In)); entryPWS0TrainPassenger.CurrentStationId = stations.fnc_getStationId(jmodel.Current_Station_Code, null, true); entryPWS0TrainPassenger.DepartureDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(jmodel.Departure_Date, string.IsNullOrEmpty(jmodel.Departure_Time) ? null : (int?)int.Parse(jmodel.Departure_Time)); entryPWS0TrainPassenger.DepartureProgramTimeOut = string.IsNullOrEmpty(jmodel.Departure_Program_Time_Out) ? null : Functions.fnc_convertTimeLongToTimespan(int.Parse(jmodel.Departure_Program_Time_Out)); entryPWS0TrainPassenger.DestinationProgramTimeIn = string.IsNullOrEmpty(jmodel.Destination_Program_Time_In) ? null : Functions.fnc_convertTimeLongToTimespan(int.Parse(jmodel.Destination_Program_Time_In)); entryPWS0TrainPassenger.DestinationStationId = stations.fnc_getStationId(jmodel.Destination_Station_Code, null, true); entryPWS0TrainPassenger.EntranceDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(jmodel.Departure_Date, string.IsNullOrEmpty(jmodel.Entrance_Date) ? null : (int?)int.Parse(jmodel.Entrance_Time)); entryPWS0TrainPassenger.ExitDateTime = Functions.fnc_convertSolarDateAndTimeToDateTime(jmodel.Exit_Date, string.IsNullOrEmpty(jmodel.Exit_Time) ? null : (int?)int.Parse(jmodel.Exit_Time)); entryPWS0TrainPassenger.jArivalHours = jmodel.ArivalHours; entryPWS0TrainPassenger.jCurrent_Program_Time_In = jmodel.Current_Program_Time_In; entryPWS0TrainPassenger.jCurrent_Station_Code = jmodel.Current_Station_Code; entryPWS0TrainPassenger.jDelayMinute = jmodel.DelayMinute; entryPWS0TrainPassenger.jDeparture_Date = jmodel.Departure_Date; entryPWS0TrainPassenger.jDeparture_Program_Time_Out = jmodel.Departure_Program_Time_Out; entryPWS0TrainPassenger.jDeparture_Time = jmodel.Departure_Time; entryPWS0TrainPassenger.jDestination_Program_Time_In = jmodel.Destination_Program_Time_In; entryPWS0TrainPassenger.jDestination_Station_Code = jmodel.Destination_Station_Code; entryPWS0TrainPassenger.jEntrance_Date = jmodel.Entrance_Date; entryPWS0TrainPassenger.jEntrance_Time = jmodel.Entrance_Time; entryPWS0TrainPassenger.jExit_Date = jmodel.Exit_Date; entryPWS0TrainPassenger.jExit_Time = jmodel.Exit_Time; entryPWS0TrainPassenger.jSource_Station_Code = jmodel.Source_Station_Code; entryPWS0TrainPassenger.jTrain_No = jmodel.Train_No; entryPWS0TrainPassenger.jUpdate_DateTime = jmodel.Update_DateTime; entryPWS0TrainPassenger.SourceStationId = stations.fnc_getStationId(jmodel.Source_Station_Code, null, true); entryPWS0TrainPassenger.FetchTime = DateTime.Now; entryPWS0TrainPassenger.CycleNumber = cycleNumber; if (add) { entityLogistic.PWS0TrainsPassengers.Add(entryPWS0TrainPassenger); } entityLogistic.SaveChanges(); } catch (Exception ex) { } } }
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; } } } } } }
private void sb_readOwnerDetail(int companyId, int cycleNumber) { login lg = new login(); lg.fnc_loginWithSelenium(this.v_webBrowser); bool add; string tableId = "ContentPlaceHolder1_dgVehicleOwners"; this.v_webBrowser.Navigate().GoToUrl(this.v_url); SharedFunctions.sb_waitForReady(this.v_webBrowser); var btnSearch = this.v_webBrowser.FindElement(By.Id("ContentPlaceHolder1_btnSearch")); if (btnSearch == null) { return; } btnSearch.Click(); SharedFunctions.sb_waitForReady(this.v_webBrowser); var table = this.v_webBrowser.FindElement(By.Id(tableId)); if (table == null) { return; } var rows = table.FindElements(By.TagName("tr")); if (rows == null || rows.Count < 3) { return; } var columns = rows[1].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); table = this.v_webBrowser.FindElement(By.Id("ContentPlaceHolder1_dgVehicleOwnerDetails")); if (table == null) { return; } rows = table.FindElements(By.TagName("tr")); if (rows == null || rows.Count < 3) { return; } columns = rows[1].FindElements(By.TagName("td")); if (columns.Count >= 6) { href = columns[6].FindElement(By.TagName("a")); if (href != null) { href.Click(); //SharedFunctions.sb_waitForReady(this.v_webBrowser); SharedFunctions.sb_waitForReady(this.v_webBrowser); string 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"); using (var entityLogistic = new Model.logisticEntities()) { if (!string.IsNullOrEmpty(meliNo)) { add = false; var entryOwnerExtraDetail = entityLogistic.rwmmsVehicleOwnersDetails.FirstOrDefault(o => o.wMeliNo == meliNo); if (entryOwnerExtraDetail == null) { entryOwnerExtraDetail = new Model.rwmmsVehicleOwnersDetail(); add = true; } entryOwnerExtraDetail.CycleNumber = cycleNumber; entryOwnerExtraDetail.FetchTime = DateTime.Now; entryOwnerExtraDetail.Source = this.v_url; entryOwnerExtraDetail.vehicleOwnerId = companyId; 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); if (add) { entityLogistic.rwmmsVehicleOwnersDetails.Add(entryOwnerExtraDetail); } else { entityLogistic.Entry(entryOwnerExtraDetail).State = System.Data.Entity.EntityState.Modified; } entityLogistic.SaveChanges(); } } } } } } }
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(); } } }
public void sb_saveToDB() { using (var entityLogistic = new Model.logisticEntities()) { bool add = false; Model.PWS0Agencies entryPWS0Agency = entityLogistic.PWS0Agencies.FirstOrDefault(o => o.AgencyCode == this.properties.AgencyCode && o.AgencyName == this.properties.AgencyName && o.CountryCode == this.properties.CountryCode && o.ProvinceCode == this.properties.ProvinceCode && o.cityCode == this.properties.cityCode); if (entryPWS0Agency == null) { add = true; entryPWS0Agency = new Model.PWS0Agencies(); } entryPWS0Agency.AgencyCode = this.properties.AgencyCode; entryPWS0Agency.AgencyName = this.properties.AgencyName; entryPWS0Agency.AgencyStreet = this.properties.AgencyStreet; entryPWS0Agency.AgencyTel = this.properties.AgencyTel; entryPWS0Agency.cityCode = this.properties.cityCode; entryPWS0Agency.cityName = this.properties.cityName; entryPWS0Agency.CountryCode = this.properties.CountryCode; entryPWS0Agency.CountryName = this.properties.CountryName; entryPWS0Agency.Lat = this.properties.Lat; entryPWS0Agency.Lng = this.properties.Lng; entryPWS0Agency.ProvinceCode = this.properties.ProvinceCode; entryPWS0Agency.provinceName = this.properties.provinceName; entryPWS0Agency.FetchTime = DateTime.Now; if (add) { entityLogistic.PWS0Agencies.Add(entryPWS0Agency); } entityLogistic.SaveChanges(); //to get id of stationid int AgencyId = entryPWS0Agency.Id; add = false; Model.PWS0AgenciesGeos entryPWS0AgenciesGeos = entityLogistic.PWS0AgenciesGeos.FirstOrDefault(o => o.AgencyId == AgencyId && o.id == this.id); if (entryPWS0AgenciesGeos == null) { entryPWS0AgenciesGeos = new Model.PWS0AgenciesGeos(); add = true; } entryPWS0AgenciesGeos.id = this.id; entryPWS0AgenciesGeos.geometry_name = this.geometry_name; if (this.geometry != null) { entryPWS0AgenciesGeos.geometryType = this.geometry.type; if (this.geometry.coordinates != null) { entryPWS0AgenciesGeos.geometryCoordinates = string.Join(",", this.geometry.coordinates.ToArray()); } } entryPWS0AgenciesGeos.AgencyId = AgencyId; entryPWS0AgenciesGeos.type = this.type; if (add) { entityLogistic.PWS0AgenciesGeos.Add(entryPWS0AgenciesGeos); } entityLogistic.SaveChanges(); } }