//Inserting Karvy Staging Data to Profile Staging (IN USE) public bool KARVYStagingInsertToProfileStaging(int processId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { Package karvyProPkg2 = App.LoadPackage(Packagepath, null); karvyProPkg2.Variables["varProcessId"].Value = processId; karvyProPkg2.Variables["varProcessId1"].Value = processId; karvyProPkg2.Variables["varXMLFileType"].Value = 4; karvyProPkg2.Configurations[0].ConfigurationString = configPath; DTSExecResult karvyProResult2 = karvyProPkg2.Execute(); if (karvyProResult2.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "KarvyUploadsBo.cs:KARVYStagingInsertToProfileStaging()"); object[] objects = new object[2]; objects[0] = processId; objects[1] = Packagepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
public bool DeutscheInsertToInputTrans(int ProcessId, string PackagePath, string XMLFilePath, string ConfigPath) { bool IsProcessComplete = false; try { Package deutscheTranPkg1 = App.LoadPackage(PackagePath, null); deutscheTranPkg1.Variables["varXMLFilePath"].Value = XMLFilePath; deutscheTranPkg1.Variables["varProcessId"].Value = ProcessId; deutscheTranPkg1.ImportConfigurationFile(ConfigPath); DTSExecResult camsTranResult1 = deutscheTranPkg1.Execute(); if (camsTranResult1.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "DeutscheUploadsBo.cs:DeutscheInsertToInputTrans()"); object[] objects = new object[4]; objects[0] = PackagePath; objects[1] = XMLFilePath; objects[2] = ProcessId; objects[3] = ConfigPath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
public bool WERPEQProcessDataInSecondStagingTradeAccount(int processId, string Packagepath, string configPath, int adviserId) { bool blResult = false; try { Package werpEQTranPkg1 = App.LoadPackage(Packagepath, null); werpEQTranPkg1.Variables["varAdviserId"].Value = adviserId; werpEQTranPkg1.Variables["varProcessId"].Value = processId; werpEQTranPkg1.ImportConfigurationFile(configPath); DTSExecResult werpEQTranResult1 = werpEQTranPkg1.Execute(); if (werpEQTranResult1.ToString() == "Success") { blResult = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "WerpMFUploadsBo.cs:WerpMFInsertToInputProfile()"); object[] objects = new object[3]; objects[0] = processId; objects[1] = Packagepath; objects[2] = adviserId; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(blResult); }
//Transfer the Folio details from CAMS main staging to the Common Folio Staging public bool CAMSInsertFolioDataToFolioCommonStaging(int processId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { Package camsProPkg5 = App.LoadPackage(Packagepath, null); camsProPkg5.Variables["varProcessId"].Value = processId; camsProPkg5.Variables["varXMLFileTypeId"].Value = 2; camsProPkg5.ImportConfigurationFile(configPath); DTSExecResult camsProResult5 = camsProPkg5.Execute(); if (camsProResult5.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "CamsUploadsBo.cs:CAMSInsertFolioDataToFolioCommonStaging()"); object[] objects = new object[2]; objects[0] = processId; objects[1] = Packagepath; objects[2] = configPath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
//Fifthth Phase: Insert to Common Profile staging from std profil input public bool StdInsertToCommonStaging(int processId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { Package stdProPkg4 = App.LoadPackage(Packagepath, null); stdProPkg4.Variables["varProcessId"].Value = processId; stdProPkg4.ImportConfigurationFile(configPath); //stdProPkg2.Configurations[0].ConfigurationString = configPath; stdProPkg4.Variables["varXMLFileTypeId"].Value = 7; DTSExecResult stdProResult4 = stdProPkg4.Execute(); if (stdProResult4.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "StandardProfileUploadBo.cs:StdInsertToFirstStaging()"); object[] objects = new object[2]; objects[0] = processId; objects[1] = Packagepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
// Insert Data from First Staging to Second Staging public bool TempletonInsertFromTempStagingTransToCommonStaging(int processId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { Package tempProPkg2 = App.LoadPackage(Packagepath, null); tempProPkg2.Variables["varProcessId"].Value = processId; tempProPkg2.Variables["varXMLFileTypeId"].Value = 15; tempProPkg2.ImportConfigurationFile(configPath); DTSExecResult tempProResult2 = tempProPkg2.Execute(); if (tempProResult2.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "TempletonUploadsBo.cs:TempletonInsertFromTempStagingTransToCommonStaging()"); object[] objects = new object[3]; objects[0] = processId; objects[1] = Packagepath; objects[2] = configPath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
//Fifth Phase: Move good data to Tables public bool WERPMFInsertTransDetails(int processId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { Package WERPMFTranPkg4 = App.LoadPackage(Packagepath, null); WERPMFTranPkg4.Variables["varProcessId"].Value = processId; WERPMFTranPkg4.Variables["varDeleteStagingProcessId"].Value = processId; WERPMFTranPkg4.Configurations[0].ConfigurationString = configPath; DTSExecResult WERPMFTranResult4 = WERPMFTranPkg4.Execute(); if (WERPMFTranResult4.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "KarvyUploadBo.cs:WERPMFInsertTransDetails()"); object[] objects = new object[2]; objects[0] = processId; objects[1] = Packagepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
public bool MFFolioStagingCheck(string Packagepath, int adviserId, int processId, string configPath) { bool IsProcessComplete = false; try { Package stdProPkg1 = App.LoadPackage(Packagepath, null); stdProPkg1.Variables["varProcessId"].Value = processId; stdProPkg1.Variables["varAdviserId"].Value = adviserId; stdProPkg1.ImportConfigurationFile(configPath); DTSExecResult stdProResult1 = stdProPkg1.Execute(); if (stdProResult1.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "StandardFolioUploadBo.cs:StdFolioChksInFolioStaging()"); object[] objects = new object[1]; objects[0] = Packagepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
public bool DeutscheTransInsertToCommonTransStaging(int processId, int AdviserId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { Package deutscheTranPkg3 = App.LoadPackage(Packagepath, null); deutscheTranPkg3.Variables["varProcessId"].Value = processId; deutscheTranPkg3.ImportConfigurationFile(configPath); DTSExecResult camsTranResult3 = deutscheTranPkg3.Execute(); if (camsTranResult3.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "DeutscheUploadsBo.cs:DeutscheProcessDataInStagingTrans()"); object[] objects = new object[3]; objects[0] = processId; objects[1] = AdviserId; objects[2] = Packagepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
public bool WerpEQInsertToInputTransaction(string Packagepath, string XMLFilepath, string configPath) { bool blResult = false; try { Package werpEQTranPkg1 = App.LoadPackage(Packagepath, null); werpEQTranPkg1.Variables["varXMLFilePath"].Value = XMLFilepath; werpEQTranPkg1.ImportConfigurationFile(configPath); DTSExecResult werpEQTranResult1 = werpEQTranPkg1.Execute(); if (werpEQTranResult1.ToString() == "Success") { blResult = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "WerpMFUploadsBo.cs:WerpMFInsertToInputProfile()"); object[] objects = new object[2]; objects[0] = Packagepath; objects[1] = XMLFilepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(blResult); }
protected void Button4_Click(object sender, EventArgs e) { if (DropDownList1.SelectedItem.Text == "--Please select a pay period--") { Response.Write("<script LANGUAGE='JavaScript' >alert('Please select a Pay Period!')</script>"); DropDownList1.Focus(); } else { TextBox3.Text = ""; string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; //update TechOne employe postion table : string T1ToComCareEmployeePosition = ConfigurationManager.AppSettings["T1ToComCareEmployeePosition"].ToString(); // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); string fileName3 = Path.Combine(Server.MapPath("~/Upload"), "LoadT1EmployePosition.dtsx"); Package myPackage = myApplication.LoadPackage(@fileName3, null); myPackage.Variables["T1ServerFolder"].Value = T1ToComCareEmployeePosition; TextBox3.Text = TextBox3.Text + logtime + " == Starting updating TechOne employee position data...==\r\n"; DTSExecResult myResult = myPackage.Execute(); TextBox3.Text = TextBox3.Text + logtime + " == Updating result: " + myResult.ToString() + " == \r\n"; TextBox3.Text = TextBox3.Text + " ********** If Updating fail, please contact System Admin to check! ********** \r\n"; TextBox3.Text = TextBox3.Text + logtime + " \r\n"; // TextBox3.Text = ""; TextBox3.Text = TextBox3.Text + logtime + " == Begin to process and analysis the timesheet data == \r\n"; TextBox3.Text = TextBox3.Text + logtime + " == Need some time, please wait ...... == \r\n"; System.Threading.Thread.Sleep(2000); ShowProcessBar(); //execute sp to do data process string connStr = ConfigurationManager.ConnectionStrings["ASADWHConnectionString"].ConnectionString; SqlConnection connsql = new SqlConnection(connStr); if (connsql.State.ToString() == "Closed") { connsql.Open(); } SqlCommand Cmd = new SqlCommand("P_ComCare_Timesheet_ForT1_PastPayPeriod", connsql); Cmd.CommandTimeout = 0; Cmd.CommandType = CommandType.StoredProcedure; Cmd.Parameters.Add("@P_StartDay", SqlDbType.VarChar, 10).Value = DropDownList1.SelectedValue.ToString(); // Cmd.Parameters.Add("@P_EndDay", SqlDbType.VarChar, 10).Value = "2015-08-16".ToString(); try { Cmd.ExecuteNonQuery(); TextBox3.Text = TextBox3.Text + logtime + " == Data Process successfully! == \r\n"; GridView2.Visible = true; GridView2.DataBind(); //get all the records Int32 newRecordCount = 0; string connStrall = ConfigurationManager.ConnectionStrings["ASADWHConnectionString"].ConnectionString; SqlConnection connsqlall = new SqlConnection(connStrall); if (connsqlall.State.ToString() == "Closed") { connsqlall.Open(); } SqlCommand Cmdall = new SqlCommand("select count(*) from CC_T1_Timesheet_ReadforExport_withno", connsqlall); newRecordCount = (Int32)Cmdall.ExecuteScalar(); Label9.Visible = true; Label9.Text = "Data Process successfully! There are total # " + newRecordCount.ToString() + " # lines which will be exported."; if (newRecordCount < 2000) { TextBox4.Text = newRecordCount.ToString(); } else { TextBox4.Text = (newRecordCount / 5).ToString(); } } catch (Exception eee) { TextBox3.Text = TextBox3.Text + logtime + " == Data Process fial! [ERROR: " + eee.Message + "] == \r\n"; Label9.Visible = true; Label9.Text = "Data Process fail!"; } finally { connsql.Close(); } System.Threading.Thread.Sleep(500); ExitProcessBar(); } }
private void btnStart_Click(object sender, EventArgs e) { // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); // Load package from file system (use LoadFromSqlServer for SQL Server based packages) lblStatus.Text = "Loading package from file system."; Package myPackage = myApplication.LoadPackage(@"C:\Users\jvanrossum\OneDrive\Documenten\Extending SSIS with .Net\02_Code\2012\Extending SSIS with .NET\Chapter 21\Package.dtsx", null); // Optional set the value from one of the SSIS package variables myPackage.Variables["User::myVar"].Value = "test123"; // Execute package lblStatus.Text = "Executing package"; DTSExecResult myResult = myPackage.Execute(); // Show the execution result lblStatus.Text = "Package result: " + myResult.ToString(); // https://msdn.microsoft.com/en-us/library/ms136090(v=sql.120).aspx ////////////////////////////////////////// // Code for showing warnings and errors // ////////////////////////////////////////// // Create a temporary table to store warnings and errors DataTable myLogTable = new DataTable("myLogTable"); myLogTable.Columns.Add("LogTime", typeof(DateTime)); myLogTable.Columns.Add("Source", typeof(string)); myLogTable.Columns.Add("Message", typeof(string)); // Loop through all warnings and add them to the table foreach (DtsWarning packageWarning in myPackage.Warnings) { myLogTable.Rows.Add(Convert.ToDateTime(packageWarning.TimeStamp), packageWarning.Source, packageWarning.Description); } // Loop through all errors and add them to the table foreach (DtsError packageError in myPackage.Errors) { myLogTable.Rows.Add(Convert.ToDateTime(packageError.TimeStamp), packageError.Source, packageError.Description); } // Create a sorted view and then make a new datatable with it myLogTable.DefaultView.Sort = "LogTime"; DataTable myLogTableSorted = myLogTable.DefaultView.ToTable(); // Cleanup resource myLogTable.Dispose(); // Loop through the new sorted dataset and add rows to the listbox foreach (DataRow row in myLogTableSorted.Rows) { lbLog.Items.Add(row.Field <DateTime>(0).ToLongTimeString() + " - " + row.Field <string>(1) + " - " + row.Field <string>(2)); } // Cleanup resource myLogTableSorted.Dispose(); }
protected void Button1_Click1(object sender, EventArgs e) { string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; try { logtxt.Text = ""; // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); string fileName = Path.Combine(Server.MapPath("~/Upload"), "PPMP_ImportExceldataforXML-All.dtsx"); logtxt.Text = logtxt.Text + logtime + "Loading PPMP_ImportExceldataforXML-All.dtsx from server...\r\n"; string fileName2 = fileName.Replace(@"\", @"\\"); Package myPackage = myApplication.LoadPackage(fileName2, null); // Execute package logtxt.Text = logtxt.Text + logtime + "Executing package...\r\n"; DTSExecResult myResult = myPackage.Execute(); // Show the execution result logtxt.Text = logtxt.Text + logtime + "Package executed result: " + myResult.ToString() + " \r\n"; //check records in table PPMP_DEX_Client int r_no = 0; string connStr = ConfigurationManager.ConnectionStrings["DEX"].ConnectionString; SqlConnection connsql = new SqlConnection(connStr); try { if (connsql.State.ToString() == "Closed") { connsql.Open(); } //check financil transaction data (most types) string sqlstr = "SELECT count(*) from PPMP_DEX_Client "; SqlCommand Cmd = new SqlCommand(sqlstr, connsql); r_no = (int)Cmd.ExecuteScalar(); logtxt.Text = logtxt.Text + logtime + "Total records in PPMP_DEX_Client is :" + r_no.ToString() + " \r\n"; } catch (Exception eee) { logtxt.Text = logtxt.Text + logtime + "#Query From Database ERROR# " + eee.Message + " .Please try again!"; } finally { connsql.Close(); } //check records in table PPMP_cases int l_no = 0; SqlConnection connsql1 = new SqlConnection(connStr); try { if (connsql1.State.ToString() == "Closed") { connsql1.Open(); } //check financil transaction data (most types) string sqlstr = "SELECT count(*) from PPMP_cases "; SqlCommand Cmd = new SqlCommand(sqlstr, connsql1); l_no = (int)Cmd.ExecuteScalar(); logtxt.Text = logtxt.Text + logtime + "Total records in PPMP_cases is :" + l_no.ToString() + " \r\n"; } catch (Exception eee) { logtxt.Text = logtxt.Text + logtime + "#Query From Database ERROR# " + eee.Message + " .Please try again!"; } finally { connsql1.Close(); } //check records in table PPMP_session int g_no = 0; SqlConnection connsql2 = new SqlConnection(connStr); try { if (connsql2.State.ToString() == "Closed") { connsql2.Open(); } //check financil transaction data (most types) string sqlstr = "SELECT count(*) from PPMP_session "; SqlCommand Cmd = new SqlCommand(sqlstr, connsql2); g_no = (int)Cmd.ExecuteScalar(); logtxt.Text = logtxt.Text + logtime + "Total records in PPMP_session is :" + g_no.ToString() + " \r\n"; } catch (Exception eee) { logtxt.Text = logtxt.Text + logtime + "#Query From Database ERROR# " + eee.Message + " .Please try again!"; } finally { connsql2.Close(); } } catch (Exception ee) { logtxt.Text = logtime + "Package executed fail and Erros is: " + ee.Message + " \r\n"; } }
protected void Button1_Click1(object sender, EventArgs e) { string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; TextBox3.Text = ""; if (FileUpload1.HasFile) { try { //upload package file to web server TextBox3.Text = logtime + "Upload ComCare timesheet file to server...\r\n"; string fileName = Path.Combine(Server.MapPath("~/Upload"), FileUpload1.FileName); FileUpload1.SaveAs(fileName); TextBox3.Text = TextBox3.Text + logtime + "Upload timesheet file to server successfully.\r\n"; // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); string fileName3 = Path.Combine(Server.MapPath("~/Upload"), "LoadComCareTemesheet.dtsx"); // TextBox3.Text = TextBox3.Text+logtime + "Loading import package from file system...\r\n"; string fileName2 = fileName3.Replace(@"\", @"\\"); //string SSISLocation = "C:\\SSIS\\KyperaToTechone_TF.dtsx"; Package myPackage = myApplication.LoadPackage(@fileName2, null); // TextBox3.Text = TextBox3.Text + logtime + "Loading import package paramter name and value...\r\n"; // myPackage.Variables[TextBox1.Text].Value = TextBox2.Text; // Execute package TextBox3.Text = TextBox3.Text + logtime + "Starting loading timesheet file into data warehouse table...\r\n"; DTSExecResult myResult = myPackage.Execute(); // Show the execution result TextBox3.Text = TextBox3.Text + logtime + "Loading result: " + myResult.ToString() + " \r\n"; TextBox3.Text = TextBox3.Text + " =========Begin check the result========\r\n"; //check records in csv and database table //check csv files int ft_csv = 0; //手工指定 csv文件所在路径,需要修改 // string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\ASABIITool - Dev\\Upload';Extended Properties='text;HDR=Yes;FMT=Delimited'"); //连接数据。 Data Source为CSV文件存在的目录 string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Jerry Shen\\ASPnet\\ASABIITool - Dev2\\Upload';Extended Properties='text;HDR=Yes;FMT=Delimited'"); //连接数据。 Data Source为CSV文件存在的目录 OleDbConnection conn = new OleDbConnection(strConn); OleDbCommand comm1 = new OleDbCommand("select count(*) from [CURRENT_PA_EXPORT.csv]", conn); try { conn.Open(); ft_csv = (int)comm1.ExecuteScalar(); TextBox3.Text = TextBox3.Text + " == Begin to check results from Timesheet CSV files == \r\n"; TextBox3.Text = TextBox3.Text + " Total records in CURRENT_PA_EXPORT.csv is :" + ft_csv.ToString() + " \r\n"; TextBox3.Text = TextBox3.Text + " == Check CSV files finished == \r\n"; } catch (Exception ee) { TextBox3.Text = TextBox3.Text + " == Begin to check results from Timesheet CSV files == \r\n"; TextBox3.Text = TextBox3.Text + "#Read CSV File ERROR# " + ee.Message + " .Please try again!\r\n"; } finally { conn.Close(); } //check records in database querey int ft_db = 0; string connStr = ConfigurationManager.ConnectionStrings["ASADWHConnectionString"].ConnectionString; SqlConnection connsql = new SqlConnection(connStr); try { TextBox3.Text = TextBox3.Text + "\r\n"; TextBox3.Text = TextBox3.Text + " == Begin to check records using database query == \r\n"; if (connsql.State.ToString() == "Closed") { connsql.Open(); } //check financil transaction data (most types) string sqlstr = "SELECT count(*) from asadwh.dbo.CC_Timesheetfile_import "; SqlCommand Cmd = new SqlCommand(sqlstr, connsql); ft_db = (int)Cmd.ExecuteScalar(); TextBox3.Text = TextBox3.Text + "Total records in CC_Timesheetfile_import is :" + ft_db.ToString() + " \r\n"; TextBox3.Text = TextBox3.Text + " == Check database table finished == \r\n"; } catch (Exception eee) { TextBox3.Text = "#Query From Database ERROR# " + eee.Message + " .Please try again!"; } finally { connsql.Close(); } TextBox3.Text = TextBox3.Text + " =========Import Timsheet File Conclusion========= \r\n"; if (ft_db == ft_csv) { TextBox3.Text = TextBox3.Text + "[GOOD!]the Timesheet file records in CSV is the same with the ones got from database query \r\n"; } else { TextBox3.Text = TextBox3.Text + "[OOPS!]the Timesheet file records in CSV is not the same with the ones got from database query. Please check! \r\n"; } GridView1.Visible = true; GridView1.DataBind(); } catch (Exception ee) { TextBox3.Text = logtime + "Loading fail and Erros is: " + ee.Message + " \r\n"; } } else { ClientScript.RegisterStartupScript(this.GetType(), "SystemMessage", "alert('" + "Please select a timesheet file !" + "');", true); FileUpload1.Focus(); } }
public void execute_load_SSIS_package(string csvfilename, string payperiod) { GridView2.Visible = false; Label9.Visible = false; string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; //TextBox3.Text = ""; if (DropDownList1.SelectedItem.Text == "--Please select a pay period--") { Response.Write("<script LANGUAGE='JavaScript' >alert('Please select a Pay Period!')</script>"); DropDownList1.Focus(); } else { try { string fileserverfolder = ConfigurationManager.AppSettings["ComCareTimesheetServerFolder"].ToString(); // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); string fileName3 = Path.Combine(Server.MapPath("~/Upload"), "LoadComCareTemesheetforallfiles.dtsx"); // TextBox3.Text = TextBox3.Text+logtime + "Loading import package from file system...\r\n"; string fileName2 = fileName3.Replace(@"\", @"\\"); //string SSISLocation = "C:\\SSIS\\KyperaToTechone_TF.dtsx"; Package myPackage = myApplication.LoadPackage(@fileName2, null); myPackage.Variables["LoadFolder"].Value = fileserverfolder.Replace(@"\\", @"\"); myPackage.Variables["Filename"].Value = csvfilename; myPackage.Variables["payperiod"].Value = payperiod; TextBox3.Text = TextBox3.Text + logtime + "Starting loading timesheet file [ " + csvfilename + " ]into data warehouse table...\r\n"; ShowProcessBar(); DTSExecResult myResult = myPackage.Execute(); // Show the execution result TextBox3.Text = TextBox3.Text + logtime + "Loading result: " + myResult.ToString() + " \r\n"; System.Threading.Thread.Sleep(2000); ExitProcessBar(); TextBox3.Text = TextBox3.Text + " =========Begin check the result========\r\n"; //check records in csv and database table //check csv files int ft_csv = 0; string fileserverfolder22 = fileserverfolder.Replace(@"\\", @"\"); string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='text;HDR=Yes;FMT=Delimited'", fileserverfolder22); OleDbConnection conn = new OleDbConnection(strConn); OleDbCommand comm1 = new OleDbCommand("select count(*) from [" + csvfilename + "]", conn); try { conn.Open(); ft_csv = (int)comm1.ExecuteScalar(); TextBox3.Text = TextBox3.Text + " == Begin to check results from Timesheet CSV files == \r\n"; TextBox3.Text = TextBox3.Text + " Total records in " + csvfilename + " is :" + ft_csv.ToString() + " \r\n"; TextBox3.Text = TextBox3.Text + " == Check CSV files finished == \r\n"; } catch (Exception ee) { TextBox3.Text = TextBox3.Text + " == Begin to check results from Timesheet CSV files == \r\n"; TextBox3.Text = TextBox3.Text + "#Read CSV File ERROR# " + ee.Message + " .Please try again!\r\n"; } finally { conn.Close(); } //check records in database querey int ft_db = 0; string connStr = ConfigurationManager.ConnectionStrings["ASADWHConnectionString"].ConnectionString; SqlConnection connsql = new SqlConnection(connStr); try { TextBox3.Text = TextBox3.Text + "\r\n"; TextBox3.Text = TextBox3.Text + " == Begin to check records using database query == \r\n"; if (connsql.State.ToString() == "Closed") { connsql.Open(); } //check financil transaction data (most types) string sqlstr = "SELECT count(*) from asadwh.dbo.CC_Timesheetfile_import_new where filename='" + csvfilename + "' and payperiod ='" + payperiod + "' "; SqlCommand Cmd = new SqlCommand(sqlstr, connsql); ft_db = (int)Cmd.ExecuteScalar(); TextBox3.Text = TextBox3.Text + "Total records in " + csvfilename + " is :" + ft_db.ToString() + " \r\n"; TextBox3.Text = TextBox3.Text + " == Check database table finished == \r\n"; } catch (Exception eee) { TextBox3.Text = "#Query From Database ERROR# " + eee.Message + " .Please try again!"; } finally { connsql.Close(); } TextBox3.Text = TextBox3.Text + " =========Import Timsheet File Conclusion========= \r\n"; if (ft_db == ft_csv) { TextBox3.Text = TextBox3.Text + "[GOOD!]the Timesheet file records in CSV is the same with the ones got from database query \r\n"; } else { TextBox3.Text = TextBox3.Text + "[OOPS!]the Timesheet file records in CSV is not the same with the ones got from database query. Please check! \r\n"; } } catch (Exception ee) { TextBox3.Text = logtime + "Loading fail and Erros is: " + ee.Message + " \r\n"; } } }
protected void Button1_Click1(object sender, EventArgs e) { GridView2.Visible = false; Label9.Visible = false; string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; TextBox3.Text = ""; if (DropDownList1.SelectedItem.Text == "--Please select a pay period--") { Response.Write("<script LANGUAGE='JavaScript' >alert('Please select a Pay Period!')</script>"); DropDownList1.Focus(); } else { if (FileUpload1.HasFile) { try { string SSIS_UploadFolder = ConfigurationManager.AppSettings["SSIS_UploadFolder_CIM"].ToString(); //upload package file to web server TextBox3.Text = logtime + "Upload ComCare timesheet file to server...\r\n"; // string fileName = Path.Combine(Server.MapPath("~/Upload"), FileUpload1.FileName); // FileUpload1.SaveAs("\\\\clank\\COMCARETEST\\CCToCIM\\Upload\\" + FileUpload1.FileName); string ComCareTimesheetUpload = ConfigurationManager.AppSettings["ComCareTimesheetUpload-Stage"].ToString(); FileUpload1.SaveAs(ComCareTimesheetUpload + FileUpload1.FileName); TextBox3.Text = TextBox3.Text + logtime + "Upload timesheet file to server successfully.\r\n"; // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); string fileName3 = Path.Combine(Server.MapPath("~/Upload"), "LoadComCareTemesheet.dtsx"); // TextBox3.Text = TextBox3.Text+logtime + "Loading import package from file system...\r\n"; string fileName2 = fileName3.Replace(@"\", @"\\"); //string SSISLocation = "C:\\SSIS\\KyperaToTechone_TF.dtsx"; Package myPackage = myApplication.LoadPackage(@fileName2, null); myPackage.Variables["LoadFolder"].Value = SSIS_UploadFolder; // TextBox3.Text = TextBox3.Text + logtime + "Loading import package paramter name and value...\r\n"; // myPackage.Variables[TextBox1.Text].Value = TextBox2.Text; // Execute package TextBox3.Text = TextBox3.Text + logtime + "Starting loading timesheet file into data warehouse table...\r\n"; ShowProcessBar(); DTSExecResult myResult = myPackage.Execute(); // Show the execution result TextBox3.Text = TextBox3.Text + logtime + "Loading result: " + myResult.ToString() + " \r\n"; System.Threading.Thread.Sleep(2000); ExitProcessBar(); TextBox3.Text = TextBox3.Text + " =========Begin check the result========\r\n"; //check records in csv and database table //check csv files int ft_csv = 0; //手工指定 csv文件所在路径,需要修改 // string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\\Jerry Shen\\ASPnet\\ASABIITool - Dev2\\Upload';Extended Properties='text;HDR=Yes;FMT=Delimited'"); //连接数据。 Data Source为CSV文件存在的目录 // string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\\\clank\\COMCARETEST\\CCToCIM\\Upload';Extended Properties='text;HDR=Yes;FMT=Delimited'"); //连接数据。 Data Source为CSV文件存在的目录 string ComCareTimesheetUpload_csv = ConfigurationManager.AppSettings["ComCareTimesheetUpload-csv"].ToString(); string strConn = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='text;HDR=Yes;FMT=Delimited'", ComCareTimesheetUpload_csv); //连接数据。 Data Source为CSV文件存在的目录 OleDbConnection conn = new OleDbConnection(strConn); OleDbCommand comm1 = new OleDbCommand("select count(*) from [CURRENT_PA_EXPORT.csv]", conn); try { conn.Open(); ft_csv = (int)comm1.ExecuteScalar(); TextBox3.Text = TextBox3.Text + " == Begin to check results from Timesheet CSV files == \r\n"; TextBox3.Text = TextBox3.Text + " Total records in CURRENT_PA_EXPORT.csv is :" + ft_csv.ToString() + " \r\n"; TextBox3.Text = TextBox3.Text + " == Check CSV files finished == \r\n"; } catch (Exception ee) { TextBox3.Text = TextBox3.Text + " == Begin to check results from Timesheet CSV files == \r\n"; TextBox3.Text = TextBox3.Text + "#Read CSV File ERROR# " + ee.Message + " .Please try again!\r\n"; } finally { conn.Close(); } //check records in database querey int ft_db = 0; string connStr = ConfigurationManager.ConnectionStrings["ASADWHConnectionString"].ConnectionString; SqlConnection connsql = new SqlConnection(connStr); try { TextBox3.Text = TextBox3.Text + "\r\n"; TextBox3.Text = TextBox3.Text + " == Begin to check records using database query == \r\n"; if (connsql.State.ToString() == "Closed") { connsql.Open(); } //check financil transaction data (most types) string sqlstr = "SELECT count(*) from asadwh.dbo.CC_Timesheetfile_import where p_orders=1 "; SqlCommand Cmd = new SqlCommand(sqlstr, connsql); ft_db = (int)Cmd.ExecuteScalar(); TextBox3.Text = TextBox3.Text + "Total records in CC_Timesheetfile_import is :" + ft_db.ToString() + " \r\n"; TextBox3.Text = TextBox3.Text + " == Check database table finished == \r\n"; } catch (Exception eee) { TextBox3.Text = "#Query From Database ERROR# " + eee.Message + " .Please try again!"; } finally { connsql.Close(); } TextBox3.Text = TextBox3.Text + " =========Import Timsheet File Conclusion========= \r\n"; if (ft_db == ft_csv) { TextBox3.Text = TextBox3.Text + "[GOOD!]the Timesheet file records in CSV is the same with the ones got from database query \r\n"; //move file to archive TextBox3.Text = TextBox3.Text + logtime + "Start to move the timsheet file to archive folder.... \r\n"; string fileNameSer = "CURRENT_PA_EXPORT.csv"; string dateString = DateTime.Now.ToLocalTime().ToString(); string dateString1 = dateString.Replace("/", ""); string dateString2 = dateString1.Replace(" ", ""); string dateString3 = dateString2.Replace(":", ""); string filenameDes = "CURRENT_PA_EXPORT" + dateString3 + ".csv"; string ComCareTimesheetServerFolder = ConfigurationManager.AppSettings["ComCareTimesheetServerFolder"].ToString(); string ComCareTimesheetServerArchiveFolder = ConfigurationManager.AppSettings["ComCareTimesheetServerArchiveFolder"].ToString(); // string sourcePath = @"\\\\clank\\comcaretest\\Payroll"; // string targetPath = @"\\\\clank\\comcaretest\\Payroll\\Archive"; string sourcePath = @ComCareTimesheetServerFolder; string targetPath = @ComCareTimesheetServerArchiveFolder; // Use Path class to manipulate file and directory paths. string sourceFile = System.IO.Path.Combine(sourcePath, fileNameSer); string destFile = System.IO.Path.Combine(targetPath, filenameDes); // To copy a file to another location and // overwrite the destination file if it already exists. try { System.IO.File.Copy(sourceFile, destFile, true); //delete from origial file try { System.IO.File.Delete(sourceFile); TextBox3.Text = TextBox3.Text + logtime + "Finish moving the timsheet file to archive folder...."; Button5.Enabled = true; } catch (Exception e3) { TextBox3.Text = TextBox3.Text + logtime + "#Delete file fail and ERROR is: # " + e3.Message + " .Please try again!"; } } catch (Exception eeee) { TextBox3.Text = TextBox3.Text + logtime + "#Move file fail and ERROR is: # " + eeee.Message + " .Please try again!"; } } else { TextBox3.Text = TextBox3.Text + "[OOPS!]the Timesheet file records in CSV is not the same with the ones got from database query. Please check! \r\n"; } GridView1.Visible = true; GridView1.DataBind(); } catch (Exception ee) { TextBox3.Text = logtime + "Loading fail and Erros is: " + ee.Message + " \r\n"; } } else { ClientScript.RegisterStartupScript(this.GetType(), "SystemMessage", "alert('" + "Please select a timesheet file !" + "');", true); FileUpload1.Focus(); } } }
/// <summary> /// Execute the setup, asserts, and teardown associated with this test. /// </summary> /// <returns>True if the test was executed with no errors, false if it encountered errors.</returns> public bool Execute(Context context) { _packageErrors = new List <string>(); var testLog = new Log { ItemName = string.Format(CultureInfo.CurrentCulture, "Test: {0}", this.Name) }; context.Log.Find(new Log { ItemName = "TestSuite" }).Add(testLog); testLog.Messages.Add("Test Started"); OnRaiseTestStarted(new TestStartedEventArgs()); TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestCount); bool returnValue = false; object loadedProject = null; try { Package packageToTest; DtsContainer taskHost; try { LoadPackageAndTask(PackageLocation, StoredPassword, ProjectLocation, Task, out packageToTest, out taskHost, out loadedProject); } catch (Exception) { TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestFailedCount); throw; } InternalPackage = packageToTest; string setupResults = string.Empty; bool setupSucceeded; _taskName = taskHost.Name; var setupLog = new Log(); context.Log.Find(testLog).Add(setupLog); setupLog.ItemName = string.Format(CultureInfo.CurrentCulture, "{0} Setup", Name); try { ExecuteCommandSet(TestSuite.SetupCommands, loadedProject, packageToTest, taskHost); ExecuteCommandSet(TestSetup, loadedProject, packageToTest, taskHost); setupResults = "Setup succeeded."; setupLog.Messages.Add(setupResults); setupSucceeded = true; } catch (Exception ex) { setupResults = "Setup failed: " + ex.Message; setupLog.Messages.Add(string.Format(CultureInfo.CurrentCulture, "Setup failed: {0}", ex)); if (ex.InnerException != null) { setupResults += " : " + ex.InnerException; } setupSucceeded = false; TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestFailedCount); } finally { TestSuite.OnRaiseSetupCompleted(new SetupCompletedEventArgs(DateTime.Now, Name, PackageLocation, _taskName, setupResults)); } if (!setupSucceeded) { return(false); } string resultMessage = string.Empty; var preExecAssertLog = new Log(); context.Log.Find(testLog).Add(preExecAssertLog); preExecAssertLog.ItemName = string.Format(CultureInfo.CurrentCulture, "{0} Pre Execution Asserts", Name); var execLog = new Log(); context.Log.Find(testLog).Add(execLog); execLog.ItemName = string.Format(CultureInfo.CurrentCulture, "{0} Task Execution", Name); var assertLog = new Log(); context.Log.Find(testLog).Add(assertLog); assertLog.ItemName = string.Format(CultureInfo.CurrentCulture, "{0} Post Execution Asserts", Name); try { // Pre execution Asserts ProcessAsserts(loadedProject, packageToTest, taskHost, true, preExecAssertLog); var events = new SsisEvents(_packageErrors); #if SQL2012 || SQL2014 || SQL2017 if (packageToTest.Project != null) { packageToTest.Project.EnsureConnectionsAreLoaded(); } #endif taskHost.Execute(packageToTest.Connections, taskHost.Variables, events, null, null); DTSExecResult result = taskHost.ExecutionResult; TestSuite.Statistics.IncrementStatistic(StatisticEnum.AssertCount); if (TaskResult == DTSExecResult.Success) { // User expects success if (result == TaskResult) { if (_packageErrors.Count > 0) { TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, "Task Completed: There were validation or execution errors.", false))); TestSuite.Statistics.IncrementStatistic(StatisticEnum.AssertFailedCount); foreach (var packageError in _packageErrors) { execLog.Messages.Add(string.Format("Package Error: {0}.", packageError)); TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, "Task Error: " + packageError.Replace(Environment.NewLine, string.Empty), false))); } } else { execLog.Messages.Add( string.Format( "Task Execution: Actual result ({0}) was equal to the expected result ({1}).", result, TaskResult)); TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, string.Format( "Task Completed: Actual result ({0}) was equal to the expected result ({1}).", result, TaskResult), true))); TestSuite.Statistics.IncrementStatistic(StatisticEnum.AssertPassedCount); // Post Execution Asserts ProcessAsserts(loadedProject, packageToTest, taskHost, false, assertLog); resultMessage = "All asserts were completed."; returnValue = true; TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestPassedCount); } } else { execLog.Messages.Add(string.Format("Task Execution: Actual result ({0}) was not equal to the expected result ({1}).", result, TaskResult)); foreach (var packageError in _packageErrors) { execLog.Messages.Add(string.Format("Package Error: {0}.", packageError)); } TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, string.Format("Task Completed: Actual result ({0}) was not equal to the expected result ({1}).", result.ToString(), TaskResult.ToString()), false))); TestSuite.Statistics.IncrementStatistic(StatisticEnum.AssertFailedCount); foreach (DtsError err in packageToTest.Errors) { execLog.Messages.Add(string.Format("Package Error: {0}.", err.Description)); TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, "Task Error: " + err.Description.Replace(Environment.NewLine, string.Empty), false))); } resultMessage = "The task " + _taskName + " did not execute successfully."; TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestFailedCount); } } if (TaskResult == DTSExecResult.Failure) { // User expects failure if (result == TaskResult || _packageErrors.Count > 0) { execLog.Messages.Add( string.Format( "Task Execution: Actual result ({0}) was equal to the expected result ({1}).", result, TaskResult)); TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, string.Format( "Task Completed: Actual result ({0}) was equal to the expected result ({1}).", result, TaskResult), true))); TestSuite.Statistics.IncrementStatistic(StatisticEnum.AssertPassedCount); // Post Execution Asserts ProcessAsserts(loadedProject, packageToTest, taskHost, false, assertLog); resultMessage = "All asserts were completed."; returnValue = true; TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestPassedCount); } else { execLog.Messages.Add(string.Format("Task Execution: Actual result ({0}) was not equal to the expected result ({1}).", result, TaskResult)); foreach (var packageError in _packageErrors) { execLog.Messages.Add(string.Format("Package Error: {0}.", packageError)); } TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, string.Format("Task Completed: Actual result ({0}) was not equal to the expected result ({1}).", result.ToString(), TaskResult.ToString()), false))); TestSuite.Statistics.IncrementStatistic(StatisticEnum.AssertFailedCount); foreach (DtsError err in packageToTest.Errors) { execLog.Messages.Add(string.Format("Package Error: {0}.", err.Description)); TestSuite.OnRaiseAssertCompleted(new AssertCompletedEventArgs(null, new TestResult(DateTime.Now, PackageLocation, _taskName, Name, "Task Error: " + err.Description.Replace(Environment.NewLine, string.Empty), false))); } resultMessage = "The task " + _taskName + " did not execute successfully."; TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestFailedCount); } } } catch (Exception ex) { TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestFailedCount); returnValue = false; resultMessage = "Exception occurred: " + ex.Message; } finally { TestSuite.OnRaiseTestCompleted(new TestCompletedEventArgs(DateTime.Now, PackageLocation, _taskName, Name, resultMessage, returnValue)); } if (!returnValue) { return(false); } string teardownResults = string.Empty; try { ExecuteCommandSet(TestTeardown, loadedProject, packageToTest, taskHost); ExecuteCommandSet(TestSuite.TeardownCommands, loadedProject, packageToTest, taskHost); teardownResults = "Teardown succeeded."; } catch (Exception ex) { teardownResults = "Teardown failed: " + ex.Message; if (ex.InnerException != null) { teardownResults += " : " + ex.InnerException; } returnValue = false; TestSuite.Statistics.IncrementStatistic(StatisticEnum.TestFailedCount); } finally { TestSuite.OnRaiseTeardownCompleted(new TeardownCompletedEventArgs(DateTime.Now, Name, PackageLocation, _taskName, teardownResults)); } return(returnValue); } finally { #if SQL2012 || SQL2014 || SQL2017 Project project = loadedProject as Project; if (project != null) { project.Dispose(); } #else loadedProject = null; #endif OnRaiseTestCompleted(new TestCompletedEventArgs(DateTime.Now, PackageLocation, _taskName, Name, string.Format("The {0} unit test has completed.", Name), returnValue)); } }
protected void SSISExport(string filename, int startno, int endno) { string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; //invoke ssis package to export string fileserverfolder = ConfigurationManager.AppSettings["CCToT1Manyfiles"].ToString(); // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); string fileName3 = Path.Combine(Server.MapPath("~/Upload"), "ComCareTimesheetToT1Cianywhere_severalfiles.dtsx"); // TextBox3.Text = TextBox3.Text+logtime + "Loading import package from file system...\r\n"; Package myPackage = myApplication.LoadPackage(@fileName3, null); myPackage.Variables["filefolder"].Value = fileserverfolder; myPackage.Variables["filename"].Value = filename; myPackage.Variables["startno"].Value = startno; myPackage.Variables["endno"].Value = endno; TextBox3.Text = TextBox3.Text + logtime + " Starting to export timesheet data to file: " + filename + "...\r\n"; ShowProcessBar(); try { DTSExecResult myResult = myPackage.Execute(); // Show the execution result TextBox3.Text = TextBox3.Text + logtime + " " + filename + " export result: " + myResult.ToString() + " \r\n"; } catch (Exception ex) { TextBox3.Text = TextBox3.Text + logtime + "Load fail and ERROR is :" + ex.Message; } finally { myPackage.Dispose(); myPackage = null; } }
protected void Button1_Click1(object sender, EventArgs e) { string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; TextBox3.Text = ""; if (FileUpload1.HasFile) { if (CheckBox1.Checked == true) { if (TextBox1.Text == "") { ClientScript.RegisterStartupScript(this.GetType(), "SystemMessage", "alert('Parameter name and value cannot be NULL');", true); TextBox1.Focus(); } else { try { //upload package file to web server TextBox3.Text = logtime + "Uploade package file to server...\r\n"; string fileName = Path.Combine(Server.MapPath("~/Upload"), FileUpload1.FileName); TextBox3.Text = FileUpload1.FileName; FileUpload1.SaveAs(fileName); TextBox3.Text = TextBox3.Text + logtime + "Upload package file to server successfully.\r\n"; // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); TextBox3.Text = TextBox3.Text + logtime + "Loading package from file system...\r\n"; string fileName2 = fileName.Replace(@"\", @"\\"); //string SSISLocation = "C:\\SSIS\\KyperaToTechone_TF.dtsx"; Package myPackage = myApplication.LoadPackage(@fileName2, null); TextBox3.Text = TextBox3.Text + logtime + "Loading package paramter name and value...\r\n"; myPackage.Variables[TextBox1.Text].Value = TextBox2.Text; // Execute package TextBox3.Text = TextBox3.Text + logtime + "Executing package...\r\n"; DTSExecResult myResult = myPackage.Execute(); // Show the execution result TextBox3.Text = TextBox3.Text + logtime + "Package executed result: " + myResult.ToString() + " \r\n"; } catch (Exception ee) { TextBox3.Text = logtime + "Package executed fail and Erros is: " + ee.Message + " \r\n"; } } } else { try { //upload package file to web server TextBox3.Text = logtime + "Uploade package file to server...\r\n"; string fileName = Path.Combine(Server.MapPath("~/Upload"), FileUpload1.FileName); FileUpload1.SaveAs(fileName); TextBox3.Text = TextBox3.Text + logtime + "Upload package file to server successfully.\r\n"; Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); TextBox3.Text = TextBox3.Text + logtime + "Loading package from file system...\r\n"; string fileName2 = fileName.Replace(@"\", @"\\"); // string SSISLocation = "C:\\SSIS\\KyperaToTechone_TF.dtsx"; Package myPackage = myApplication.LoadPackage(@fileName2, null); // Execute package TextBox3.Text = TextBox3.Text + logtime + "Executing package...\r\n"; DTSExecResult myResult = myPackage.Execute(); // Show the execution result TextBox3.Text = TextBox3.Text + logtime + "Package executed result: " + myResult.ToString() + " \r\n"; } catch (Exception ee) { TextBox3.Text = logtime + "Package executed fail and Erros is: " + ee.Message + " \r\n"; } } } else { ClientScript.RegisterStartupScript(this.GetType(), "SystemMessage", "alert('" + "Please select a SSIS package file !" + "');", true); FileUpload1.Focus(); } }
private void timer_Tick(object sender, EventArgs e) { try { //set path folder import files . string path = txtImportFolder.Text; string path_package = txtPathPackage.Text; //scan file in directory realtime ---------------- string file_scan_directory_realtime = scan_file_in_directory(path); if (file_scan_directory_realtime != null) { var_info_log = var_info_log + "Time: " + DateTime.Now.ToString() + " - "; var_info_log = var_info_log + "File: " + file_scan_directory_realtime + "\n"; var_info_log = var_info_log + "-----------------------------------------------------------------------------------------------------------------------------------------------------------\n"; // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); // Load package from file system (use LoadFromSqlServer for SQL Server based packages) var_info_log = var_info_log + "Loading package from file system." + "\n"; txtShowLogs.Text = var_info_log; if (file_scan_directory_realtime.ToUpper().Contains("OWNER") == true) { url_packages = System.IO.Path.Combine(path_package, "OWNER.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("BRANCH") == true) { url_packages = System.IO.Path.Combine(path_package, "BRANCH.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("CUSTOMER") == true) { url_packages = System.IO.Path.Combine(path_package, "CUSTOMER.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("ACCOUNT") == true) { url_packages = System.IO.Path.Combine(path_package, "ACCOUNT.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("ACCOUNT-TYPE") == true) { url_packages = System.IO.Path.Combine(path_package, "ACCOUNT-TYPE.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("EMPLOYEE") == true) { url_packages = System.IO.Path.Combine(path_package, "EMPLOYEE.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("POSITION-EMP") == true) { url_packages = System.IO.Path.Combine(path_package, "POSITION-EMP.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("SAVINGS-ACCOUNT") == true) { url_packages = System.IO.Path.Combine(path_package, "SAVINGS-ACCOUNT.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("TRANSACTION") == true) { url_packages = System.IO.Path.Combine(path_package, "TRANSACTION.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("TRANSACTION-TYPES") == true) { url_packages = System.IO.Path.Combine(path_package, "TRANSACTION-TYPES.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("TYPE-SAVINGS-ACCOUNT") == true) { url_packages = System.IO.Path.Combine(path_package, "TYPE-SAVINGS-ACCOUNT.dtsx"); } else if (file_scan_directory_realtime.ToUpper().Contains("SAVINGS-ACCOUNT") == true) { url_packages = System.IO.Path.Combine(path_package, "SAVINGS-ACCOUNT.dtsx"); } else { url_packages = null; }; //Package myPackage = myApplication.LoadPackage(txtPathPackage.Text, null); Package myPackage = myApplication.LoadPackage(url_packages, null); // Optional set the value from one of the SSIS package variables myPackage.Variables["User::file_path_import"].Value = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + System.IO.Path.Combine(path, file_scan_directory_realtime) + @";Extended Properties=""Excel 8.0;HDR=YES"";"; // Execute package var_info_log = var_info_log + "Executing package" + "\n"; txtShowLogs.Text = var_info_log; DTSExecResult myResult = myPackage.Execute(); //if (myResult == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure) //{ // foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in myPackage.Errors) // { // MessageBox.Show(local_DtsError.Description); // } //} // Show the execution result var_info_log = var_info_log + "Package result: " + myResult.ToString() + "\n\n"; var_info_log_sort = var_info_log + var_info_log_sort; var_info_log = ""; if (myResult.ToString().ToUpper() == "Success".ToUpper()) { string sourceFile = System.IO.Path.Combine(path, file_scan_directory_realtime); string destinationFile = System.IO.Path.Combine(path, "MOVE", file_scan_directory_realtime); if (System.IO.File.Exists(destinationFile)) { System.IO.File.Delete(destinationFile); } // To move a file or folder to a new location: System.IO.File.Move(sourceFile, destinationFile); } else { //msg error and write log file ------------------- string sourceFile = System.IO.Path.Combine(path, file_scan_directory_realtime); string destinationFile = System.IO.Path.Combine(path, "ERROR", file_scan_directory_realtime); if (System.IO.File.Exists(destinationFile)) { System.IO.File.Delete(destinationFile); } // To move a file or folder to a new location: System.IO.File.Move(sourceFile, destinationFile); foreach (Microsoft.SqlServer.Dts.Runtime.DtsError local_DtsError in myPackage.Errors) { //MessageBox.Show(local_DtsError.Description); var_info_log = var_info_log + "Error: " + local_DtsError.Description + "\n\n"; var_info_log_sort = var_info_log + var_info_log_sort; var_info_log = ""; } } txtShowLogs.Text = var_info_log_sort; } } catch (Exception) { throw; } }
//Fourth Phase: Checks and setting of flags in the WerpMF staging table public bool WerpMFProcessDataInStagingProfile(int processId, int AdviserId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { string query1 = "UPDATE CustomerMFXtrnlProfileStaging SET CMFXPS_IsCustomerNew = 0 , C_CustomerId = B.C_CustomerId " + "FROM CustomerMFXtrnlProfileStaging A " + "INNER JOIN Customer B " + "ON A.CMFXPS_PANNum = B.C_PANNum " + "INNER JOIN AdviserRM C " + "ON B.AR_RMId = C.AR_RMId " + "WHERE C.A_AdviserId = " + AdviserId + " and A.ADUL_ProcessId =" + processId; string query2 = "UPDATE CustomerMFXtrnlProfileStaging SET CMFXPS_IsFolioNew = 0 , CMFA_AccountId = B.CMFA_AccountId " + "FROM CustomerMFXtrnlProfileStaging A " + "INNER JOIN CustomerMutualFundAccount B " + "ON A.CMFXPS_FolioNum = B.CMFA_FolioNum AND A.PA_AMCCode = B.PA_AMCCode " + "INNER JOIN CustomerPortfolio C " + "ON B.CP_PortfolioId = C.CP_PortfolioId " + "INNER JOIN Customer D " + "ON C.C_CustomerId = D.C_CustomerId " + "INNER JOIN AdviserRM E " + "ON D.AR_RMId = E.AR_RMId " + "WHERE E.A_AdviserId =" + AdviserId + " and A.ADUL_ProcessID =" + processId; Package werpMFProPkg3 = App.LoadPackage(Packagepath, null); werpMFProPkg3.Variables["varQueryCustomerCheck"].Value = query1; werpMFProPkg3.Variables["varQueryFolioCheck"].Value = query2; werpMFProPkg3.Variables["varProcessIdPanNullCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdTypeCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdSubTypeCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdQualificationCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdOccupationCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdNationalityCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdMaritalStatusCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdFolioModeOfOperatingCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdBankModeOfOperationCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdBankAccountTypeCheck"].Value = processId; werpMFProPkg3.Variables["varProcessIdAMCCheck"].Value = processId; DTSExecResult werpMFProResult3 = werpMFProPkg3.Execute(); if (werpMFProResult3.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "WerpMFUploadsBo.cs:WerpMFProcessDataInStagingProfile()"); object[] objects = new object[3]; objects[0] = processId; objects[1] = AdviserId; objects[2] = Packagepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }
private static void TimerEventProcessor(Object myObject, EventArgs myEventArgs) { myTimer.Stop(); //// Displays a message box asking whether to continue running the timer. //if (MessageBox.Show("Continue running?", "Count is: ", // MessageBoxButtons.YesNo) == DialogResult.Yes) //{ // // Restarts the timer and increments the counter. // //alarmCounter += 1; // myTimer.Enabled = true; //} //else //{ // // Stops the timer. // exitFlag = true; //} // Instantiate SSIS application object // string path_fileimport = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Package\Import"); string path_fileimport_success = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Package\Import\success"); string path_fileimport_failure = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Package\Import\failure"); string path_filepackage = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Package\Package\Package\Package.dtsx"); //string[] files = File.ReadAllLines(path); // string[] filePahts = System.IO.Directory.GetFiles(path_fileimport, "*.txt"); //MessageBox.Show(path_fileimport); if (filePahts.Length != 0) { Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); // Load package from file system (use LoadFromSqlServer for SQL Server based packages) //lblStatus.Text = "Loading package from file system."; Package myPackage = myApplication.LoadPackage(path_filepackage, null); // Optional set the value from one of the SSIS package variables myPackage.Variables["File_import_path"].Value = filePahts[0]; // Execute package //lblStatus.Text = "Executing package"; DTSExecResult myResult = myPackage.Execute(); // Show the execution result //lblStatus.Text = "Package result: " + myResult.ToString(); //MessageBox.Show(myResult.ToString()); // Check Success and move file folder if (myResult.ToString().Equals("Success")) { //move file -> folder success string fileName = Path.GetFileName(filePahts[0]); //filePahts[0] = filePahts[0] + "123123"; File.Move(filePahts[0], path_fileimport_success + @"\" + fileName); } else if (!myResult.ToString().Equals("Success")) { string fileName = Path.GetFileName(filePahts[0]); //filePahts[0] = filePahts[0] + "123123"; File.Move(filePahts[0], path_fileimport_failure + @"\" + fileName); } // MessageBox.Show(filePahts.Length.ToString()); } myTimer.Enabled = true; }
protected void Button1_Click1(object sender, EventArgs e) { string logtime = "[ " + DateTime.Now.ToLocalTime().ToString() + " ]"; //get the yyyymmdd format date from canlendar string rundate = Calendar1.SelectedDate.ToShortDateString(); string sdate = ""; string smonth = ""; string syear = ""; string newrundate = ""; if (rundate.Length == 9) { sdate = "0" + rundate.Substring(0, 1); smonth = rundate.Substring(2, 2); syear = rundate.Substring(5, 4); newrundate = syear + smonth + sdate; } else { sdate = rundate.Substring(0, 2); smonth = rundate.Substring(3, 2); syear = rundate.Substring(6, 4); newrundate = syear + smonth + sdate; } if (newrundate == "00010101") { // ClientScript.RegisterStartupScript(this.GetType(), "SystemMessage", "alert('You didn't selete a date & Please click the Calendar's date. Thanks!');", true); TextBox3.Text = "[ALERT]You didn't selete a date & Please click the Calendar to select a runing date. Thanks!"; } else { //execute the package for kyperatotechone try { // Instantiate SSIS application object Microsoft.SqlServer.Dts.Runtime.Application myApplication = new Microsoft.SqlServer.Dts.Runtime.Application(); string fileName = Path.Combine(Server.MapPath("~/Upload"), "JOB_KyperaToTechone_Inputdate.dtsx"); TextBox3.Text = TextBox3.Text + logtime + "Loading JOB_KyperaToTechone_Inputdate.dtsx from server...\r\n"; string fileName2 = fileName.Replace(@"\", @"\\"); Package myPackage = myApplication.LoadPackage(@fileName2, null); TextBox3.Text = TextBox3.Text + logtime + "Loading package paramter - rundate...\r\n"; myPackage.Variables["RunDate"].Value = newrundate; // Execute package TextBox3.Text = TextBox3.Text + logtime + "Executing package...\r\n"; DTSExecResult myResult = myPackage.Execute(); // Show the execution result TextBox3.Text = TextBox3.Text + logtime + "Package executed result: " + myResult.ToString() + " \r\n"; } catch (Exception ee) { TextBox3.Text = logtime + "Package executed fail and Erros is: " + ee.Message + " \r\n"; } } }
//Fourth Phase: Checks and setting of flags in the Karvy staging table public bool KARVYProcessDataInStagingProfile(int processId, int AdviserId, string Packagepath, string configPath) { bool IsProcessComplete = false; try { string query1 = "UPDATE CustomerMFKarvyXtrnlProfileStaging SET CMFKXPS_IsCustomerNew = 0 , C_CustomerId = B.C_CustomerId , CP_PortfolioId = D.CP_PortfolioId " + "FROM CustomerMFKarvyXtrnlProfileStaging A " + "INNER JOIN Customer B " + "ON A.CMFKXPS_PANNumber = B.C_PANNum " + "INNER JOIN CustomerPortfolio D " + "ON B.C_CustomerId = D.C_CustomerId " + "INNER JOIN AdviserRM C " + "ON B.AR_RMId = C.AR_RMId " + "WHERE C.A_AdviserId = " + AdviserId + " and A.ADUL_ProcessId = " + processId + " and D.CP_IsMainPortfolio = 1"; string query2 = "UPDATE CustomerMFKarvyXtrnlProfileStaging SET CMFKXPS_IsFolioNew = 0 , CMFA_AccountId = B.CMFA_AccountId " + "FROM CustomerMFKarvyXtrnlProfileStaging A " + "INNER JOIN CustomerMutualFundAccount B " + "ON A.CMFKXPS_Folio = B.CMFA_FolioNum AND A.PA_AMCCode = B.PA_AMCCode " + "INNER JOIN CustomerPortfolio C " + "ON B.CP_PortfolioId = C.CP_PortfolioId " + "INNER JOIN Customer D " + "ON C.C_CustomerId = D.C_CustomerId " + "INNER JOIN AdviserRM E " + "ON D.AR_RMId = E.AR_RMId " + "WHERE E.A_AdviserId =" + AdviserId + " and A.ADUL_ProcessID =" + processId; string query3 = "UPDATE CustomerMFKarvyXtrnlProfileStaging set PA_AMCCode = C.PA_AMCCode " + "FROM CustomerMFKarvyXtrnlProfileStaging INNER JOIN ProductAMCSchemeMapping B ON " + "CMFKXPS_ProductCode = B.PASC_AMC_ExternalCode " + "INNER JOIN ProductAMCSchemePlan C ON " + "B.PASP_SchemePlanCode=C.PASP_SchemePlanCode " + "where ( CMFKXPS_IsRejected = 0 and ADUL_ProcessId = " + processId + " ) "; Package karvyProPkg3 = App.LoadPackage(Packagepath, null); karvyProPkg3.Variables["varQueryCustomerCheck"].Value = query1; karvyProPkg3.Variables["varQueryFolioCheck"].Value = query2; karvyProPkg3.Variables["varQueryAMCCheck"].Value = query3; karvyProPkg3.Variables["varProcessIdPanNullCheck"].Value = processId; karvyProPkg3.Variables["varProcessIdAMCCheck"].Value = processId; karvyProPkg3.Variables["varProcessIdUpdateAMCFlag"].Value = processId; karvyProPkg3.Variables["varProcessIdBrokerCodeCheck"].Value = processId; karvyProPkg3.Variables["varProcessIdBankAccountTypeTranslatorCheck"].Value = processId; karvyProPkg3.Variables["varProcessIdBankModeOfHoldingTranslatorCheck"].Value = processId; karvyProPkg3.Variables["varProcessIdCustomerTypeTranslatorCheck"].Value = processId; karvyProPkg3.Variables["varProcessIdOccupationCodeTranslatorCheck"].Value = processId; karvyProPkg3.Configurations[0].ConfigurationString = configPath; DTSExecResult karvyProResult3 = karvyProPkg3.Execute(); if (karvyProResult3.ToString() == "Success") { IsProcessComplete = true; } } catch (BaseApplicationException Ex) { throw Ex; } catch (Exception Ex) { BaseApplicationException exBase = new BaseApplicationException(Ex.Message, Ex); NameValueCollection FunctionInfo = new NameValueCollection(); FunctionInfo.Add("Method", "KarvyUploadsBo.cs:KARVYProcessDataInStagingProfile()"); object[] objects = new object[3]; objects[0] = processId; objects[1] = AdviserId; objects[2] = Packagepath; FunctionInfo = exBase.AddObject(FunctionInfo, objects); exBase.AdditionalInformation = FunctionInfo; ExceptionManager.Publish(exBase); throw exBase; } return(IsProcessComplete); }