Dictionary stopping at loadingfromscreen - c#

I run the code and it will not store the values it stops immediately at the loadingfromscreen. What its supposed to do is a multi-page application form that will reinput the values to the texbox's on the back button from the next form.
The ASP.net code is too long to post, but basically its just texbox's and dropboxes. If needed i can post it, but the main issue im 90% sure is the C# code.
UPDATE: When i say stop it continues the code but will not run the dictionary method...i have put a arrow where the method stops in DICTIONARY ONLY
C#:
public partial class employment_driversapplication_personalinfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Dictionary<string, string> DriversApplicationData = (Dictionary<string, string>) Session["DriversApp"];
try
{
if (Page.IsPostBack)
{
LoadMemoryFromScreen(DriversApplicationData);
}
else
{
LoadScreenFromMemory(DriversApplicationData);
}
}
catch //(Exception ex)
{
// throw new Exception("Exception occured in employment_driversapplication_personalinfo.aspx - Page_Load" + ex.Message);
}
finally
{
}
}
private void LoadMemoryFromScreen(Dictionary<string, string> DicDriversApp)
{
DicDriversApp["position"] = position.Text; <---Stops here (won't even store this)
DicDriversApp["fname"] = fname.Text;
DicDriversApp["middleinitial"] = middleinitial.Text;
DicDriversApp["lname"] = lname.Text;
DicDriversApp["birthday"] = birthday.Text;
DicDriversApp["proofofage"] = proofofage.SelectedValue;
DicDriversApp["address"] = address.Text;
DicDriversApp["city"] = city.Text;
DicDriversApp["state"] = state.Text;
DicDriversApp["email"] = email.Text;
DicDriversApp["phone"] = phone.Text;
DicDriversApp["altphone"] = altphone.Text;
DicDriversApp["citizen"] = citizen.SelectedValue;
DicDriversApp["whoreferred"] = whoreferred.Text;
DicDriversApp["famfriend"] = famfriend.Text;
DicDriversApp["relationship"] = relationship.Text;
DicDriversApp["rateofpayexpected"] = rateofpayexpected.Text;
DicDriversApp["rateofpaytype"] = RadioButtonList1.SelectedValue;
DicDriversApp["employedNow"] = employednow.SelectedValue;
DicDriversApp["curremployment"] = curremployment.Text;
DicDriversApp["pastAddress"] = pastaddress.SelectedValue;
DicDriversApp["previousAddress"] = previousaddress.Text;
DicDriversApp["previousCity"] = previouscity.Text;
DicDriversApp["previousZip"] = previouszip.Text;
DicDriversApp["previousState"] = previousstate.Text;
DicDriversApp["previousDuration"] = previousduration.Text;
DicDriversApp["previousAddress1"] = previousaddress1.Text;
DicDriversApp["previousCity1"] = previouscity1.Text;
DicDriversApp["previousZip1"] = previouszip1.Text;
DicDriversApp["previousState1"] = previousstate1.Text;
DicDriversApp["previousDuration1"] = previousduration1.Text;
Session["DriversApp"] = DicDriversApp;
}
private void LoadScreenFromMemory(Dictionary<string, string> DicDriversApp)
{
position.Text = DicDriversApp["position"];
fname.Text = DicDriversApp["fname"] ;
middleinitial.Text = DicDriversApp["middleinitial"];
lname.Text = DicDriversApp["lname"];
birthday.Text = DicDriversApp["birthday"];
proofofage.SelectedValue = DicDriversApp["proofofage"];
address.Text = DicDriversApp["address"];
city.Text = DicDriversApp["city"];
state.Text = DicDriversApp["state"];
email.Text = DicDriversApp["email"];
phone.Text = DicDriversApp["phone"];
altphone.Text = DicDriversApp["altphone"];
citizen.SelectedValue = DicDriversApp["citizen"];
whoreferred.Text = DicDriversApp["whoreferred"];
famfriend.Text = DicDriversApp["famfriend"];
relationship.Text = DicDriversApp["relationship"];
rateofpayexpected.Text = DicDriversApp["rateofpayexpected"];
RadioButtonList1.SelectedValue = DicDriversApp["rateofpaytype"];
employednow.SelectedValue = DicDriversApp["employedNow"];
curremployment.Text = DicDriversApp["curremployment"];
pastaddress.SelectedValue = DicDriversApp["pastAddress"];
previousaddress.Text = DicDriversApp["previousAddress"];
previouscity.Text = DicDriversApp["previousCity"];
previouszip.Text = DicDriversApp["previousZip"];
previousstate.Text = DicDriversApp["previousState"];
previousduration.Text = DicDriversApp["previousDuration"];
previousaddress1.Text = DicDriversApp["previousAddress1"];
previouscity1.Text = DicDriversApp["previousCity1"];
previouszip1.Text = DicDriversApp["previousZip1"];
previousstate1.Text = DicDriversApp["previousState1"];
previousduration1.Text = DicDriversApp["previousDuration1"];
}

try something like this:
private void LoadMemoryFromScreen()
{
Dictionary<string, string> driver = new Dictionary<string, string>();
driver.Add("position", position.Text);
driver.Add("othervalue",value.Text); ///etc..
Session["dict"] = driver;
}
then, later on if you want to access the values in your dictionary, use something like this:
var dict = (Dictionary<string, string>)Session["dict"];
problem with this is that you're going to have to use dict.GetElementAt(index) in order to retrieve values, and i don't think that's a very good approach.
This will work, but i kinda dont understand why you are using a dictionary to do this. I assume you are only loading data from 1 person on your page? Then you might as well just make a class with all the properties in it, and then you can just pass that around instead of using this dictionary/session hack.
public class DriversApplicationData
{
public string position {get;set;}
public string firstname {get;set;}
//etc
}
then, you can just do something like
DriversApplicationData data = new DriversApplicationData();
data.position = position.Text;
data.firstname = fname.Text;
this is gonna be alot easier to maintain and to retrieve/insert values.

Related

How to get CustomProperties displayed in RoomInfo | Unity + PUN2

I am setting a CustomRoomProperties when a new game is started. Here:
public void startGame()
{
RoomOptions options = new RoomOptions();
options.CleanupCacheOnLeave = true;
options.MaxPlayers = 8;
options.IsOpen = true;
options.IsVisible = true;
Hashtable RoomCustomProps = new Hashtable();
RoomCustomProps.Add("availablePods", gameLenghtsIs);
options.CustomRoomProperties = RoomCustomProps;
PhotonNetwork.JoinOrCreateRoom(createInput.text, options, TypedLobby.Default);
}
And this is the RoomInfo displayed in the Lobby once a game is created:
public void SetRoomInfo(RoomInfo roomInfo)
{
RoomInfo = roomInfo;
maxPlayetTxt.text = roomInfo.MaxPlayers + ",";
nameRoomText.text = roomInfo.Name + ",";
payerNumberText.text = roomInfo.PlayerCount+ "/8";
}
To this RoomInfo i would want to add the created Custom Property but not really sure how. I tried:
podsTxt.text = roomInfo.CustomProperties["availablePods"] + ",";
This resulted in nothingness.
And i tried this:
podsTxt.text = roomInfo.CustomProperties["availablePods"].GetHashCode() + ",";
Resulted in a error.
Tried a few other things but can't get it to work.
P.S. I am using the Hashtable and the hastable does what it's sopposto to do. I would just want this value that i set at startGame()
"availablePods"
to bi displayed when getting the room list in the lobby.
Anyone can help?
If this help anybody, this is what wroked for me:
public void startGame()
{
RoomOptions options = new RoomOptions();
options.CleanupCacheOnLeave = true;
options.MaxPlayers = 8;
options.IsOpen = true;
options.IsVisible = true;
Hashtable RoomCustomProps = new Hashtable();
RoomCustomProps.Add("availablePods", gameLenghtsIs);
options.CustomRoomProperties = RoomCustomProps;
options.CustomRoomProperties.Add("availablePods", allPods);
options.CustomRoomPropertiesForLobby = new string[1] { "availablePods" };
PhotonNetwork.JoinOrCreateRoom(createInput.text, options, TypedLobby.Default);
}
Room Info:
public void SetRoomInfo(RoomInfo roomInfo)
{
RoomInfo = roomInfo;
maxPlayetTxt.text = roomInfo.MaxPlayers + ",";
nameRoomText.text = roomInfo.Name + ",";
payerNumberText.text = roomInfo.PlayerCount+ "/8";
podsTxt.text = roomInfo.CustomProperties["availablePods"].ToString();
}
Thanks to hijinxbassist, i got this working.

how to return an object in c#?

I'm filling data inside an object with c# but I don't know how to return this object.
I create an object named ArasOrder and fill in the data and I want to return the ArasOrder object.
how can I do this.
public class ArasDeneme
{
public static void aras()
{
var ArasService = new ArasTEST.Service();
var ArasGonderi = new ArasTEST.ShippingOrder();
var ArasOrder = new ArasTEST.Order();
var parametreler = ArasKargoTEST.ParametreGet();
var newentegrationcode = "";
foreach (var item in parametreler)
{
var encode = entegrationcode();
var YeniGelenDesi = DesiHesabi(item.WebSiparisNo);
var yeniteminyeri = item.TeminYeri;
newentegrationcode = 123+ "" + encode;
ArasOrder.UserName = "";
ArasOrder.Password = "";
ArasOrder.ReceiverName = item.KargoAdSoyad;
ArasOrder.ReceiverPhone1 = item.KargoTelefon;
ArasOrder.ReceiverCityName = item.KargoIlAdi;
ArasOrder.ReceiverTownName = item.KargoIlceAdi;
ArasOrder.ReceiverAddress = item.KargoAdres;
ArasOrder.TradingWaybillNumber = item.WebSiparisNo;
ArasOrder.PieceCount = "1";
ArasOrder.IntegrationCode = newentegrationcode;
ArasOrder.PayorTypeCode = "1";
ArasOrder.IsWorldWide = "0";
ArasOrder.IsCod = "0";
ArasOrder.VolumetricWeight = YeniGelenDesi;
ArasOrder.SenderAccountAddressId = "1071";
ArasTEST.PieceDetail[] ArasPieceDetails = new ArasTEST.PieceDetail[1];
PieceDetail ArasPieceDetail1 = new PieceDetail();
ArasPieceDetail1.BarcodeNumber = newentegrationcode;
ArasPieceDetail1.VolumetricWeight = YeniGelenDesi;
ArasPieceDetail1.Weight = "1";
ArasPieceDetail1.Description = "";
ArasPieceDetails[0] = ArasPieceDetail1;
ArasOrder.PieceDetails = ArasPieceDetails;
var ArasOrderInfo = new ArasTEST.Order[1];
ArasOrderInfo[0] = ArasOrder;
var takipNoResult = ArasService.SetOrder("", "", "");
var ArasOrderResultInfo = takipNoResult[0];
var SonucKodu = takipNoResult[0].ResultCode;
var SonucMesaji = takipNoResult[0].ResultMessage;
var SonucInvoiceKey = takipNoResult[0].InvoiceKey;
}
}
}
You should define the return type and return the instance.
public static ArasTEST aras()
{
// insert code here...
return ArasOrder;
}
Change void to ArasDeneme return type.
Then call like:
var ad = ArasDeneme.aras();

Load Windows form after complete combobox data load in c#

I have a form for employees called frmEmployees where I need to load couple of combo box with data like country, category, nationality, such others.
Now when user click on to open frmEmployees, window is stuck for bit and then open. I assume that this is because of data loading and initializing the combo box.
Now! what I want is, just after click on button to open frmEmployees run a progress bar till data loading complete and then open form.
public frmEmployee()
{
InitializeComponent();
con = new Connection();
LoadComboboxDS();
}
I have tried also
private void FrmEmployee_Load(object sender, EventArgs e)
{
LoadComboboxDS();
}
private void LoadComboboxDS()
{
//company
var _companies = con.Companies.Where(x => x.IsDeleted == false).ToList();
_companies.Insert(0,new data.Models.CompanyModels.Company { Address = new data.Models.Address(), Code = null, Name = "--Select--", BaseCurrency = new data.Models.Currency() });
cbCompany.DataSource = _companies;
cbCompany.DisplayMember = "Name";
cbCompany.ValueMember = "ID";
//gender
cbGender.DataSource = Enum.GetValues(typeof(Gender));
//merital status
cbMeritalStatus.DataSource = Enum.GetValues(typeof(MaritalStatus));
//citizenship
var _citizenships = con.Countries.Select(x => x.Citizenship).Distinct().ToList();
_citizenships.Insert(0, "--Select--");
cbCitizenship.DataSource = _citizenships;
cbCitizenship.DisplayMember = "Citizenship";
//nationality
var _nations = con.Countries.Select(x => x.Name).Distinct().ToList();
_nations.Insert(0, "--Select--");
cbNationality.DataSource = _nations;
cbNationality.DisplayMember = "Name";
//domicile
var _domiciles = con.Countries.Select(x => x.Name).Distinct().ToList();
_domiciles.Insert(0, "--Select--");
cbDomicile.DataSource = _domiciles;
cbDomicile.DisplayMember = "Name";
//cast category
var _casts = con.CastCategories.Select(x => new {x.ShortText, x.Description}).Distinct().ToList();
_casts.Insert(0, new { ShortText = "", Description = "--Select--" });
cbCategory.DataSource = _casts;
cbCategory.DisplayMember = "Description";
cbCategory.ValueMember = "ShortText";
//religion
cbReligion.DataSource = Enum.GetValues(typeof(Religion));
}
You can use Async extension methods of Entity Framework 6 to make your code asynchronous.
Separate your data access and presentation layer, at first:
public static class MyRepository // consider not static, just an example
{
public static async Task<List<Company>> GetCompanies()
{
using (var connection = new Connection()) // consider factory
{
return await con.Companies.Where(x => x.IsDeleted == false).ToListAsync();
}
}
public async Task<List<Citizenship>> GetCitizenships()
{
using (var connection = new Connection()) // factory?
{
return await con.Countries.Select(x => x.Citizenship).Distinct().ToList();
}
}
}
Then, you can run all these tasks at once and wait for them to complete:
// Wherever you are going to open frmEmployee
public async Task openFrmEmployee_OnClick(object sender, EventArgs e)
{
var getCompaniesTask = MyRepository.GetCompanies();
var getCitizenshipsTask = MyRepository.GetCitizenships();
await Task.WhenAll(getCompaniesTask, getCitizenshipsTask); // UI thread is not blocked
var form = new FrmEmployee(getCompaniesTask.Result, getCitizenshipsTask.Result); // form is created with data
}
Now, you only need to make your form accept complete data in constructor instead of making your form load this data which breaks abstraction:
public class FrmEmployees
{
public FrmEmployees(List<Company> companies, List<Citizenship> citizenships)
{
companies.Insert(0,new data.Models.CompanyModels.Company { Address = new data.Models.Address(), Code = null, Name = "--Select--", BaseCurrency = new data.Models.Currency() });
cbCompany.DataSource = companies;
cbCompany.DisplayMember = "Name";
cbCompany.ValueMember = "ID";
citizenships.Insert(0, "--Select--");
cbCitizenship.DataSource = _citizenships;
cbCitizenship.DisplayMember = "Citizenship";
// etc.
}
}
One important thing: you can get many tasks and many data passed to a form constructor. If all this data is going to be used often togetther, then you would probably want to encapsulate this "get all these things" logic into a single place to remove possible code duplication.
See what I have done... if anyone can review my code it would be appreciable.
public class EmployeeFormDataRepesenter
{
public List<Company> Companies { get; set; }
public List<Country> Countries { get; set; }
public List<CastCategory> CastCategories { get; set; }
}
public void LoadData(EmployeeFormDataRepesenter representer)
{
//gender
cbGender.DataSource = Enum.GetValues(typeof(Gender));
//merital status
cbMeritalStatus.DataSource = Enum.GetValues(typeof(MaritalStatus));
//religion
cbReligion.DataSource = Enum.GetValues(typeof(Religion));
//company
var _companies = representer.Companies;
_companies.Insert(0, new data.Models.CompanyModels.Company { Address = new data.Models.Address(), Code = null, Name = "--Select--", BaseCurrency = new data.Models.Currency() });
cbCompany.DataSource = _companies;
cbCompany.DisplayMember = "Name";
cbCompany.ValueMember = "ID";
//citizenship
var _citizenships = representer.Countries.Select(x => x.Citizenship).ToList();
_citizenships.Insert(0, "--Select--");
cbCitizenship.DataSource = _citizenships;
cbCitizenship.DisplayMember = "Citizenship";
//nationality
var _nations = representer.Countries.Select(x => x.Name).ToList();
_nations.Insert(0, "--Select--");
cbNationality.DataSource = _nations;
cbNationality.DisplayMember = "Name";
//domicile
var _domiciles = representer.Countries.Select(x => x.Name).ToList();
_domiciles.Insert(0, "--Select--");
cbDomicile.DataSource = _domiciles;
cbDomicile.DisplayMember = "Name";
//cast category
var _casts = representer.CastCategories.Select(x => new { x.ShortText, x.Description }).Distinct().ToList();
_casts.Insert(0, new { ShortText = "", Description = "--Select--" });
cbCategory.DataSource = _casts;
cbCategory.DisplayMember = "Description";
cbCategory.ValueMember = "ShortText";
}
private async void btnEmplyee_Click(object sender, EventArgs e)
{
con = new Connection();
Action showProgress = () => frmStatrup._progressBar.Visible = true;
Action hideProgress = () => frmStatrup._progressBar.Visible = false;
EmployeeFormDataRepesenter representer;
Task<List<Company>> _taskCompany = new Task<List<Company>>(() =>
{
BeginInvoke(showProgress);
var list = con.Companies.ToListAsync();
BeginInvoke(hideProgress);
if (list != null)
return list.Result;
return null;
});
Task<List<Country>> _taskCountry = new Task<List<Country>>(() =>
{
BeginInvoke(showProgress);
var list = con.Countries.ToListAsync();
BeginInvoke(hideProgress);
if (list != null)
return list.Result;
return null;
});
Task<List<CastCategory>> _taskCasts = new Task<List<CastCategory>>(() =>
{
BeginInvoke(showProgress);
var list = con.CastCategories.ToListAsync();
BeginInvoke(hideProgress);
if (list != null)
return list.Result;
return null;
});
_taskCompany.Start();
var _companies = await _taskCompany;
_taskCountry.Start();
var _countries = await _taskCountry;
_taskCasts.Start();
var _casts = await _taskCasts;
if (_companies.Count != 0)
{
representer = new EmployeeFormDataRepesenter();
representer.Companies = _companies;
representer.Countries = _countries;
representer.CastCategories = _casts;
}
else
{
representer = null;
}
if (representer != null)
{
frmEmployee _emp = new frmEmployee();
_emp.LoadData(representer);
Functions.OpenForm(_emp, this.ParentForm);
}
}

How do i parse my array to my model

I have made a ajax post and stringifyed my json and send the data to my controller method:
The data that the controller recieves looks like this:
"[\"0041300201\",1610612764,\"WAS\",\"Washington\",2772,\"Trevor Ariza\",\"F\",\"\",\"37:20\",7,10,0.7,6,6,1,2,4,0.5,1,5,6,2,1,0,0,3,22,18]"
My controller method:
public void addBoxScore(string playerstats)
{
Games gamestats = new Games();
gamestats.GAME_ID = playerstats[0];
gamestats.TEAM_ID = playerstats[1];
gamestats.TEAM_ABBREVIATION = playerstats[2].ToString();
gamestats.TEAM_CITY = playerstats[3].ToString();
gamestats.PLAYER_ID = playerstats[4];
gamestats.PLAYER_NAME = playerstats[5].ToString();
gamestats.START_POSITION = playerstats[6].ToString();
gamestats.COMMENT = playerstats[7].ToString();
gamestats.MIN = playerstats[8];
gamestats.FGM = playerstats[9];
gamestats.FGA = playerstats[10];
gamestats.FG_PCT = playerstats[11];
gamestats.FGTHREEM = playerstats[12];
gamestats.FGTHREEA = playerstats[13];
gamestats.FGTHREE_PCT = playerstats[14];
gamestats.FTM = playerstats[15];
gamestats.FTA = playerstats[16];
gamestats.FT_PCT = playerstats[17];
gamestats.OREB = playerstats[18];
gamestats.DREB = playerstats[19];
gamestats.REB = playerstats[20];
gamestats.AST = playerstats[21];
gamestats.STL = playerstats[22];
gamestats.BLK = playerstats[23];
gamestats.TO = playerstats[24];
gamestats.PF = playerstats[25];
gamestats.PTS = playerstats[26];
gamestats.PLUS_MINUS = playerstats[27];
}
When i do this the gamestats.Game_ID becomes "91" instead of "0041300201" as i wanted it to be.
Please use this array or list of string instead of only strings. like this
public void addBoxScore(string[] playerstats)

WCF Data Service Query seems to be retrurning duplcate rows on repeated queries

I have a data class that return some objects from a wcf dataservice to a silverlight app:
void ExecuteWipReportQuery(DataServiceQuery qry)
{
context = new StaffKpiServices.HwfStaffKpiEntities(theServiceRoot);
qry.BeginExecute(new AsyncCallback(a =>
{
try
{
IEnumerable results = qry.EndExecute(a);
OnDataLoadingComplete(new WipReportByMonthEventArgs(results));
}
catch (Exception ex)
{
OnDataLoadingError(ex);
}
}), null);
}
The view model then get these results and adds them to an observable collection:
void wipReportDataContainer_DataLoadingComplete(object sender, Domain.WipReportByMonthEventArgs e)
{
Application.Current.RootVisual.Dispatcher.BeginInvoke(() =>
{
this.wipReport.Clear();
string s = "";
foreach (StaffKpiServices.WipReportByMonth r in e.Results)
{
//this.wipReport.Add(r);
//s += r.ClientCode;
this.wipReport.Add(new StaffKpiServices.WipReportByMonth
{
ClientCode = r.ClientCode,
ClientGroup = r.ClientGroup,
ClientName = r.ClientName,
ClientType = r.ClientType,
FinancialYear = r.FinancialYear,
Month = r.Month,
OSDebt = r.OSDebt,
OSDisb = r.OSDisb,
OSOther = r.OSOther,
OSTime = r.OSTime,
OSTotal = r.OSTotal,
PartnerUserName = r.PartnerUserName,
PracName = r.PracName,
Recov = r.Recov,
RecovFees = r.RecovFees,
RecPerc = r.RecPerc,
SicCode = r.SicCode,
SicParentName = r.SicParentName,
StaffName = r.StaffName,
YTDFees = r.YTDFees,
YTDTime = r.YTDTime
});
s += r.ClientCode + " ";
}
string s2 = "";
foreach (var p in this.wipReport)
{
s2 += p.ClientCode + " ";
}
OnPropertyChanged("WipReport");
if (null != LoadComplete)
{
LoadComplete(this, EventArgs.Empty);
}
});
}
Everything works ok, but if the data is refreshed two or three times, then the collections retrun contains the right number of objects, but all with duplicate properties. There seems to be no reason why, it is as if the foreach is not working on the collection, but at the same time not returning any errors. Any ideas?
Ok so this was odd.. but by recreating the object that fetches the data (the one that creates the context), all was ok, but if the viewmodel kept alive the object responsible for running the dataservice query, the problem occured.....
I have no idea why this should have been, but the problem has gone away.....

Categories