using using using using using using using using using using using using using using using

System; System.Collections; System.Configuration; System.Data; System.Linq; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.HtmlControls; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Xml.Linq; System.Data.OleDb; System.Data.SqlClient; System.Text;

public partial class UploadDatabase : System.Web.UI.Page { public static System.Data.OleDb.OleDbConnection conn; public static System.Data.OleDb.OleDbCommand cmd; public static System.Data.OleDb.OleDbConnection connserver; public static System.Data.OleDb.OleDbCommand cmdserver; public void connection() { try { string pth = Convert.ToString(ViewState["Path"]); conn = new System.Data.OleDb.OleDbConnection(); if (pth == "OPDDataAccount") { conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data S ource= |DataDirectory|\OPDDataAccount.mdb;Jet OLEDB:Database Password=SUNEHRI;P ersist Security Info=False"; } else if (pth == "OPDDataDoctor") { conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data S ource= |DataDirectory|\OPDDataDoctor.mdb;Jet OLEDB:Database Password=SUNEHRI;Pe rsist Security Info=False"; } else if (pth == "OPDDataVaccine") { conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data S ource= |DataDirectory|\OPDDataVaccine.mdb;Jet OLEDB:Database Password=SUNEHRI;P ersist Security Info=False"; } else { lblMessage.Text = "Database Not Found"; } // conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data So urce=D:\Project\WebSite1\App_Data\OPDDataDoctor.mdb"; //conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Sou rce=D:\Project\WebSite1\test.mdb"; conn.Open(); }

catch (Exception ex) { lblMessage.Text = ex.ToString(); } } public void ConnectionServer() { try { string pth =Convert.ToString(ViewState["Path"]); connserver = new System.Data.OleDb.OleDbConnection(); if (pth != "") { //connserver.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4. 0;Data Source= |DataDirectory|\Database\tt.mdb;Jet OLEDB:Database Password=SUN EHRI;Persist Security Info=False"; connserver.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Project\WebSite1\Database\" "\"+ pth +";Jet OLEDB:Databas e Password=SUNEHRI;Persist Security Info=False"; } else { lblMessage.Text = "Database Not Found"; } //if (pth == "tt.mdb") //{ // conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |DataDirectory|\ '"+ pth +"';Jet OLEDB:Database Password=SUNEHRI;Persi st Security Info=False"; //} //else if (pth == "OPDDataDoctor") //{ // conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |DataDirectory|\OPDDataDoctor.mdb;Jet OLEDB:Database Password=SUNEHRI; Persist Security Info=False"; //} //else if (pth == "OPDDataVaccine") //{ // conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= |DataDirectory|\OPDDataVaccine.mdb;Jet OLEDB:Database Password=SUNEHRI ;Persist Security Info=False"; //} //else //{ // lblMessage.Text = "Database Not Found"; //} //connserver = new System.Data.OleDb.OleDbConnection(); //conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Sou rce=D:\Project\WebSite1\App_Data\OPDDataDoctor.mdb"; //connserver.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Da ta Source=D:\Project\WebSite1\Database\Doctor.mdb;Jet OLEDB:Database Passwor d=SUNEHRI;Persist Security Info=False"; //conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Sou rce= |DataDirectory|\Doctor.mdb;Jet OLEDB:Database Password=SUNEHRI;Persist Sec urity Info=False"; connserver.Open(); } catch (Exception ex)

{ lblMessage.Text = ex.ToString(); } } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindLocation(); } // BindData(); } protected void btnUpload_Click(object sender, EventArgs e) { try { string pth = ""; pth = flp.FileName.ToString(); ViewState["Path"] = pth; connection(); ConnectionServer(); lblMessage.Text = "Database Upload Successfully !"; } catch (Exception ex) { lblMessage.Text = ex.ToString(); } } public void BindLocation() { connection(); ddlLocation.Items.Clear(); DataTable dt = new DataTable(); ddlLocation.Items.Add("...Select..."); ddlLocation.Items[0].Value = "-1"; OleDbDataAdapter da = new OleDbDataAdapter("select * from Location ", co nn); da.Fill(dt); if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { ListItem lstLoc = new ListItem(dr["Loc_Name"].ToString(), dr["Lo c_Code"].ToString()); ddlLocation.Items.Add(lstLoc); } ddlLocation.DataBind(); } } public DataTable BindData() { string[] arr = new string[60]; //arr[0] = "Acct_Mast"; arr[0] = "allergic"; arr[1] = "Appointment_Sch";

arr[3] = "Areas"; arr[4] = "Charge_Detail"; arr[5] = "Cities"; arr[6] = "Comp_Rights"; arr[7] = "CompDur"; arr[8] = "Conv_Dose"; arr[9] = "Diagnosis"; arr[10] = "DispMaster"; arr[11] = "District"; arr[12] = "DocIncentive"; arr[13] = "Doct_Mast"; arr[14] = "DoctorInfo"; arr[15] = "Doctors"; arr[16] = "Examination"; arr[17] = "GrpInst"; arr[18] = "GrpMedInst"; arr[19] = "HistLetters"; arr[20] = "History_Diagnosis"; arr[21] = "History_Examin"; arr[22] = "History_Medicine"; arr[23] = "History_NV"; arr[24] = "History_Phy"; arr[25] = "History_SpInst"; arr[26] = "History_Test"; arr[27] = "IdealWeight"; arr[28] = "Investigation"; arr[29] = "Investigation_Det"; arr[30] = "Lab"; arr[31] = "LOCATION"; arr[32] = "LP"; arr[33] = "MainComplains"; arr[34] = "Margin"; arr[35] = "Medi_Diag"; arr[36] = "Medicine"; arr[37] = "MedInst"; arr[38] = "Menu_Rights"; arr[39] = "MenuMast"; arr[40] = "New_Patient"; arr[41] = "Patient_PersonalDetail"; arr[42] = "Reminders"; arr[43] = "SpInst"; arr[44] = "State"; arr[45] = "StdDiag"; arr[46] = "StdIndRx"; arr[47] = "StdRx"; arr[48] = "Streets"; arr[49] = "SubComplains"; arr[50] = "tempadvise"; arr[51] = "temppnv"; arr[52] = "Timing"; arr[53] = "Title"; arr[54] = "Today_Apt"; arr[55] = "Today_Apt_Bac"; arr[56] = "Units"; arr[57] = "Usermast"; arr[58] = "Utility"; arr[59] = "VisitDate"; connection(); ConnectionServer(); DataTable dt = new DataTable();

for (int i = 0; i <= 1; i++) { DataTable dtdate = new DataTable(); DataTable dttime = new DataTable(); OleDbDataAdapter dadate = new OleDbDataAdapter("select max(Cdate) fr om " + arr[i] + "", connserver); dadate.Fill(dtdate); OleDbDataAdapter datime = new OleDbDataAdapter("select max(Ctime) fr om " + arr[i] + "", connserver); datime.Fill(dttime); DateTime date = Convert.ToDateTime(dtdate.Rows[0][0]); DateTime time = Convert.ToDateTime(dttime.Rows[0][0]); DataTable dtupload = new DataTable(); OleDbDataAdapter daupload = new OleDbDataAdapter("select * from " + arr[i] + " where Cdate >= cdate ('" + date + "')", conn); daupload.Fill(dtupload); if (dtupload.Rows.Count > 0) { OleDbCommand cmd2 = new OleDbCommand("delete from " + arr[i] + " where Cdate = cdate ('" + date + "')", connserver); cmd2.ExecuteNonQuery(); OleDbCommand cmd1 = new OleDbCommand(); cmd1.CommandType = CommandType.Text; string insertFields = ""; string insertValues = ""; foreach (DataColumn col in dtupload.Columns) { insertFields += col.ColumnName + ","; } string FinalField = insertFields.TrimEnd(','); foreach (DataRow row in dtupload.Rows) { for (int k = 0; k <= dtupload.Columns.Count - 1; k++) { insertValues += "'" + row.ItemArray.GetValue(k) + "'" + " ,"; } string FinalValue = insertValues.TrimEnd(','); cmd1 = new OleDbCommand("insert into " + arr[i] + " (" + Fi nalField + ") values (" + FinalValue + ")", connserver); cmd1.ExecuteNonQuery(); insertValues = insertValues.Replace(insertValues, ""); } } } return dt; } protected void ddlLocation_SelectedIndexChanged(object sender, EventArgs e) { // chkFileList.Items.Clear(); if (ddlLocation.SelectedItem.Text == "...Select...")

{ lblMessage.Text = "Please Select Location !"; ddlLocation.Focus(); // btnDownload.Enabled = false; } else { lblMessage.Text = ""; } } }