I have to reload a huge database by a program regularily. There are two datasources for this database, but there are some user inputed information in the database too, like comments. here are some experiences I gain from doing this:
(1) selected the user inputed information into a hashtable or arraylist with database primary key, a simple struct or class will serve the purpose
(2) in database table, have backup indicator column, when insert, only insert as backup data
(3) keep count the error rate when inserting
(4) at the end, if everything is fine, error rate is low, delete the no-backup data and flipover backup data to live
(5) make sure all queries to the database only get live data, not backup data. Or to create a view for this
Thursday, August 30, 2007
Search dataset/dataview using primary key
If you have a huge dataset, the performance of searching a record using dataset.Select won't be efficient. The best way to do this is to make primary key(s) of the dataset/dateview.
following line add two primary keys to the dataview
DataView dv = new DataView(dt,null,"pol_nbr,pol_sfx",DataViewRowState.CurrentRows);
then you can search a row by these keys
following line add two primary keys to the dataview
DataView dv = new DataView(dt,null,"pol_nbr,pol_sfx",DataViewRowState.CurrentRows);
then you can search a row by these keys
object[] keys = new object[2];
keys[0] = "0000"+p.Number;
keys[1] = p.Suffix;
DataRowView[] drv = dv.FindRows(keys);
Simply Ajax Solution
No need any AJAX framework or fancy update panels, just by using some simple javascript you can get some cool Ajax effect, plus web service is not needed.
In this function, xmlHttp.onreadystatechange set a callback function, while xmlHttp.open("GET","slgetemail.aspx?pol=" + pol_nbr,true); initial the call of another page to get emails using a query string. So the whole content of the page will be parsed in the callback function and display the email.
function GetSLEmailByID(controlID, pol_nbr)
{
var xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
try
{
document.getElementById(controlID).innerHTML = xmlHttp.responseText;
}
catch(e)
{
alert(controlID+"\n"+e.message);
}
}
}
xmlHttp.open("GET","slgetemail.aspx?pol=" + pol_nbr,true);
xmlHttp.send(null);
}
In this function, xmlHttp.onreadystatechange set a callback function, while xmlHttp.open("GET","slgetemail.aspx?pol=" + pol_nbr,true); initial the call of another page to get emails using a query string. So the whole content of the page will be parsed in the callback function and display the email.
Business layer sorting
Sometime, you need to sort a list of business object, for example you have a list of SLPolicy object in an arraylist, and you want to sort it in different ways, like by policynumber, expiration date, or agent code. You want to do this as easy as this:
ArrayList Policies = CreateListofPolicies() ;
SLPolicy.SortBy = "PolicyNumber";
Policies.Sort();
if that's what you want, you need to implement some class like below:
ArrayList Policies = CreateListofPolicies() ;
SLPolicy.SortBy = "PolicyNumber";
Policies.Sort();
if that's what you want, you need to implement some class like below:
[Serializable]
public class SLPolicy : IComparable
{
#region IComparable Members
public int CompareTo(object obj)
{
switch (_container.Container.SortKind)
{
case SLSortableKind.AgentCodeAsc:
return _agentCode.CompareTo(((SLPolicy) obj).AgentCode);
case SLSortableKind.AgentCodeDesc:
return ((SLPolicy) obj).AgentCode.CompareTo(_agentCode);
case SLSortableKind.InsuredNameAsc:
case SLSortableKind.InsuredNameDesc:
case SLSortableKind.ExpDateAsc:
return _expDate.CompareTo(((SLPolicy) obj).ExpDate);
case SLSortableKind.ExpDateDesc:
return ((SLPolicy) obj).ExpDate.CompareTo(_expDate);
default:
return 0;
}
}
#endregion
}
Crazy business requirements
I am going to organize all the good parts of the recent projects. But before that, I'd like to write down these nosense business requirements I've ever heard in this company. I believe it will fun to read them even couple years later.
(1) one business people asked if we can program the web application so that we can tell if customers are using keyboard or mouse, and if they are using keyboard, how fast they can type
(2) another business people wants to find out if user is visiting a page purposely or just accidentally click the wrong link.
(1) one business people asked if we can program the web application so that we can tell if customers are using keyboard or mouse, and if they are using keyboard, how fast they can type
(2) another business people wants to find out if user is visiting a page purposely or just accidentally click the wrong link.
Subscribe to:
Posts (Atom)