Beispiel #1
0
        private void btnCompare_Click(object sender, EventArgs e)
        {
            SourceConnection.Connect();
            DestinationConnection.Connect();
            progressBar.Maximum = lstBox1.Items.Count;
            progressBar.Value   = 0;

            foreach (String table in lstBox1.Items)
            {
                if (!In(table, lstBox2.Items))
                {
                    resultDiff.Nodes.Add(String.Format("{1} - missing table", ddlListConnection1.SelectedItem, table));
                }
                else
                {
                    TreeNode        node            = null;
                    List <DBColumn> columnsMismatch = GetMissingColumn(table, SourceConnection, DestinationConnection);
                    if (columnsMismatch.Count > 0)
                    {
                        node = resultDiff.Nodes.Add(String.Format("{1} - missing column", ddlListConnection1.SelectedItem, table));
                        foreach (DBColumn col in columnsMismatch)
                        {
                            node.Nodes.Add(col.ColumnName);
                        }
                    }
                }
                progressBar.Value += 1;
            }

            SourceConnection.Disconnect();
            DestinationConnection.Disconnect();
        }
Beispiel #2
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if ((txtFilePath.HasFile))
            {
                DataSet ds = ReadExcelFile();

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        SourceConnection.MFMPoints.AddObject(new MFMPoints()
                        {
                            MeasurementSection = dr["MeasurementSection"].ToString(), PointGas = StringHelper.TryParse(dr["PointGas"].ToString()), PointOil = StringHelper.TryParse(dr["PointOil"].ToString()), MeterName = dr["MeterName"].ToString()
                        });
                    }
                    SourceConnection.SaveChanges();
                }

                lblMessage.Text      = "Data successfully Imported! Total Recodes:" + ds.Tables[0].Rows.Count;
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Visible   = true;
            }
            else
            {
                lblMessage.Text      = "Please select an excel file first";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Visible   = true;
            }
        }
Beispiel #3
0
        private void SaveEntitybutton_Click(object sender, EventArgs e)
        {
            //  IConnectionProperties cn;
            try
            {
                EntityStructure.Drawn = true;
                if (SourceConnection.Entities.Where(o => o.EntityName.Equals(EntityStructure.EntityName, StringComparison.OrdinalIgnoreCase)).Any())
                {
                    SourceConnection.Entities[SourceConnection.Entities.FindIndex(i => i.EntityName.Equals(EntityStructure.EntityName, StringComparison.OrdinalIgnoreCase))] = EntityStructure;
                }
                else
                {
                    SourceConnection.CreateEntityAs(EntityStructure);
                }

                DMEEditor.ConfigEditor.SaveDataSourceEntitiesValues(new DatasourceEntities {
                    datasourcename = SourceConnection.DatasourceName, Entities = SourceConnection.Entities
                });
                MessageBox.Show("Entity Saved successfully", "Beep");
            }
            catch (Exception ex)
            {
                ErrorObject.Flag = Errors.Failed;
                string errmsg = "Error Saving Function Mapping ";
                ErrorObject.Message = $"{errmsg}:{ex.Message}";
                errmsg = ErrorObject.Message;
                MessageBox.Show(errmsg, "Beep");
                Logger.WriteLog($" {errmsg} :{ex.Message}");
            }
        }
Beispiel #4
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if ((txtFilePath.HasFile))
            {
                DataSet ds = ReadExcelFile();

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        SourceConnection.MeterNotes.AddObject(new DataSource.MeterNote()
                        {
                            Comment = dr["Comments"].ToString(), MeterNumber = dr["MeterName"].ToString()
                        });
                    }
                    SourceConnection.SaveChanges();
                }

                lblMessage.Text      = "Data successfully Imported! Total Records:" + ds.Tables[0].Rows.Count;
                lblMessage.ForeColor = System.Drawing.Color.Green;
                lblMessage.Visible   = true;
            }
            else
            {
                lblMessage.Text      = "Please select an excel file first";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Visible   = true;
            }
        }
Beispiel #5
0
        public static int ConnectToSourceClient(string clientName, string bapiKey)
        {
            var loginCode = SourceConnection.bcLogon(clientName, string.Empty, string.Empty, bapiKey);

            HandleLoginResult(loginCode, clientName, bapiKey);
            return(loginCode);
        }
Beispiel #6
0
 private void EnsureConnectionsOpened()
 {
     if ((SourceConnection.State & ConnectionState.Open) == 0)
     {
         SourceConnection.Open();
     }
     if ((DestinyConnection.State & ConnectionState.Open) == 0)
     {
         DestinyConnection.Open();
     }
 }
Beispiel #7
0
        public void Close()
        {
            if (Status == ConnectionStatus.Open)
            {
                SourceConnection.Close();
            }
            else if (Status == ConnectionStatus.Opening)
            {
                cancelSource.Cancel();
            }

            Status = ConnectionStatus.Closed;
            Closed?.Invoke(this, EventArgs.Empty);
        }
Beispiel #8
0
 public void Open()
 {
     try
     {
         SourceConnection.Open();
         Status = ConnectionStatus.Open;
         Opened?.Invoke(this, EventArgs.Empty);
     }
     catch (Exception)
     {
         Status = ConnectionStatus.Closed;
         OpenFailed?.Invoke(this, EventArgs.Empty);
     }
 }
Beispiel #9
0
        private void ValidateQuerybutton_Click(object sender, EventArgs e)
        {
            object dt;

            ds = DMEEditor.GetDataSource(dataSourceIDComboBox.Text);
            if (SourceConnection != null && EntityStructure.CustomBuildQuery != null)
            {
                dt = SourceConnection.RunQuery(EntityStructure.CustomBuildQuery);
            }
            else
            {
                dt = SourceConnection.GetEntity(EntityName, null);
            }
            CustomQueryDatadataGridView.DataSource = dt;
        }
Beispiel #10
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Id = (Update) ? StringHelper.TryParse(StringHelper.Decrypt(Request.QueryString["Id"].ToString())) : 0;
            DataSource.MeterNoteCategory data = (!Update) ? new DataSource.MeterNoteCategory() : SourceConnection.MeterNoteCategories.Where(x => x.Id.Equals(Id)).First();
            data.Description = txtDescription.Text;
            data.Category    = txtCategory.Text;

            if (!Update)
            {
                SourceConnection.MeterNoteCategories.AddObject(data);
            }

            SourceConnection.SaveChanges();
            Response.Redirect("DataView.aspx");
        }
Beispiel #11
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Id = (Update) ? StringHelper.TryParse(StringHelper.Decrypt(Request.QueryString["Id"].ToString())) : 0;
            MFMGVF data = (!Update) ? new MFMGVF() : SourceConnection.MFMGVFs.Where(x => x.GVFID.Equals(Id)).First();

            data.GVF       = Convert.ToDouble(txtGVF.Text);
            data.MeterName = txtMeterName.Text;

            if (!Update)
            {
                SourceConnection.MFMGVFs.AddObject(data);
            }

            SourceConnection.SaveChanges();
            Response.Redirect("DataView.aspx");
        }
Beispiel #12
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Id = (Update) ? StringHelper.TryParse(StringHelper.Decrypt(Request.QueryString["Id"].ToString())) : 0;
            DataSource.MeterNote data = (!Update) ? new DataSource.MeterNote() : SourceConnection.MeterNotes.Where(x => x.Id.Equals(Id)).First();
            data.Comment    = txtComment.Text;
            data.CategoryId = StringHelper.TryParse(ddlCategory.SelectedValue);

            if (!Update)
            {
                data.MeterNumber = meterNumber;
                SourceConnection.MeterNotes.AddObject(data);
            }

            SourceConnection.SaveChanges();
            Response.Redirect("DataView.aspx?tagnumber=" + meterNumber);
        }
Beispiel #13
0
        private async void OnLoadSourceTablesAsync()
        {
            IsBusy = true;

            await SourceConnection.TestDBConnectionAsync();

            Databases.Clear();

            string instance = SourceConnection.ServerInstance;

            IEnumerable <DataBaseModel> databases = await GetConnectionDatabasesAsync(SourceConnection);

            LoadDatabases(databases);

            //RefreshDatabases(databases);

            IsBusy = false;
        }
Beispiel #14
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Id = (Update) ? StringHelper.TryParse(StringHelper.Decrypt(Request.QueryString["Id"].ToString())) : 0;
            MFMPoints data = (!Update) ? new MFMPoints() : SourceConnection.MFMPoints.Where(x => x.MFMPointsID.Equals(Id)).First();

            data.PointGas           = Convert.ToInt32(txtPointGas.Text);
            data.PointOil           = Convert.ToInt32(txtPointOil.Text);
            data.MeasurementSection = txtMeasurementSection.Text;
            data.MeterName          = txtMeterName.Text;

            if (!Update)
            {
                SourceConnection.MFMPoints.AddObject(data);
            }

            SourceConnection.SaveChanges();
            Response.Redirect("DataView.aspx");
        }
Beispiel #15
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Id = (Update) ? StringHelper.TryParse(StringHelper.Decrypt(Request.QueryString["Id"].ToString())) : 0;
            MFMAxisData data = (!Update) ? new MFMAxisData() : SourceConnection.MFMAxisDatas.Where(x => x.Id.Equals(Id)).First();

            data.MaxValue  = Convert.ToInt64(txtMaxValue.Text);
            data.MinValue  = Convert.ToInt64(txtMinValue.Text);
            data.Axis      = ddlAxis.SelectedValue;
            data.LogBase   = Convert.ToInt32(txtLogBase.Text);
            data.MeterName = txtMeterName.Text;

            if (!Update)
            {
                SourceConnection.MFMAxisDatas.AddObject(data);
            }

            SourceConnection.SaveChanges();
            Response.Redirect("DataView.aspx");
        }
Beispiel #16
0
 private void ValidateFieldsbutton_Click(object sender, EventArgs e)
 {
     if (EntityStructure.Drawn == true)
     {
         SourceConnection = DMEEditor.GetDataSource(dataSourceIDComboBox.Text);
         if (SourceConnection == null)
         {
             DMEEditor.AddLogMessage("Error", "Could not Find DataSource " + EntityStructure.DataSourceID, DateTime.Now, EntityStructure.Id, EntityStructure.EntityName, Errors.Failed);
             MessageBox.Show($"{ErrorObject.Message}");
         }
         else
         {
             EntityStructure ent = SourceConnection.GetEntityStructure(EntityStructure.EntityName, true);
             EntityStructure.Fields = ent.Fields;
             this.dataHierarchyBindingSource.ResetBindings(true);
             this.fieldsBindingSource.ResetBindings(true);
         }
     }
 }
Beispiel #17
0
    /// <summary>
    /// Called when the game starts/this object is created
    /// </summary>
    public void Initialise()
    {
        // Setup the gates first
        SetupGates();
        GateParent = new GameObject();
        GateParent.transform.position = new Vector3(0, 0, 5);
        GateParent.name = "Logic Gate Parent Object";

        // Assign the sprites
        AssignSprites();

        // Get the level manager
        _LevelManager = GameObject.FindObjectOfType <LevelManager>();

        // Initialise the source connections
        InputConnections  = new List <SourceConnection>();
        OutputConnections = new List <SourceConnection>();

        // Add a source connection for each input and output
        for (int i = 0; i < InputCount; i++)
        {
            SourceConnection NewConnection = new SourceConnection();
            NewConnection.IsInputConnection = true;
            NewConnection.SourceID          = i;
            NewConnection.Gates             = new List <GateBehaviour>();
            NewConnection.GateInputIDs      = new List <int>();

            InputConnections.Add(NewConnection);
        }

        for (int i = 0; i < OutputCount; i++)
        {
            SourceConnection NewConnection = new SourceConnection();
            NewConnection.IsInputConnection = false;
            NewConnection.SourceID          = i;
            NewConnection.Gates             = new List <GateBehaviour>();
            NewConnection.GateInputIDs      = new List <int>();

            OutputConnections.Add(NewConnection);
        }
    }
        private void ValidateQuerybutton_Click(object sender, EventArgs e)
        {
            // ds = (DataViewDataSource)DMEEditor.GetDataSource(dataSourceIDComboBox.Text);

            object dt;

            if (!string.IsNullOrEmpty(EntityStructure.CustomBuildQuery) && !string.IsNullOrWhiteSpace(EntityStructure.CustomBuildQuery))
            {
                SourceConnection = DMEEditor.GetDataSource(dataSourceIDComboBox.Text);
                if (SourceConnection.Category != DatasourceCategory.VIEWS)
                {
                    if (SourceConnection != null && EntityStructure.CustomBuildQuery != null)
                    {
                        dt = SourceConnection.RunQuery(EntityStructure.CustomBuildQuery);
                    }
                    else
                    {
                        dt = SourceConnection.GetEntity(EntityName, null);
                    }
                    if (dt != null)
                    {
                        EntityStructure.Fields = DMEEditor.Utilfunction.GetFieldFromGeneratedObject(dt);
                        this.dataHierarchyBindingSource.ResetBindings(true);
                        this.fieldsBindingSource.ResetBindings(true);
                        fieldsBindingSource.DataSource = dataHierarchyBindingSource;
                        fieldsDataGridView.Refresh();
                        CustomQueryDatadataGridView.DataSource = dt;
                    }
                }
                else
                {
                    MessageBox.Show("Cannot Run Query on DataView");
                }
            }
            else
            {
                MessageBox.Show("Query Missing");
            }
        }
Beispiel #19
0
        private void CreateinDBbutton_Click1(object sender, EventArgs e)
        {
            try
            {
                tb = (EntityStructure)entitiesBindingSource.Current;
                SourceConnection = DMEEditor.GetDataSource(databaseTypeComboBox.Text);
                DMEEditor.OpenDataSource(databaseTypeComboBox.Text);
                //SourceConnection.Dataconnection.OpenConnection();
                SourceConnection.ConnectionStatus = SourceConnection.Dataconnection.ConnectionStatus;
                if (SourceConnection.ConnectionStatus == ConnectionState.Open)
                {
                    tb.DatasourceEntityName = tb.EntityName;

                    SourceConnection.CreateEntityAs(tb);
                    if (DMEEditor.ErrorObject.Flag == Errors.Ok)
                    {
                        MessageBox.Show("Entity Creation Success", "Beep");
                        DMEEditor.AddLogMessage("Success", "Table Creation Success", DateTime.Now, -1, "", Errors.Failed);
                    }
                    else
                    {
                        string mes = "Entity Creation Failed";
                        MessageBox.Show(mes, "Beep");
                        DMEEditor.AddLogMessage("Create Table", mes, DateTime.Now, -1, mes, Errors.Failed);
                    }
                }
                else
                {
                    MessageBox.Show("Entity Creation Not Success Could not open Database", "Beep");
                    DMEEditor.AddLogMessage("Fail", "Table Creation Not Success Could not open Database", DateTime.Now, -1, "", Errors.Failed);
                }
            }
            catch (Exception ex)
            {
                string mes = "Entity Creation Failed";
                MessageBox.Show(mes, "Beep");
                DMEEditor.AddLogMessage(ex.Message, mes, DateTime.Now, -1, mes, Errors.Failed);
            };
        }
Beispiel #20
0
        //todo: repair DRY violation

        private async void StartOpenAsync()
        {
            try
            {
                Status = ConnectionStatus.Opening;
                await SourceConnection.OpenAsync(cancelSource.Token);

                Status = ConnectionStatus.Open;
            }
            catch (Exception)
            {
                Status = ConnectionStatus.Closed;
            }

            if (Status == ConnectionStatus.Open)
            {
                Opened?.Invoke(this, EventArgs.Empty);
            }
            else
            {
                OpenFailed?.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #21
0
        protected void gvMFMPoints_RowCommand(object sender, GridCommandEventArgs e)
        {
            int dataId;

            switch (e.CommandName)
            {
            case "DeletePoint":
                dataId = Convert.ToInt32(e.CommandArgument);
                MFMPoints data = SourceConnection.MFMPoints.Where(x => x.MFMPointsID.Equals(dataId)).First();
                if (data != null)
                {
                    SourceConnection.MFMPoints.DeleteObject(data);
                    SourceConnection.SaveChanges();
                }
                BindPointsData();
                break;

            case "EditPoint":
                dataId = Convert.ToInt32(e.CommandArgument);
                Response.Redirect("AddorEdit.aspx?Id=" + StringHelper.Encrypt(dataId.ToString()));
                break;
            }
        }
Beispiel #22
0
        protected void gvMeterNotes_RowCommand(object sender, GridCommandEventArgs e)
        {
            int dataId;

            switch (e.CommandName)
            {
            case "DeleteNote":
                dataId = Convert.ToInt32(e.CommandArgument);
                DataSource.MeterNote data = SourceConnection.MeterNotes.Where(x => x.Id.Equals(dataId)).First();
                if (data != null)
                {
                    SourceConnection.MeterNotes.DeleteObject(data);
                    SourceConnection.SaveChanges();
                }
                BindNoteData();
                break;

            case "EditNote":
                dataId = Convert.ToInt32(e.CommandArgument);
                Response.Redirect("AddorEdit.aspx?meter=" + meterNumber + "&Id=" + StringHelper.Encrypt(dataId.ToString()));
                break;
            }
        }
Beispiel #23
0
        public void SetConfig(IDMEEditor pbl, IDMLogger plogger, IUtil putil, string[] args, PassedArgs e, IErrorsInfo per)
        {
            Passedarg = e;

            Logger = plogger;

            ErrorObject      = per;
            DMEEditor        = pbl;
            SourceConnection = DMEEditor.GetDataSource(e.DatasourceName);
            Visutil          = (IVisUtil)e.Objects.Where(c => c.Name == "VISUTIL").FirstOrDefault().obj;
            branch           = (IBranch)e.Objects.Where(c => c.Name == "Branch").FirstOrDefault().obj;
            if (e.Objects.Where(c => c.Name == "ParentBranch").Any())
            {
                Parentbranch = (IBranch)e.Objects.Where(c => c.Name == "ParentBranch").FirstOrDefault().obj;
                //ParentEntity = SourceConnection.GetEntityStructure(Parentbranch.BranchText, true);
            }

            foreach (ConnectionProperties c in DMEEditor.ConfigEditor.DataConnections)
            {
                var t = dataSourceIDComboBox.Items.Add(c.ConnectionName);
            }
            foreach (var item in Enum.GetValues(typeof(ViewType)))
            {
                viewtypeComboBox.Items.Add(item);
            }

            this.dataSourceIDComboBox.SelectedIndexChanged += ComboBox1_SelectedIndexChanged;
            this.ValidateQuerybutton.Click  += ValidateQuerybutton_Click;
            this.ValidateFKbutton.Click     += ValidateFKbutton_Click;
            this.SaveEntitybutton.Click     += SaveEntitybutton_Click;
            this.ValidateFieldsbutton.Click += ValidateFieldsbutton_Click;

            if (e.CurrentEntity != null)
            {
                EntityName = e.CurrentEntity;
            }
            else
            {
                EntityName = "";
            }


            EntityStructure = SourceConnection.GetEntityStructure(EntityName, false);
            if (EntityStructure == null)
            {
                if (!string.IsNullOrEmpty(e.ParameterString1))
                {
                    EntityStructure = SourceConnection.GetEntityStructure(e.ParameterString1, false);
                }
            }
            if (EntityStructure == null)
            {
                if (!string.IsNullOrEmpty(e.ParameterString2))
                {
                    EntityStructure = SourceConnection.GetEntityStructure(e.ParameterString2, false);
                }
            }
            if (EntityStructure == null)
            {
                if (!string.IsNullOrEmpty(e.ParameterString3))
                {
                    EntityStructure = SourceConnection.GetEntityStructure(e.ParameterString3, false);
                }
            }
            if (EntityStructure == null)
            {
                MessageBox.Show("Cannot Find Entity in DataSource");
            }
            else
            {
                this.dataHierarchyBindingSource.ResetBindings(true);
                this.fieldsBindingSource.ResetBindings(true);
                dataHierarchyBindingSource.DataSource = EntityStructure;
                //ConnectionProperties connection = DMEEditor.ConfigEditor.DataConnections.Where(o => o.ConnectionName.Equals(this.SourceConnection.DatasourceName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                //ConnectionDriversConfig conf = DMEEditor.Utilfunction.LinkConnection2Drivers(connection);
                //if (conf != null)
                //    {
                //        dataTypesMapBindingSource.DataSource = DMEEditor.ConfigEditor.DataTypesMap.Where(p => p.DataSourceName.Equals(conf.classHandler, StringComparison.OrdinalIgnoreCase)).Distinct();
                //    }

                DMEEditor.ConfigEditor.ReadDataTypeFile();
                this.fieldtypeDataGridViewTextBoxColumn.DataSource = DMEEditor.typesHelper.GetNetDataTypes2();
                //     fieldtypeDataGridViewTextBoxColumn.DataSource = dataTypesMapBindingSource;
            }
            this.fieldsDataGridView.DataError += FieldsDataGridView_DataError;
        }
Beispiel #24
0
    /// <summary>
    /// Called every frame by the engine
    /// </summary>
    void Update()
    {
        // Check that we don't keep outputs powered
        for (int i = 0; i < OutputConnections.Count; i++)
        {
            // Get a shorthand reference for the current source
            SourceConnection CurrentSource = OutputConnections[i];

            // Check that we don't keep something powered unnecessarily
            if (CurrentSource.Gates.Count < 1)
            {
                CurrentSource.Powered = false;
            }
        }

        // Loop through and make power flower
        if (_LevelManager.PowerFlowing)
        {
            // Go through the list of current gates and run the logic if they work
            for (int i = 0; i < CurrentGates.Count; i++)
            {
                CurrentGates[i].RunLogic();
            }

            // Go through the list of power sources and power
            for (int i = 0; i < InputConnections.Count; i++)
            {
                // Get a shorthand reference for the current source
                SourceConnection CurrentSource = InputConnections[i];

                // Check if powered
                if (CurrentSource.Powered)
                {
                    // Power each gate
                    for (int j = 0; j < InputConnections[i].Gates.Count; j++)
                    {
                        // Power gate
                        CurrentSource.Gates[j].Inputs[CurrentSource.GateInputIDs[j]] = true;
                    }
                }
                else
                {
                    // Power each gate
                    for (int j = 0; j < InputConnections[i].Gates.Count; j++)
                    {
                        // Power gate
                        CurrentSource.Gates[j].Inputs[CurrentSource.GateInputIDs[j]] = false;
                    }
                }
            }
        }
        else
        {
            // Go through the list of current gates and stop power
            for (int i = 0; i < CurrentGates.Count; i++)
            {
                // Stop power
                CurrentGates[i].SetInputs(false, false);
                CurrentGates[i].Output = false;
                CurrentGates[i].ColourWires();
            }

            // Go through the list of power sources and reset light
            for (int i = 0; i < InputConnections.Count; i++)
            {
                // Get a shorthand reference for the current source
                SourceConnection CurrentSource = InputConnections[i];

                // Power each gate
                for (int j = 0; j < InputConnections[i].Gates.Count; j++)
                {
                    // Un-power gate
                    CurrentSource.Gates[j].Inputs[CurrentSource.GateInputIDs[j]] = false;
                }
            }
        }
    }
Beispiel #25
0
        protected override void BeginProcessing()
        {
            DbTransaction transaction = null;

            try
            {
                if ((TargetTable == null && TargetSql == null) || (TargetTable != null && TargetSql != null))
                {
                    throw new ArgumentException("Specify either one of TargetTable or TargetSql");
                }

                bool timeoutGiven = MyInvocation.BoundParameters.ContainsKey("Timeout");

                var connection = TargetConnection.Connection;

                transaction = connection.BeginTransaction();

                using (var selectCmd = SourceConnection.Connection.CreateCommand())
                {
                    selectCmd.CommandText = SourceSql;

                    if (timeoutGiven)
                    {
                        selectCmd.CommandTimeout = Timeout;
                    }

                    Helpers.SetParameters(selectCmd, SourceParameters);

                    using (var reader = selectCmd.ExecuteReader())
                    {
                        string[] paramNames = null;

                        while (reader.Read())
                        {
                            if (paramNames == null)
                            {
                                paramNames = new string[reader.FieldCount];
                                for (var i = 0; i < reader.FieldCount; ++i)
                                {
                                    paramNames[i] = reader.GetName(i);
                                }
                            }

                            using (var insertCmd = TargetConnection.Connection.CreateCommand())
                            {
                                insertCmd.Transaction = transaction;

                                if (TargetSql == null)
                                {
                                    var factory = Helpers.GetDbProviderFactory(connection);
                                    using (var builder = factory.CreateCommandBuilder())
                                    {
                                        var columns = string.Join(", ", paramNames.Select(p => builder.QuoteIdentifier(p)));
                                        var paras   = "@" + string.Join(", @", paramNames);
                                        TargetSql = $"insert into {TargetTable} ({columns}) values ({paras})";
                                    }
                                }

                                insertCmd.CommandText = TargetSql;

                                for (var i = 0; i < reader.FieldCount; ++i)
                                {
                                    var param = insertCmd.CreateParameter();
                                    param.ParameterName = paramNames[i];
                                    param.Value         = reader.GetValue(i);
                                    insertCmd.Parameters.Add(param);
                                }

                                if (timeoutGiven)
                                {
                                    insertCmd.CommandTimeout = Timeout;
                                }

                                insertCmd.ExecuteNonQuery();
                            }
                        }
                    }
                }

                transaction.Commit();
            }
            catch (Exception e)
            {
                if (transaction != null)
                {
                    transaction.Rollback();
                }

                WriteError(new ErrorRecord(e, "", ErrorCategory.NotSpecified, null));
            }
            finally
            {
                SourceConnection.Close();
                TargetConnection.Close();
            }
        }