WCF-ServiceReference Response gives ArrayOfXElement instead of the object - c#

I am trying to write login app.
My problem is that Service gives me ArrayOfXElement instead of an object.
And I do not know how to get to this object.
Here is the code:
StartPage.xaml.cs
using (...);
namespace MyFirstProject
{
public sealed partial class StartPage : Page
{
ServiceReference1.Service1Client MyService;
public StartPage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
MyService = new ServiceReference1.Service1Client();
}
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.GetSinglePassCmdResponse h = MyService.GetSinglePassCmdAsync(new ServiceReference1.Pass { nickName = tBoxNick_log.Text }).Result;
Now I thought that in h I have object and I can do smth like this:
testBlock.Text = "nickname: " + h.nickname + " password: " + h.pass;
}}}
but I got error that GetSinglePassCmdResponse does not contain a definition for 'nickname'
IService1.cs
[OperationContract]
Pass GetSinglePassCmd(Pass Pass);
[DataContract]
public partial class Pass
{
[DataMember]
public string nickName { get; set; }
[DataMember]
public string password { get; set; }
[DataMember]
public Nullable<System.DateTime> lastLogDate { get; set; }
Service1.svc
public Pass GetSinglePassCmd(Pass Pass)
{
if (con.State == ConnectionState.Closed)
{
con.Open();
}
SqlCommand cmd = new SqlCommand("SELECT * FROM Passwords WHERE nickName=#nickName", con);
cmd.Parameters.AddWithValue("#nickName", Passwords.nickName);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
cmd.ExecuteNonQuery();
con.Close();
Pass pass = new Pass();
int i = 0;
if (ds.Tables[0].Rows.Count > 0)
{
//assign dataset values to array
pass.nickName = ds.Tables[0].Rows[i]["nickName"].ToString();
pass.password = ds.Tables[0].Rows[i]["password"].ToString();
pass.lastLogDate = DateTime.Parse(ds.Tables[0].Rows[i]["lastLogDate"].ToString());
}
else pass = null;
return pass;
}
And in MyFirstProject->ServiceReferences->ServiceReference1->Reference.cs->GetSinglePassCmdResponse I got
public partial class GetSinglePassCmdResponse {
[System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://tempuri.org/", Order=0)]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public MyFirstProject.ServiceReference1.ArrayOfXElement GetSinglePassCmdResult;
public GetSinglePassCmdResponse() {
}
public GetSinglePassCmdResponse(MyFirstProject.ServiceReference1.ArrayOfXElement GetSinglePassCmdResult) {
this.GetSinglePassCmdResult = GetSinglePassCmdResult;
}
}
Could anyone help me please... ?
PS I have also tried this:
testBlock.Text = "nickname: " + h.GetSinglePassCmdResult.nickname + " password: " + h.GetSinglePassCmdResult.pass;

Related

Show MessageBox that contain sql data when button clicked in c#

I'm making a program that showing my data into image and label. Here's an example of my program when not clicked:
When not Clicked:
When Clicked
The question is when I click one of those images. How to show the id ("id_movie" in my SQL) of that image into a MessageBox ViewModel Class.
public class VModel
{
public VModel()
{
Clicked = new ClickedCommand(this);
DataTable dt = new DataTable();
using (MySqlConnection connection = new MySqlConnection("SERVER=localhost;" + "DATABASE=library;" + "UID=root;" + "PASSWORD=;"))
{
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand("Select * from movie_list", connection);
adapter.Fill(dt);
}
Library = dt.DefaultView;
}
public ICommand Clicked { get; set; }
public DataView Library { get; private set; }
}
Click Class
internal class ClickedCommand : ICommand
{
private VModel vModel;
public ClickedCommand(VModel vModel)
{
this.vModel = vModel;
}
public event EventHandler CanExecuteChanged { add { } remove { } }
public bool CanExecute(object parameter)
{
return true;
}
public void Execute(object parameter)
{
MessageBox.Show("the id that got clicked");
}
}
If you just need the data of the database, you could give the dt as a parameter when initializing the ClickedCommand.
public class VModel
{
public ICommand Clicked { get; set; }
public DataView Library { get; private set; }
public VModel()
{
DataTable dt = new DataTable();
using (MySqlConnection connection = new MySqlConnection("SERVER=localhost;" + "DATABASE=library;" + "UID=root;" + "PASSWORD=;"))
{
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand("Select * from movie_list", connection);
adapter.Fill(dt);
}
var Library = dt.DefaultView;
// this = viewModel or Library as parameter
var Clicked = new ClickedCommand(this);
}
}
And in the Execute method you access the vModel or Library field, depending on what you gave as a parameter and present the data.
internal class ClickedCommand : ICommand
{
private VModel _vModel;
// private DataView _library;
public ClickedCommand(VModel vModel)
{
_vModel = vModel;
// _library = library;
}
public void Execute(object parameter)
{
int rowIndex;
int.TryParse(((string[])parameter)[0], out rowIndex);
var stringToSearch = ((string[]) parameter)[1];
// however you access it here.
MessageBox.Show(_vModel.Library[rowIndex][stringToSearch]);
// MessageBox.Show(_library[rowIndex][stringToSearch]);
}
}

Passing logged in user information to another form c# mysql

For example I want to display the logged in user's information from database to another form like firstname and lastname I got no problem in admin because it only has one form or details for it. I tried passing the text in textbox username to another form and then select the passed text to display the other information of it but it won't, here's my code btw.
private void button2_Click(object sender, EventArgs e)
{
int i = 0;
MySqlCommand comm = con.CreateCommand();
comm.CommandText = "select * from accountinfo where username = #user and pass = #password";
comm.Parameters.AddWithValue("#user", textBox1.Text);
comm.Parameters.AddWithValue("#password", textBox2.Text);
MySqlDataReader myReader;
con.Open();
comm.ExecuteNonQuery();
myReader = comm.ExecuteReader();
string accountType = string.Empty;
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(comm);
i = Convert.ToInt32(dt.Rows.Count.ToString());
while (myReader.Read())
{
i = i + 1;
accountType = myReader["accountType"].ToString();
}
if (i == 0)
{
MessageBox.Show("Wrong username or password!");
}
else if (accountType == "admin")
{
MessageBox.Show("Welcome admin");
this.Hide();
textBox1.Text = string.Empty;
textBox2.Text = string.Empty;
Form3 frm3 = new Form3();
frm3.Show();
}
else
{
MessageBox.Show("Welcome");
this.Hide();
using(var frm4 = new Form4())
{
frm4.FirstName = textBox1.Text;
frm4.ShowDialog();
}
}
con.Close();
}
and my code in second form
public partial class Form4 : Form
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string CellNo { get; set; }
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
tbUser.Text = FirstName;
try
{
string MyConnection2 = "server=localhost;user id=root;database=account;persistsecurityinfo=True;PASSWORD=test123;SslMode=none";
string Query = "SELECT firstname = '" + tbFN.Text + "' from accountinfo WHERE username = '" + tbUser + "' " ;
MySqlConnection MyConn2 = new MySqlConnection(MyConnection2);
MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
MyAdapter.SelectCommand = MyCommand2;
DataTable dTable = new DataTable();
MyAdapter.Fill(dTable);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
Logged in user information is kind of static for all your application, so you should be able to access to it from anywhere
As a solution create class user
public class User {
username, full name ...
}
Create embiend class ApplicationContext
public class ApplicationContext
{
private ApplicationContext(){
}
public User UserInfo {get;}
public static ApplicationContext Current{get;}
public static Init(User userInfo)
{
if(Current != null)
throw new Exception("Context already initialized");
Current = new ApplicationContext(){
UserInfo = userInfo
}
}
}
After login call
ApplicationContext.Init(userInfo);
Everywhere where you need user info call
ApplicationContext.Current.UserInfo

C# 'Class.IMDb' does not contain a constructor that takes 0 arguments

I have class which gets info from Imdb.com about movie ant stores info in class variables.I have another class which writes info about movie in database. So, I want to make inheritence and get variables info and save into database. But I am getting error: 'FilmuBiblioteka.IMDb' does not contain a constructor that takes 0 arguments
Here is my code:
public class IMDb
{
public bool status { get; set; }
public string Id { get; set; }
public string Title { get; set; }
public string OriginalTitle { get; set; }
public string Year { get; set; }
public string Rating { get; set; }
public ArrayList Genres { get; set; }
public ArrayList Directors { get; set; }
public ArrayList Cast { get; set; }
public string Plot { get; set; }
public string Poster { get; set; }
public string PosterLarge { get; set; }
public string PosterFull { get; set; }
public string Runtime { get; set; }
public ArrayList Languages { get; set; }
public ArrayList Countries { get; set; }
public string ImdbURL { get; set; }
//Search Engine URLs
private string GoogleSearch = "http://www.google.com/search?q=imdb+";
private string BingSearch = "http://www.bing.com/search?q=imdb+";
private string AskSearch = "http://www.ask.com/web?q=imdb+";
private Func<string> toString;
private bool v;
//Constructor
public IMDb(string MovieName, bool GetExtraInfo = true)
{
string imdbUrl = getIMDbUrl(System.Uri.EscapeUriString(MovieName));
status = false;
if (!string.IsNullOrEmpty(imdbUrl))
{
parseIMDbPage(imdbUrl, GetExtraInfo);
}
}
public IMDb(Func<string> toString, bool v)
{
this.toString = toString;
this.v = v;
}
//Get IMDb URL from search results
private string getIMDbUrl(string MovieName, string searchEngine = "google")
{
string url = GoogleSearch + MovieName; //default to Google search
if (searchEngine.ToLower().Equals("bing")) url = BingSearch + MovieName;
if (searchEngine.ToLower().Equals("ask")) url = AskSearch + MovieName;
string html = getUrlData(url);
ArrayList imdbUrls = matchAll(#"<a href=""(http://www.imdb.com/title/tt\d{7}/)"".*?>.*?</a>", html);
if (imdbUrls.Count > 0)
return (string)imdbUrls[0]; //return first IMDb result
else if (searchEngine.ToLower().Equals("google")) //if Google search fails
return getIMDbUrl(MovieName, "bing"); //search using Bing
else if (searchEngine.ToLower().Equals("bing")) //if Bing search fails
return getIMDbUrl(MovieName, "ask"); //search using Ask
else //search fails
return string.Empty;
}
//Parse IMDb page data
private void parseIMDbPage(string imdbUrl, bool GetExtraInfo)
{
string html = getUrlData(imdbUrl + "combined");
Id = match(#"<link rel=""canonical"" href=""http://www.imdb.com/title/(tt\d{7})/combined"" />", html);
if (!string.IsNullOrEmpty(Id))
{
status = true;
Title = match(#"<title>(IMDb \- )*(.*?) \(.*?</title>", html, 2);
OriginalTitle = match(#"title-extra"">(.*?)<", html);
Year = match(#"<title>.*?\(.*?(\d{4}).*?\).*?</title>", html);
Rating = match(#"<b>(\d.\d)/10</b>", html);
Genres = matchAll(#"<a.*?>(.*?)</a>", match(#"Genre.?:(.*?)(</div>|See more)", html));
Directors = matchAll(#"<td valign=""top""><a.*?href=""/name/.*?/"">(.*?)</a>", match(#"Directed by</a></h5>(.*?)</table>", html));
Cast = matchAll(#"<td class=""nm""><a.*?href=""/name/.*?/"".*?>(.*?)</a>", match(#"<h3>Cast</h3>(.*?)</table>", html));
Plot = match(#"Plot:</h5>.*?<div class=""info-content"">(.*?)(<a|</div)", html);
Runtime = match(#"Runtime:</h5><div class=""info-content"">(\d{1,4}) min[\s]*.*?</div>", html);
Languages = matchAll(#"<a.*?>(.*?)</a>", match(#"Language.?:(.*?)(</div>|>.?and )", html));
Countries = matchAll(#"<a.*?>(.*?)</a>", match(#"Country:(.*?)(</div>|>.?and )", html));
Poster = match(#"<div class=""photo"">.*?<a name=""poster"".*?><img.*?src=""(.*?)"".*?</div>", html);
if (!string.IsNullOrEmpty(Poster) && Poster.IndexOf("media-imdb.com") > 0)
{
Poster = Regex.Replace(Poster, #"_V1.*?.jpg", "_V1._SY200.jpg");
PosterLarge = Regex.Replace(Poster, #"_V1.*?.jpg", "_V1._SY500.jpg");
PosterFull = Regex.Replace(Poster, #"_V1.*?.jpg", "_V1._SY0.jpg");
}
else
{
Poster = string.Empty;
PosterLarge = string.Empty;
PosterFull = string.Empty;
}
ImdbURL = "http://www.imdb.com/title/" + Id + "/";
if (GetExtraInfo)
{
string plotHtml = getUrlData(imdbUrl + "plotsummary");
}
}
}
/*******************************[ Helper Methods ]********************************/
//Match single instance
private string match(string regex, string html, int i = 1)
{
return new Regex(regex, RegexOptions.Multiline).Match(html).Groups[i].Value.Trim();
}
//Match all instances and return as ArrayList
private ArrayList matchAll(string regex, string html, int i = 1)
{
ArrayList list = new ArrayList();
foreach (Match m in new Regex(regex, RegexOptions.Multiline).Matches(html))
list.Add(m.Groups[i].Value.Trim());
return list;
}
//Strip HTML Tags
static string StripHTML(string inputString)
{
return Regex.Replace(inputString, #"<.*?>", string.Empty);
}
//Get URL Data
private string getUrlData(string url)
{
WebClient client = new WebClient();
Random r = new Random();
//Random IP Address
client.Headers["X-Forwarded-For"] = r.Next(0, 255) + "." + r.Next(0, 255) + "." + r.Next(0, 255) + "." + r.Next(0, 255);
//Random User-Agent
client.Headers["User-Agent"] = "Mozilla/" + r.Next(3, 5) + ".0 (Windows NT " + r.Next(3, 5) + "." + r.Next(0, 2) + "; rv:2.0.1) Gecko/20100101 Firefox/" + r.Next(3, 5) + "." + r.Next(0, 5) + "." + r.Next(0, 5);
Stream datastream = client.OpenRead(url);
StreamReader reader = new StreamReader(datastream);
StringBuilder sb = new StringBuilder();
while (!reader.EndOfStream)
sb.Append(reader.ReadLine());
return sb.ToString();
}
}
public class filmai : IMDb
{
public System.Data.DataSet gauticonnection
{
get
{ return gauti(); }
}
private System.Data.DataSet gauti()
{
System.Data.SqlClient.SqlConnection sqlConnection1;
System.Data.SqlClient.SqlDataAdapter da;
sqlConnection1 = new System.Data.SqlClient.SqlConnection(#"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Darius\Documents\Visual Studio 2013\Projects\FilmuBiblioteka\FilmuBiblioteka\duombaze.mdf");
da = new SqlDataAdapter("select * from filmai", sqlConnection1);
DataSet ds = new DataSet();
da.Fill(ds, "Table");
try
{
sqlConnection1.Open();
da.Fill(ds);
}
catch (Exception e)
{
throw;
}
finally
{
if (sqlConnection1.State == System.Data.ConnectionState.Open)
sqlConnection1.Close();
}
return ds;
}
public void prideti()
{
System.Data.SqlClient.SqlConnection sqlConnection1 = new System.Data.SqlClient.SqlConnection(#"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\Darius\Documents\Visual Studio 2013\Projects\FilmuBiblioteka\FilmuBiblioteka\duombaze.mdf");
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT filmai (Id, Pavadinimas, Metai, trukme, salis, kalba, reitingas, zanras, aktoriai, link, plot, rezisieriai) VALUES (Id, Title, Year, Runtime, Countries, Languages, Rating, Genres, Cast, ImdbURL, Plot, Directors)";
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
}
}
I'm getting error at this line: public class filmai : IMDb
As previously said in my comment the compliation error that you have is because the current constructor for your filmai class does not correctly call a constructor of your IMDb class.
To correctly inherit from a base class you must call it's constructor before your implemented constructor of the deriving class runs such as:
public filmai(string filmName)
: base(filmName, false)
{
}
This will call the base constructor of public IMDb(string MovieName, bool GetExtraInfo = true) with the film name that was provided to the filmai constructor and will say that it does not require extra information.
I'm not sure on your use-case though as it looks like filmai is purely for database access and IMDb is for requesting for a single film? But implementing a constructor on filmai and calling : base(...) will fix your issue just now.

WCF Not implementing interface member

I am working on a wcf service that connects to database. I had debugged and tested my operation playerregistration and clubregistration. I then tried to test the get functions but i received the error:
Error 1 'WebApplication1.ADOService' does not implement interface member 'WebApplication1.IADOService.newMembership(WebApplication1.playerDetails, WebApplication1.playerDetails, WebApplication1.clubDetails, WebApplication1.memberDetails)' C:\Users\Daniel\Documents\Visual Studio 2013\Projects\Prac4\WebApplication1\ADOService.svc.cs 14 18 WebApplication1
following the error I attempted to remove the get functions however the error remains. Below is the service code
public class ADOService : IADOService
{
public string playerRegistration(playerDetails playerInfo)
{
string Message;
using (SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=c:\\Users\\Daniel\\documents\\visual studio 2013\\Projects\\Prac4\\WebApplication1\\App_Data\\ADODatabase.mdf;Integrated Security=True"))
{
conn.Open();
using (var cmd = new SqlCommand("INSERT into Player(pid, pfname, plname, pphone, paddress, pdob) VALUES (#pid, #pfname, #plname, #pphone, #paddress, #pdob)", conn))
{
cmd.Parameters.AddWithValue("#pid", playerInfo.Pid);
cmd.Parameters.AddWithValue("#pfname", playerInfo.Pfname);
cmd.Parameters.AddWithValue("#plname", playerInfo.Plname);
cmd.Parameters.AddWithValue("#pphone", playerInfo.Pphone);
cmd.Parameters.AddWithValue("#paddress", playerInfo.Paddress);
cmd.Parameters.AddWithValue("#pdob", playerInfo.Pdob);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
Message = playerInfo.Pid + " Details inserted successfully";
}
else
{
Message = playerInfo.Pid + " Details not inserted successfully";
}
conn.Close();
return Message;
}
}
}
public string clubRegistration(clubDetails clubInfo)
{
string Message;
using (SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=c:\\Users\\Daniel\\documents\\visual studio 2013\\Projects\\Prac4\\WebApplication1\\App_Data\\ADODatabase.mdf;Integrated Security=True"))
{
conn.Open();
using (var cmd = new SqlCommand("INSERT into Club(cid, cname, cfounded, cworldranking) VALUES (#cid, #cname, #cfounded, #cworldranking)", conn))
{
cmd.Parameters.AddWithValue("#cid", clubInfo.Cid);
cmd.Parameters.AddWithValue("#cname", clubInfo.Cname);
cmd.Parameters.AddWithValue("#cfounded", clubInfo.Cfounded);
cmd.Parameters.AddWithValue("#cworldranking", clubInfo.Cworldranking);
int result = cmd.ExecuteNonQuery();
if (result == 1)
{
Message = clubInfo.Cname + " Details inserted successfully";
}
else
{
Message = clubInfo.Cname + " Details not inserted successfully";
}
conn.Close();
return Message;
}
}
}
public List<playerDetails> getplayerInfo(string pfname, string plname)
{
List<playerDetails> playerDetails = new List<playerDetails>();
{
using (SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=c:\\Users\\Daniel\\documents\\visual studio 2013\\Projects\\Prac4\\WebApplication1\\App_Data\\ADODatabase.mdf;Integrated Security=True"))
{
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Player WHERE pfname LIKE '%'+#pfname+'%' AND plname LIKE '%'+#plname+'%'", conn);
cmd.Parameters.AddWithValue("#pfname", pfname);
cmd.Parameters.AddWithValue("#plname", plname);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
playerDetails playerInfo = new playerDetails();
playerInfo.Pid = Convert.ToInt32(dt.Rows[i]["Pid"].ToString());
playerInfo.Pfname = dt.Rows[i]["Pfname"].ToString();
playerInfo.Plname = dt.Rows[i]["Plname"].ToString();
playerInfo.Pphone = Convert.ToInt32(dt.Rows[i]["Pphone"].ToString());
playerInfo.Paddress = dt.Rows[i]["Paddress"].ToString();
playerInfo.Pdob = DateTime.Parse(dt.Rows[i]["Pdob"].ToString());
playerDetails.Add(playerInfo);
}
}
conn.Close();
}
return playerDetails;
}
}
public List<clubDetails> getclubInfo(string cname)
{
List<clubDetails> clubDetails = new List<clubDetails>();
{
using (SqlConnection conn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=c:\\Users\\Daniel\\documents\\visual studio 2013\\Projects\\Prac4\\WebApplication1\\App_Data\\ADODatabase.mdf;Integrated Security=True"))
{
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Player WHERE cname LIKE '%'+#cname+'%'", conn);
cmd.Parameters.AddWithValue("#cname", cname);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
clubDetails clubInfo = new clubDetails();
clubInfo.Cid = Convert.ToInt32(dt.Rows[i]["Cid"].ToString());
clubInfo.Cname = dt.Rows[i]["Cname"].ToString();
clubInfo.Cfounded = DateTime.Parse(dt.Rows[i]["Cfounded"].ToString());
clubInfo.Cworldranking = Convert.ToInt32(dt.Rows[i]["Cworldranking"].ToString());
clubDetails.Add(clubInfo);
}
}
conn.Close();
}
return clubDetails;
}
}}}
And Iservice code
[ServiceContract]
public interface IADOService
{
[OperationContract]
string playerRegistration(playerDetails playerInfo);
[OperationContract]
string clubRegistration(clubDetails clubInfo);
[OperationContract]
List<playerDetails> getplayerInfo(string pfname, string plname);
[OperationContract]
List<clubDetails> getclubInfo(string cname);
[OperationContract]
string newMembership(playerDetails pfname, playerDetails plname, clubDetails cname, memberDetails memberstart);
}
[DataContract]
public class playerDetails
{
int pid;
string pfname;
string plname;
int pphone;
string paddress;
DateTime pdob;
[DataMember]
public int Pid
{
get { return pid; }
set { pid = value; }
}
[DataMember]
public string Pfname
{
get { return pfname; }
set { pfname = value; }
}
[DataMember]
public string Plname
{
get { return plname; }
set { plname = value; }
}
[DataMember]
public int Pphone
{
get { return pphone; }
set { pphone = value; }
}
[DataMember]
public string Paddress
{
get { return paddress; }
set { paddress = value; }
}
[DataMember]
public DateTime Pdob
{
get { return pdob; }
set { pdob = value; }
}
}
[DataContract]
public class clubDetails
{
int cid;
string cname;
DateTime cfounded;
int cworldranking;
[DataMember]
public int Cid
{
get { return cid; }
set { cid = value; }
}
[DataMember]
public string Cname
{
get { return cname; }
set { cname = value; }
}
[DataMember]
public DateTime Cfounded
{
get { return cfounded; }
set { cfounded = value; }
}
[DataMember]
public int Cworldranking
{
get { return cworldranking; }
set { cworldranking = value; }
}
}
[DataContract]
public class memberDetails
{
int mid;
DateTime memberstart;
DateTime memberend;
int gamesplayed;
[DataMember]
public int Mid
{
get { return mid; }
set { mid = value; }
}
[DataMember]
public DateTime Memberstart
{
get { return memberstart; }
set { memberstart = value; }
}
[DataMember]
public DateTime Memberend
{
get { return memberend; }
set { memberend = value; }
}
[DataMember]
public int Gamesplayed
{
get { return gamesplayed; }
set { gamesplayed = value; }
}
}
}
I am assuming that the get functions are the cause of the problem but not sure how to address the error.
You've defined the following methods in your interface:
string playerRegistration(playerDetails playerInfo);
string clubRegistration(clubDetails clubInfo);
List<playerDetails> getplayerInfo(string pfname, string plname);
List<clubDetails> getclubInfo(string cname);
string newMembership(playerDetails pfname, playerDetails plname, clubDetails cname, memberDetails memberstart);
But only implemented four of them:
playerRegistration
clubRegistration
getplayerInfo
getclubInfo
You haven't actually implemented newMembership in the ADOService class.

what is the use of datacontract?

here ,i am using wpf .in my code there is one folder named by datacontect:and it contain code as below:
public interface IAccountCategoryDataSource
{
bool Add(AccountCategory accountCategory);
bool Update(AccountCategory accountCategory);
bool Remove(AccountCategory accountCategory);
AccountCategory GetById(int id);
AccountCategory GetByName(string name);
IEnumerable<AccountCategory> GetByParentCategory(AccountCategory category);
IEnumerable<AccountCategory> GetTopLevelCategories();
IEnumerable<AccountCategory> GetBySearchTerm(string searchTerm);
IEnumerable<AccountCategory> GetAll();
event EventHandler<ObjectAddedEventArgs> AccountCategoryAdded;
event EventHandler<ObjectUpdatedEventArgs> AccountCategoryUpdated;
event EventHandler<ObjectRemovedEventArgs> AccountCategoryRemoved;
}
ther is also other folder datasource: here datasource is related to the above file
public class AccountCategoryDataSource : IAccountCategoryDataSource
{
public int ReferenceCountOf(AccountCategory accountCategory)
{
int count = 0;
string query = "select count(*) from account_categories where parent_category=" + accountCategory.Id
+ " union select count(*) from accounts where category=" + accountCategory.Id;
DataTable dataTable = SQLiteHelper.ExecuteQuery(query);
foreach (DataRow row in dataTable.Rows)
{
count += Convert.ToInt32(row[0]);
}
return count;
}
#region IAccountCategoryDataSource Members
public bool Add(AccountCategory accountCategory)
{
string query = "insert into account_categories(name, description, parent_category) values("
+ "'" + accountCategory.Name + "', "
+ "'" + accountCategory.Description + "', "
+ accountCategory.ParentCategory.Id
+ ")";
accountCategory.Id = SQLiteHelper.ExecuteInsert(query);
if (accountCategory.Id > 0)
{
if (AccountCategoryAdded != null)
{
AccountCategoryAdded(this, new ObjectAddedEventArgs(accountCategory));
}
return true;
}
return false;
}
public bool Update(AccountCategory accountCategory)..................
and this related to the model floder's accountcategory class
public class AccountCategory : IDataErrorInfo, IValidable
{
#region State Properties
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public AccountCategory ParentCategory { get; set; }
public bool Builtin { get; set; }
}
and for execution :helper class
public class SQLiteHelper
{
public static DataTable ExecuteQuery(string query)
{
DataTable dataTable = new DataTable();
SQLiteConnection conn = new SQLiteConnection(Settings.Default["DBConnectionString"].ToString());
using (SQLiteCommand cmd = new SQLiteCommand(query, conn))
{
conn.Open();
SQLiteDataReader reader = cmd.ExecuteReader();
dataTable.Load(reader);
reader.Close();
conn.Close();
}
return dataTable;
}..........................
plz explain brief role of data contract.and how it interact with helper,model,and dataSouce . is it provide linq to sql concept?
DataContract is a WCF concept. It is unrelated to WPF (until it is communicating with WCF).
From your code, seems like it it just a Folder which contain Data Access Layer classes and seems unrelated to WCF

Categories