static private DataTable SaveDynamicCollection_Deletes(esDataRequest request)
        {
            VistaDBCommand cmd = null;

            DataTable dataTable = CreateDataTable(request);

            using (esTransactionScope scope = new esTransactionScope())
            {
                using (VistaDBDataAdapter da = new VistaDBDataAdapter())
                {
                    da.AcceptChangesDuringUpdate = false;
                    da.ContinueUpdateOnError     = request.ContinueUpdateOnError;

                    try
                    {
                        cmd = da.DeleteCommand = Shared.BuildDynamicDeleteCommand(request, request.CollectionSavePacket[0].ModifiedColumns);
                        esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);

                        DataRow[] singleRow = new DataRow[1];

                        // Delete each record
                        foreach (esEntitySavePacket packet in request.CollectionSavePacket)
                        {
                            DataRow row = dataTable.NewRow();
                            dataTable.Rows.Add(row);

                            SetOriginalValues(request, packet, row, true);
                            row.AcceptChanges();
                            row.Delete();

                            singleRow[0] = row;
                            da.Update(singleRow);

                            if (row.HasErrors)
                            {
                                request.FireOnError(packet, row.RowError);
                            }

                            dataTable.Rows.Clear(); // ADO.NET won't let us reuse the same DataRow
                        }
                    }
                    finally
                    {
                        esTransactionScope.DeEnlist(cmd);
                        cmd.Dispose();
                    }
                }

                scope.Complete();
            }

            return(request.Table);
        }
Beispiel #2
0
        public void PackageFile(FileInfo pkgFileInfo)
        {
            string sql = "insert into [FileSystem](FileName,FileDir,FileSize,HashCode,BinData,FileVersion,CreateDate,LastChangeDate) values("
                         + "@FileName,@FileDir,@FileSize,@HashCode,@BinData,1, @CreateDate, @LastChangeDate"
                         + ")";
            VistaDBCommand cmd = new VistaDBCommand(sql, conn);

            cmd.Parameters.AddWithValue("@FileName", pkgFileInfo.Name);
            cmd.Parameters.AddWithValue("@FileDir", pkgFileInfo.DirectoryName.Replace(BaseDir, "").Replace("\\", "/"));
            cmd.Parameters.AddWithValue("@FileSize", pkgFileInfo.Length);

            byte[] fBin = InitialProject.GetFileBytes(pkgFileInfo.FullName);
            cmd.Parameters.AddWithValue("@HashCode", InitialProject.GetMD5Hash(fBin));
            cmd.Parameters.AddWithValue("@BinData", fBin);
            cmd.Parameters.AddWithValue("@CreateDate", pkgFileInfo.CreationTimeUtc);
            cmd.Parameters.AddWithValue("@LastChangeDate", pkgFileInfo.LastWriteTimeUtc);

            cmd.ExecuteNonQuery();
            cmd.Dispose();
        }
Beispiel #3
0
        /// <summary>
        /// 同步文件
        /// </summary>
        /// <param name="currentFile">The current file.</param>
        public void SynFileInfo(FileInfo currentFile)
        {
            //检查项目中是否存在该文件(目录+文件名)
            //比较文件:是否更新?
            string sql = string.Format("select top 1 FileID from [FileSystem] where ProjectID={0} AND FileDir='{1}' AND FileName='{2}'",
                                       1,
                                       currentFile.DirectoryName.Replace(BaseDir, "").Replace("\\", "/"),
                                       currentFile.Name);
            VistaDBCommand cmd     = new VistaDBCommand(sql, conn);
            object         oFileID = cmd.ExecuteScalar();

            if (oFileID == null)
            {
                PackageFile(currentFile);
            }
            else
            {
                #region 比较版本

                #endregion

                #region 插入新文件
                sql = "insert into [FileSystem](FileName,FileDir,FileSize,HashCode,BinData,FileVersion,CreateDate,LastChangeDate) values("
                      + "@FileName,@FileDir,@FileSize,@HashCode,@BinData,2, @CreateDate, @LastChangeDate"
                      + ")";
                VistaDBCommand cmdAdd = new VistaDBCommand(sql, conn);
                cmd.Parameters.AddWithValue("@FileName", currentFile.Name);
                cmd.Parameters.AddWithValue("@FileDir", currentFile.DirectoryName.Replace(BaseDir, "").Replace("\\", "/"));
                cmd.Parameters.AddWithValue("@FileSize", currentFile.Length);

                byte[] fBin = InitialProject.GetFileBytes(currentFile.FullName);
                cmd.Parameters.AddWithValue("@HashCode", InitialProject.GetMD5Hash(fBin));
                cmd.Parameters.AddWithValue("@BinData", fBin);
                cmd.Parameters.AddWithValue("@CreateDate", currentFile.CreationTimeUtc);
                cmd.Parameters.AddWithValue("@LastChangeDate", currentFile.LastWriteTimeUtc);

                cmd.ExecuteNonQuery();
                cmd.Dispose();
                #endregion
            }
        }
        static private DataTable SaveDynamicEntity(esDataRequest request)
        {
            bool needToDelete = request.EntitySavePacket.RowState == esDataRowState.Deleted;

            DataTable dataTable = CreateDataTable(request);

            using (VistaDBDataAdapter da = new VistaDBDataAdapter())
            {
                da.AcceptChangesDuringUpdate = false;

                DataRow row = dataTable.NewRow();
                dataTable.Rows.Add(row);

                VistaDBCommand cmd = null;

                switch (request.EntitySavePacket.RowState)
                {
                case esDataRowState.Added:
                    cmd = da.InsertCommand = Shared.BuildDynamicInsertCommand(request, request.EntitySavePacket.ModifiedColumns);
                    SetModifiedValues(request, request.EntitySavePacket, row);
                    break;

                case esDataRowState.Modified:
                    cmd = da.UpdateCommand = Shared.BuildDynamicUpdateCommand(request, request.EntitySavePacket.ModifiedColumns);
                    SetOriginalValues(request, request.EntitySavePacket, row, false);
                    SetModifiedValues(request, request.EntitySavePacket, row);
                    row.AcceptChanges();
                    row.SetModified();
                    break;

                case esDataRowState.Deleted:
                    cmd = da.DeleteCommand = Shared.BuildDynamicDeleteCommand(request, null);
                    SetOriginalValues(request, request.EntitySavePacket, row, true);
                    row.AcceptChanges();
                    row.Delete();
                    break;
                }

                if (!needToDelete && request.Properties != null)
                {
                    request.Properties["esDataRequest"]   = request;
                    request.Properties["esEntityData"]    = request.EntitySavePacket;
                    dataTable.ExtendedProperties["props"] = request.Properties;
                }

                DataRow[] singleRow = new DataRow[1];
                singleRow[0] = row;

                try
                {
                    if (!request.IgnoreComputedColumns)
                    {
                        da.RowUpdated += new VistaDBRowUpdatedEventHandler(OnRowUpdated);
                    }

                    esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);
                    da.Update(singleRow);
                }
                finally
                {
                    esTransactionScope.DeEnlist(cmd);
                }

                if (request.EntitySavePacket.RowState != esDataRowState.Deleted && cmd.Parameters != null)
                {
                    foreach (VistaDBParameter param in cmd.Parameters)
                    {
                        switch (param.Direction)
                        {
                        case ParameterDirection.Output:
                        case ParameterDirection.InputOutput:

                            request.EntitySavePacket.CurrentValues[param.SourceColumn] = param.Value;
                            break;
                        }
                    }
                }

                cmd.Dispose();
            }

            return(dataTable);
        }
        static private DataTable SaveDynamicCollection_InsertsUpdates(esDataRequest request)
        {
            DataTable dataTable = CreateDataTable(request);

            using (esTransactionScope scope = new esTransactionScope())
            {
                using (VistaDBDataAdapter da = new VistaDBDataAdapter())
                {
                    da.AcceptChangesDuringUpdate = false;
                    da.ContinueUpdateOnError     = request.ContinueUpdateOnError;

                    VistaDBCommand cmd = null;

                    if (!request.IgnoreComputedColumns)
                    {
                        da.RowUpdated += new VistaDBRowUpdatedEventHandler(OnRowUpdated);
                    }

                    foreach (esEntitySavePacket packet in request.CollectionSavePacket)
                    {
                        if (packet.RowState != esDataRowState.Added && packet.RowState != esDataRowState.Modified)
                        {
                            continue;
                        }

                        DataRow row = dataTable.NewRow();
                        dataTable.Rows.Add(row);

                        switch (packet.RowState)
                        {
                        case esDataRowState.Added:
                            cmd = da.InsertCommand = Shared.BuildDynamicInsertCommand(request, packet.ModifiedColumns);
                            SetModifiedValues(request, packet, row);
                            break;

                        case esDataRowState.Modified:
                            cmd = da.UpdateCommand = Shared.BuildDynamicUpdateCommand(request, packet.ModifiedColumns);
                            SetOriginalValues(request, packet, row, false);
                            SetModifiedValues(request, packet, row);
                            row.AcceptChanges();
                            row.SetModified();
                            break;
                        }

                        request.Properties["esDataRequest"]   = request;
                        request.Properties["esEntityData"]    = packet;
                        dataTable.ExtendedProperties["props"] = request.Properties;

                        DataRow[] singleRow = new DataRow[1];
                        singleRow[0] = row;

                        try
                        {
                            esTransactionScope.Enlist(cmd, request.ConnectionString, CreateIDbConnectionDelegate);
                            da.Update(singleRow);

                            if (row.HasErrors)
                            {
                                request.FireOnError(packet, row.RowError);
                            }
                        }
                        finally
                        {
                            esTransactionScope.DeEnlist(cmd);
                            dataTable.Rows.Clear();
                        }

                        if (!row.HasErrors && cmd.Parameters != null)
                        {
                            foreach (VistaDBParameter param in cmd.Parameters)
                            {
                                switch (param.Direction)
                                {
                                case ParameterDirection.Output:
                                case ParameterDirection.InputOutput:

                                    packet.CurrentValues[param.SourceColumn] = param.Value;
                                    break;
                                }
                            }
                        }

                        cmd.Dispose();
                    }
                }

                scope.Complete();
            }

            return(dataTable);
        }