Well here are my code blocks again.
Here is the code snippet for the flow of operations that are happening on
clicking the login button on login screen.
partial void LoginClick (MonoTouch.UIKit.UIButton sender)
{
try
{
if(ValidateControls ())
{
ASTONAPPService.IPADService objipad=new
ASTONAPP.ASTONAPPService.IPADService();
ASTONAPPService.BLL_User
user=objipad.GetLoginUser(txtClientCode.Text,
txtEmail.Text, txtPassword.Text);
if(user!=null)
{
System.Xml.Serialization.XmlSerializer xx=new
XmlSerializer(user.GetType ());
string
pathtowrite=System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var dirName=Path.Combine
(pathtowrite, "ASTON Repository");
if(!Directory.Exists (dirName))
{
Directory.CreateDirectory (dirName);
}
var filepath=Path.Combine
(dirName, "BLL_User.xml");
if(File.Exists (filepath))
{
File.Delete (filepath);
}
TextWriter txtW=new
StreamWriter(filepath);
xx.Serialize (txtW, user);
txtW.Close ();
XmlDocument xmldoc=new
XmlDocument();
xmldoc.Load (filepath);
XmlNamespaceManager nmsmgr=new
XmlNamespaceManager(xmldoc.NameTable);
nmsmgr.AddNamespace ("nmspc",
"http://tempuri.org/");
XmlNodeList
xmlnl=xmldoc.SelectNodes ("//nmspc:UserName", nmsmgr);
string
username=xmlnl[0].InnerText.ToString ();
UIAlertView uvm=new
UIAlertView("Notification", "Success!
"+username.ToString ()+" Authenticated", null, "OK", null);
uvm.Show ();
this.ash=new AssessmentsHome();
this.NavigationController.PushViewController (this.ash, true);
}
else
{
UIAlertView uvy=new
UIAlertView("Notification", "Invalid Credentials!
Please try again!", null, "OK", null);
uvy.Show ();
}
}
else
{
UIAlertView uiv=new
UIAlertView("Notification", "All fields are
mandatory. Please try again with proper credentials!", null, "OK", null);
uiv.Show ();
}
}
catch(Exception exp)
{
UIAlertView uav=new UIAlertView("Notification",
"There seems to be some
problem with your internet connection or some other issue preventing you
from signing in. Please try again at a later time.", null, "OK", null);
uav.Show ();<------ only this message is
showing on clicking login
}
}
Here is the code snippet from the AssessmentHome screen where I am trying to
create the database at runtime and insert the data by calling the
appropriate method from DBHandler class.
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
objdbh.InitializeDatabase ();
Title="ASSESSMENTS";
//this.TabBarController.NavigationItem.HidesBackButton=true;
string
pathtowrite=System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var dirName=Path.Combine (pathtowrite, "ASTON
Repository");
var filepath=Path.Combine (dirName, "BLL_User.xml");
XmlDocument xmldoc=new XmlDocument();
xmldoc.Load (filepath);
XmlNamespaceManager nmsmgr=new
XmlNamespaceManager(xmldoc.NameTable);
nmsmgr.AddNamespace ("nmspc", "http://tempuri.org/");
XmlNodeList xmlnl=xmldoc.SelectNodes
("//nmspc:UserName", nmsmgr);
XmlNodeList xmlnl1=xmldoc.SelectNodes
("//nmspc:ClientID", nmsmgr);
string username=xmlnl[0].InnerText.ToString ();
int clientID=Convert.ToInt32(xmlnl1[0].InnerText);
lblLoggedClient.AdjustsFontSizeToFitWidth=true;
lblLoggedClient.Text=username.ToString ();
DataSet ds=new DataSet();
ds=objdbh.CheckForData ("select * from ClientInfo");
if(ds.Tables[0].Rows.Count>0)
{
UIAlertView uvm=new UIAlertView("Notification",
"Client Data
Synchronized Successfully. You can proceed.", null, "OK", null);
uvm.Show();
}
else
{
try
{
objdbh.InitializeClientData ();
}
catch(Exception exp)
{
UIAlertView uv1=new
UIAlertView("Notification", exp.GetBaseException
().ToString (), null, "OK", null);
uv1.Show();
}
}
// Perform any additional setup after loading the view,
typically from a
nib.
}
Here is the entire code block from the DBhandler class where I have written
the database centric member functions. The critical point is that I cannot
see any database file being created anywhere in my folders structure. I am
using the Sqlite version 3.7.1 that is available as an add-on with Firefox.
using System;
using System.IO;
using System.Drawing;
using System.Data;
using Mono.Data.Tds;
using Mono.Data.Sqlite;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Linq;
using System.Linq;
using System.Linq.Expressions;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
namespace ASTONAPP
{
public class DBHandler
{
SqliteConnection sconn=new SqliteConnection();
SqliteCommand scmd=new SqliteCommand();
string dbConn;
public DBHandler ()
{
}
public void InitializeDatabase()
{
string
pathtowrite=System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var dirName=Path.Combine (pathtowrite, "ASTON
Repository");
if(!Directory.Exists (dirName))
{
Directory.CreateDirectory (dirName);
}
string dbFile="ASTON_DB_V1.db3";
string db=Path.Combine (dirName, dbFile);
dbConn=string.Format ("Data Source={0}", db);
sconn=new SqliteConnection();
if(!File.Exists (db))
{
SqliteConnection.CreateFile (db);
}
else
File.Delete (db);
File.Copy (dbFile, db);
}
public void InitializeClientData()
{
try
{
string
pathtowrite=System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var dirName=Path.Combine (pathtowrite, "ASTON
Repository");
var filepath=Path.Combine (dirName,
"BLL_User.xml");
XmlDocument xmldoc=new XmlDocument();
xmldoc.Load (filepath);
XmlNamespaceManager nmsmgr=new
XmlNamespaceManager(xmldoc.NameTable);
nmsmgr.AddNamespace ("nmspc",
"http://tempuri.org/");
XmlNodeList xmlnl1=xmldoc.SelectNodes
("//nmspc:ClientUserID", nmsmgr);
XmlNodeList xmlnl2=xmldoc.SelectNodes
("//nmspc:UserName", nmsmgr);
XmlNodeList xmlnl3=xmldoc.SelectNodes
("//nmspc:DiyCode", nmsmgr);
XmlNodeList xmlnl4=xmldoc.SelectNodes
("//nmspc:DiyPassword", nmsmgr);
XmlNodeList xmlnl5=xmldoc.SelectNodes
("//nmspc:Address", nmsmgr);
XmlNodeList xmlnl6=xmldoc.SelectNodes
("//nmspc:City", nmsmgr);
XmlNodeList xmlnl7=xmldoc.SelectNodes
("//nmspc:State", nmsmgr);
XmlNodeList xmlnl8=xmldoc.SelectNodes
("//nmspc:Country", nmsmgr);
XmlNodeList xmlnl9=xmldoc.SelectNodes
("//nmspc:PostCode", nmsmgr);
XmlNodeList xmlnl10=xmldoc.SelectNodes
("//nmspc:Email", nmsmgr);
XmlNodeList xmlnl11=xmldoc.SelectNodes
("//nmspc:Phone1", nmsmgr);
XmlNodeList xmlnl12=xmldoc.SelectNodes
("//nmspc:Phone2", nmsmgr);
XmlNodeList xmlnl13=xmldoc.SelectNodes
("//nmspc:IsAssessor", nmsmgr);
XmlNodeList xmlnl14=xmldoc.SelectNodes
("//nmspc:ClientID", nmsmgr);
XmlNodeList xmlnl15=xmldoc.SelectNodes
("//nmspc:ModifiedBy", nmsmgr);
XmlNodeList xmlnl16=xmldoc.SelectNodes
("//nmspc:CreatedBy", nmsmgr);
XmlNodeList xmlnl17=xmldoc.SelectNodes
("//nmspc:IsDeleted", nmsmgr);
int
ClientUserId=Convert.ToInt32(xmlnl1[0].InnerText.ToString ());
string UserName=xmlnl2[0].InnerText.ToString ();
string DiyCode=xmlnl3[0].InnerText.ToString ();
string DiyPassword=xmlnl4[0].InnerText.ToString
();
string Address=xmlnl5[0].InnerText.ToString ();
string City=xmlnl6[6].InnerText.ToString ();
string State=xmlnl7[0].InnerText.ToString ();
string Country=xmlnl8[0].InnerText.ToString ();
string PostCode=xmlnl9[0].InnerText.ToString ();
string Email=xmlnl10[0].InnerText.ToString ();
string Phone1=xmlnl11[0].InnerText.ToString ();
string Phone2=xmlnl12[0].InnerText.ToString ();
string IsAssessor=xmlnl13[0].InnerText.ToString
();
int ClientID=Convert.ToInt32
(xmlnl14[0].InnerText.ToString ());
int ModifiedBy=Convert.ToInt32
(xmlnl15[0].InnerText.ToString ());
int CreatedBy=Convert.ToInt32
(xmlnl16[0].InnerText.ToString ());
string IsAdmin=xmlnl17[0].InnerText.ToString ();
sconn=new SqliteConnection();
sconn.ConnectionString=dbConn;
sconn.Open ();
string[] sql1=new string[]{"create table if not
exists
ClientInfo(ClientOfflineID integer autoincrement, ClientUserID integer,
UserName ntext, DiyCode ntext, DiyPassword ntext, Address ntext, City ntext,
State ntext, Country ntext, PostCode ntext, Email ntext, Phone1 ntext,
Phone2 ntext, IsAssessor ntext, ClientId integer, ModifiedBy integer,
CreatedBy integer, IsAdmin ntext",
String.Format ("insert into
ClientInfo(ClientUserID, UserName, DiyCode,
DiyPassword, Address, City, State, Country, PostCode, Email, Phone1, Phone2,
IsAssessor, ClientID, CreatedBy, ModifiedBy, IsAdmin) values('{0}', '{1}',
'{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}',
'{12}', '{13}', '{14}', '{15}', '{16}', '{17}')", ClientUserId, UserName,
DiyCode, DiyPassword, Address, City, State, Country, PostCode, Email,
Phone1, Phone2, IsAssessor, ClientID, ModifiedBy, CreatedBy, IsAdmin)
} ;
foreach(string s in sql1)
{
scmd.CommandText=s;
scmd.ExecuteNonQuery ();
}
}
catch(Exception exp)
{
throw exp;
}
sconn.Close ();
}
public DataSet CheckForData(string strsql)
{
DataSet ds=new DataSet();
string
pathtowrite=System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var dirName=Path.Combine (pathtowrite, "ASTON
Repository");
string dbFile="ASTON_DB_V1.db3";
string db=Path.Combine (dirName, dbFile);
dbConn=string.Format ("Data Source={0}", db);
sconn.ConnectionString=dbConn;
scmd.Connection=sconn;
sconn.Open ();
scmd.CommandText=strsql;
scmd.CommandType=CommandType.Text;
SqliteDataAdapter sda=new SqliteDataAdapter(scmd);
sda.Fill (ds);
sconn.Close ();
return ds;
}
}
}
--
View this message in context:
http://monotouch.2284126.n4.nabble.com/MonoTouch-with-Sqlite-Critical-Scenario-Help-Needed-tp4655574p4655599.html
Sent from the MonoTouch mailing list archive at Nabble.com.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch