// //////////////////////////////////////////////////////////////////////// // INITIAL EVENTS // protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Prepare initial data Session.Remove("dataMigration"); // Initialize viewstate variables ViewState["StepFrom"] = "Out"; hdfCompanyId.Value = Session["companyID"].ToString(); // ... Initialize tables dataMigration = new DataMigrationTDS.JlDataMigrationDataTable(); dataMigrationProject = new DataMigrationTDS.DataMigrationProjectDataTable(); // ... Store tables Session["dataMigration"] = dataMigration; Session["dataMigrationProject"] = dataMigrationProject; // StepSection1In wzDataMigration.ActiveStepIndex = 0; StepProjectsIn(); } else { // Restore tables dataMigration = (DataMigrationTDS.JlDataMigrationDataTable)Session["dataMigration"]; dataMigrationProject = (DataMigrationTDS.DataMigrationProjectDataTable)Session["dataMigrationProject"]; } // control for postback hdfTag.Value = DateTime.Now.ToLongTimeString(); }
// ///////////////////////////////////////////////////////////////////////////////////////////////////// // // STEP1 - PROJECTS // // //////////////////////////////////////////////////////////////////////// // STEP1 - PROJECTS - METHODS // private void StepProjectsIn() { // Set instruction Label instruction = (Label)this.Master.FindControl("lblInstruction"); instruction.Text = "Please select a Microsoft Excel file of migration project"; //--- Initialize DataMigrationTDS dataSet = new DataMigrationTDS(); dataSet.DataMigrationProject.Merge(dataMigrationProject, true); DataMigrationProject model = new DataMigrationProject(dataSet); model.Table.Rows.Clear(); dataMigrationProject = dataSet.DataMigrationProject; Session["dataMigrationProject"] = dataSet.DataMigrationProject; }
private bool ProcessBulkProjectsUpload(string fName, out string bulkUploadProjectsResultMessage) { bool bulkUploadProccessed = true; bulkUploadProjectsResultMessage = ""; AppSettingsReader appSettingReader = new AppSettingsReader(); string excelConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties='Excel 8.0;HDR=YES;IMEX=1';Data Source=" + fName + ";"; OleDbConnection connection = new OleDbConnection(excelConnectionString); OleDbCommand command = null; OleDbDataReader dataReader = null; try { try { //--- Process bulk upload if (bulkUploadProccessed) { connection.Open(); command = new OleDbCommand("select * from [projects]", connection); dataReader = command.ExecuteReader(); while (dataReader.Read()) { if (!IsEmptyRow(dataReader)) { int companiesId = 0; Int64 countryId = 0; Int64? provinceId = null; Int64? countyId = null; Int64? cityId = null; int officeId = 0; int? projectLeadId = null; int salesmanId = 0; string project = ""; string dataCell = null; string dataCellToUpper = null; //--- ... fill section row for (int i = 0; i < dataReader.FieldCount; i++) { dataCell = dataReader.GetValue(i).ToString().Trim(); dataCellToUpper = dataReader.GetValue(i).ToString().Trim().ToUpper(); switch (dataReader.GetName(i).Trim()) { case "COMPANIES_ID": companiesId = int.Parse(dataCell); break; case "Country": if (dataCellToUpper != "NULL") { countryId = Int64.Parse(dataCell); } break; case "Province": if (dataCellToUpper != "NULL") { provinceId = Int64.Parse(dataCell); } break; case "County": if (dataCellToUpper != "NULL") { countyId = Int64.Parse(dataCell); } break; case "City": if (dataCellToUpper != "NULL" && dataCellToUpper != "") { cityId = Int64.Parse(dataCell); } break; case "Office": if (dataCellToUpper != "NULL") { officeId = int.Parse(dataCell); } break; case "Project Lead (optional)": if (dataCellToUpper != "NULL" && dataCellToUpper != "") { projectLeadId = int.Parse(dataCell); } break; case "Salesman": if (dataCellToUpper != "NULL") { salesmanId = int.Parse(dataCell); } break; case "Project": if (dataCellToUpper != "NULL") { project = dataCell; } else { bulkUploadProjectsResultMessage = "Invalid value in 'Project' column. Bulk upload ABORTED."; bulkUploadProccessed = false; } break; } if (!bulkUploadProccessed) { break; } } if (bulkUploadProccessed) { //--- Initialize DataMigrationTDS dataSet = new DataMigrationTDS(); dataSet.DataMigrationProject.Merge(dataMigrationProject, true); DataMigrationProject model = new DataMigrationProject(dataSet); model.Insert(companiesId, countryId, provinceId, countyId, cityId, officeId, projectLeadId, salesmanId, project); dataMigrationProject = dataSet.DataMigrationProject; Session["dataMigrationProject"] = dataSet.DataMigrationProject; } } } dataReader.Close(); connection.Close(); } } catch (Exception ex) { bulkUploadProjectsResultMessage = "You did not define the 'projects' data range. Bulk upload ABORTED. Original message: " + ex.Message; bulkUploadProccessed = false; if (connection.State == ConnectionState.Open) { connection.Close(); } } } catch (Exception ex) { if (!dataReader.IsClosed) { dataReader.Close(); } if (connection.State == ConnectionState.Open) { connection.Close(); } throw ex; } return (bulkUploadProccessed) ? true : false; }