AccessTodBase Windows Workflow

AccessTodBase Activity Access Dbf . ? Access . , Access , , 15 dBase, 15 . AccessTodBase .
, Activity. , OpenFileDialog Activity. Access DBf - Activity.
, , , Activity Workflow, Activity. , Workflow c "1" Activity, Access, Workflow c "2" - dBase, "3" - Activity, Access dBase.
, Workflow - , , ( :)), .
MS Visual Studio 2012 WorkFlow + Windows Forms Application. , Workflow Windows Forms .
1. OpenFileDialog Activity. Access.
OpenFileDialog Access, Activity. dBase .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ComponentModel;
using System.Windows.Forms;

namespace AccessTodBase
{
public sealed class DialogAccess : CodeActivity
{
[RequiredArgument]
[DefaultValue(null)]
public InArgument<string>Drive{ get; set; }
public OutArgument<string> OutPathAccess{ get; set;}

private OpenFileDialog dialog;

protected override void Execute(CodeActivityContext context)
{
// Open Dialog
dialog = new OpenFileDialog();
dialog.InitialDirectory = context.GetValue(Drive);
dialog.Filter = "txt files (*.accdb)|*.accdb|All files (*.accdb)|*.accdb";
dialog.FilterIndex = 2;
dialog.RestoreDirectory = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
OutPathAccess.Set(context, dialog.FileName);
}
}
}
}
2. Access dBase.
Activity .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Activities;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.IO;

namespace AccessTodBase
{
public sealed class ActivityTransfer : CodeActivity
{
// Define an activity arguments of type string
[RequiredArgument]
[DefaultValue(null)]
public InArgument<string>PathAccess{ get; set; }
public InArgument<string>PathdBase{ get; set; }
public OutArgument<string>ResultTransfer{ get; set; }

// Define private temporary
private OleDbConnectionconnectAccess, connectDbf= null;
private OleDbCommandcommandAccess, commandDbf= null;
private OleDbDataAdapteradapterAccess, adapterDbf= null;
private OleDbDataReaderreader= null;
private DataTabledataTableAccess= null;
private DataTabledataTableDbf= null;
private DataRowrowDbf= null;
private stringstringCommandAccessSQL= null;
private stringstringCommanddBaseSQL= null;
private stringreaddBase= null;

protected override void Execute(CodeActivityContext context)
{
string connectStringAccess=context.GetValue(PathAccess);
string connectStringdBase=context.GetValue(PathdBase);
try
{
if (String.IsNullOrEmpty(connectStringAccess))throw new ArgumentNullException("Value", "File Name Access is null");
if (String.IsNullOrEmpty(connectStringdBase))throw new ArgumentNullException("Value", "File Name dBase is null");
// Read data Access table
stringCommandAccessSQL = @"SELECT OutputTable.* FROM OutputTable";
connectAccess = new OleDbConnection(connectStringAccess);
connectAccess.Open();
commandAccess = new OleDbCommand(stringCommandAccessSQL, connectAccess);
adapterAccess = new OleDbDataAdapter(commandAccess);
reader = commandAccess.ExecuteReader();
dataTableAccess = new DataTable();
dataTableAccess.Load(reader);
connectAccess.Close();

// Connect dBase
stringCommanddBaseSQL= @"INSERT INTO INPUTP (NUM, FAM, IM, OT) VALUES (?, ?, ?, ?)";
readdBase= @"SELECT INPUTP.* FROM INPUTP";
connectDbf = new OleDbConnection(connectStringdBase);
connectDbf.Open();

commandDbf = new OleDbCommand(readdBase, connectDbf);
adapterDbf = new OleDbDataAdapter(commandDbf);

adapterDbf.InsertCommand = new OleDbCommand(stringCommanddBaseSQL, connectDbf);
adapterDbf.InsertCommand.Parameters.Add("@NUM", OleDbType.Numeric, 10, "NUM");
adapterDbf.InsertCommand.Parameters.Add("@FAM", OleDbType.Char, 40, "FAM");
adapterDbf.InsertCommand.Parameters.Add("@IM",OleDbType.Char, 40, "IM");
adapterDbf.InsertCommand.Parameters.Add("@OT",OleDbType.Char, 40, "OT");

dataTableDbf = new DataTable();
adapterDbf.Fill(dataTableDbf);

int i = 0;
foreach (DataRow row in dataTableAccess.Rows)
{
++i;
rowDbf = dataTableDbf.NewRow();
rowDbf["NUM"]= row[0];
rowDbf["FAM"]= row[1];
rowDbf["IM"]= row[2];
rowDbf["OT"]= row[3];
dataTableDbf.Rows.Add(rowDbf);

/* Debug
if (i == 100)
{
adapterDbf.Update(dataTableDbf);
connectDbf.Close();
Console.WriteLine("O.K.");
break;
}
*/
}
adapterDbf.Update(dataTableDbf);
connectDbf.Close();
ResultTransfer.Set(context, "O.K.");
}
catch (Exception ex)
{
ResultTransfer.Set(context, ex.ToString());
}
}
}
}
3. , Workflow Activity.
. , Workflow Windows Forms Application.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Activities;
using System.Threading;
using System.Timers;
using AccessTodBase;

namespace AccessTodBase
{
public partial class SetParametersForm : Form
{
WorkflowApplication wfApp= null;
AutoResetEvent waitHandler= null;
WorkFlowTransfer addwf= null;
WorkflowInvokerinvoker= null;

private string connectStrAccess = string.Empty;
private string connectStrDbf= string.Empty;
private int codeActivity= 0;
public int endWorkFlow= 0;

public SetParametersForm()
{
InitializeComponent();
waitHandler = new AutoResetEvent(false);
}

// Start transfer data
private void Start_Click(object sender, EventArgs e)
{
try
{
// Set show gif file
pictureBoxWait.Visible= true;
endWorkFlow= 0;

// Define local temporary
string result= string.Empty;
string fileDirectory= String.Empty;

// Set code operation for ActivityTransfer
codeActivity = 3;

// Set Connect string for Access
connectStrAccess= @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBoxAccess.Text;

// Set connect string for Dbf
int index= textBoxdBase.Text.LastIndexOf(@"\");
fileDirectory= textBoxdBase.Text.Substring(0, index + 1);
connectStrDbf= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + fileDirectory + @"; Extended Properties=dBASE IV";

// Set AutoResetEvent
waitHandler = new AutoResetEvent(false);

// Create WorkFlowTransfer
WorkFlowTransfer addwf= new WorkFlowTransfer()
{
PathAccessArgument= new InArgument<String>(connectStrAccess),
PathdBaseArgument= new InArgument<String>(connectStrDbf),
CodActivityArgument = new InArgument<int>(codeActivity)
};

// Create WorkflowApplication
wfApp = new WorkflowApplication(addwf);

// Create event handler wfApp.Completed
wfApp.Completed = (workflowApplicationCompletedEventArgs) =>
{
result = workflowApplicationCompletedEventArgs.Outputs["ResultWorkFlow"].ToString();
if (result != "O.K.") MessageBox.Show("Errot transfer Activity ...");
waitHandler.Set();
endWorkFlow = 1;
};

// Start workflow
myTimer.Enabled = true;
wfApp.Run();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

// Select Path Access DataBase
private void PathAccess_Click(object sender, EventArgs e)
{
try
{
// Set code Activity
codeActivity = 1;
addwf = new WorkFlowTransfer() { CodActivityArgument = new InArgument<int>(codeActivity) };
invoker = new WorkflowInvoker(addwf);
invoker.InvokeCompleted += delegate(object obj, InvokeCompletedEventArgs args)
{
textBoxAccess.Text = args.Outputs["ResultWorkFlow"].ToString();
waitHandler.Set();
};
invoker.InvokeAsync();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error select Access", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

// Select path dBase DataBase
private void PathdBase_Click(object sender, EventArgs e)
{
try
{
// Set code Activity
codeActivity = 2;
addwf = new WorkFlowTransfer() { CodActivityArgument = new InArgument<int>(codeActivity) };
invoker = new WorkflowInvoker(addwf);
invoker.InvokeCompleted += delegate(object obj, InvokeCompletedEventArgs args)
{
textBoxdBase.Text = args.Outputs["ResultWorkFlow"].ToString();
waitHandler.Set();
};
invoker.InvokeAsync();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error select dBase", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}

// Tick metod timer
private void myTimer_Tick(object sender, EventArgs e)
{
if (endWorkFlow == 1)
{
pictureBoxWait.Visible = false;
myTimer.Enabled = false;
}
}

}
}

Visual Studio 2012 .
C , .
08.04.2013 .

© Argument Ltd, 2017 ,  : 8-921-215-45-70,   e-mail