Example #1
0
        public static int Add(FilesDS.FilesRow dr, string SQLConnectionName)
        {
            try
            {
                SqlConnection SQLConn = new SqlConnection(getConnstring(SQLConnectionName));

                SqlCommand iSqlCommand = GenerateSqlCommandfromDataRow(dr, SP_Add);

                iSqlCommand.Connection = SQLConn;
                //Set the ID column as output as the GenerateSQLCommand would not have done this.
                iSqlCommand.Parameters["@ID"].Direction = ParameterDirection.InputOutput;
                iSqlCommand.UpdatedRowSource = UpdateRowSource.OutputParameters;

                SQLConn.Open();
                iSqlCommand.ExecuteNonQuery();
                int newID = (int)iSqlCommand.Parameters["@ID"].Value;
                iSqlCommand.Dispose();
                SQLConn.Close();
                return newID;

            }
            catch
            {
                return -1;
            }
        }
Example #2
0
        public static bool DelFile(FilesDS.FilesRow rdr)
        {
            //To do get id from HojuWebDisk context
            //String userid = HttpContext.Current.User.Identity.Name.Split(@"\".ToCharArray(), 2)[1];

            return FilesDLC.Del(rdr.ID, DBConnName);
        }
Example #3
0
        private int SaveFile(int PID)
        {
            byte[] _requestInput = GetRequestInput();

            FilesDS.FilesRow _newFile = WebDavHelper.getFile(this._requestPath);

            if (_newFile == null)
            {
                FilesDS fds = new FilesDS();
                _newFile = fds.Files.NewFilesRow();
                _newFile.FileData = _requestInput;
                _newFile.FileDataSize = _requestInput.LongLength;
                _newFile.ParentID = PID;
                _newFile.FileName = WebDavHelper.getResourceName(this._requestPath);
                _newFile.ContentType = GetMIMEType(_newFile.FileName);
                _newFile.update_user_stamp = HttpContext.Current.User.Identity.Name;

            }
            else
            {
                _newFile.FileData = _requestInput;
                _newFile.FileDataSize = _requestInput.LongLength;
            }

            return WebDavHelper.SaveFile(_newFile);
        }
Example #4
0
 /// <summary>
 /// Saves a File
 /// </summary>
 /// <param name="rdr">The file row to save</param>
 /// <returns></returns>   
 public static int SaveFile(FilesDS.FilesRow rdr)
 {
     return FileBLC.SaveFile(rdr);
 }
Example #5
0
        public static FilesDS.FilesRow Get(int KeyValue, string SQLConnectionName)
        {
            FilesDS ds = new FilesDS();

               try
            {
                SqlConnection SQLConn = new SqlConnection(getConnstring(SQLConnectionName));

                SqlDataAdapter iDataAdapter = new SqlDataAdapter(SP_Get, SQLConn);
                iDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;

                iDataAdapter.SelectCommand.Parameters.Add(new SqlParameter("@ID", SqlDbType.Int));
                iDataAdapter.SelectCommand.Parameters["@ID"].Value = KeyValue;

                SQLConn.Open();
                //Fill the DataSet with the rows that are returned.
                iDataAdapter.Fill(ds, ds.Files.TableName);
                iDataAdapter.Dispose();

                SQLConn.Close();

            }
            catch
            {
                return null;
            }

            if (ds.Files.Rows.Count == 1)
            {

                return (FilesDS.FilesRow)ds.Files.Rows[0];
            }
            else
            {
                return null;
            }
        }
Example #6
0
        private static SqlCommand GenerateSqlCommandfromDataRow(FilesDS.FilesRow Data, string StoredProcName)
        {
            SqlCommand retCom = new SqlCommand(StoredProcName);
            retCom.CommandType = CommandType.StoredProcedure;

            for (int Eni = 0; Eni < Data.ItemArray.Length; Eni++)
            {
                string stype = Data[Eni].GetType().ToString();

                switch (stype)
                {
                    case "System.Int32":
                        retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.Int);
                        retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni];
                        break;
                    case "System.Int64":
                        retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.BigInt);
                        retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni];
                        break;
                    case "System.String":
                        retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.VarChar);
                        retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni];
                        break;
                    case "System.Byte[]":
                        retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.Image);
                        retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni];

                        break;
                    case "System.DateTime":
                        retCom.Parameters.Add("@" + Data.Table.Columns[Eni].ColumnName, SqlDbType.DateTime);
                        retCom.Parameters["@" + Data.Table.Columns[Eni].ColumnName].Value = Data[Eni];
                        break;

                }
            }
            return retCom;
        }
Example #7
0
        public static int Update(FilesDS.FilesRow dr, string SQLConnectionName)
        {
            try
            {
                SqlConnection SQLConn = new SqlConnection(getConnstring(SQLConnectionName));

                SqlCommand iSqlCommand = GenerateSqlCommandfromDataRow(dr, SP_Update);

                iSqlCommand.Connection = SQLConn;
                //Set the ID column as output as the GenerateSQLCommand would not have done this.

                SQLConn.Open();
                iSqlCommand.ExecuteNonQuery();
                iSqlCommand.Dispose();
                SQLConn.Close();
                return 1;

            }
            catch
            {
                return -1;
            }
        }
Example #8
0
        public static int SaveFile(FilesDS.FilesRow rdr)
        {
            //To do get id from HojuWebDisk context
            //String userid = HttpContext.Current.User.Identity.Name.Split(@"\".ToCharArray(), 2)[1];

            if (rdr.ID == 0)
            {
                //this is a new entry.
                return FilesDLC.Add(rdr, DBConnName);
            }
            else
            {
                //this is an existing entry
                return FilesDLC.Update(rdr, DBConnName);
            }
        }
Example #9
0
        private void CopyFile(FilesDS.FilesRow _sourceFile, string destination)
        {
            FilesDS.FilesRow _destFile;

            if (_sourceFile != null)
            {
                try
                {
                   _destFile = WebDavHelper.getFile(destination);

                    if (!this._overwriteResource && _destFile != null)
                    {
                        this._Errors.Add(new ProcessingError(_sourceFile.FileName, WebDavHelper.getEnumHttpResponse(DavCopyResponseCode.PreconditionFailed)));
                    }
                    else
                    {
                        FoldersDS.FoldersRow _destdir = WebDavHelper.getParentFolder(destination);
                        if (_destdir == null)
                        {
                            this._Errors.Add(new ProcessingError(_sourceFile.FileName, WebDavHelper.getEnumHttpResponse(DavCopyResponseCode.BadGateway)));
                        }
                        else
                        {
                            if (_destFile == null)
                            {
                                FilesDS fds = new FilesDS();
                                _destFile = fds.Files.NewFilesRow();
                            }
                            _destFile.ContentType = _sourceFile.ContentType;
                            _destFile.FileData = _sourceFile.FileData;
                            _destFile.FileDataSize = _sourceFile.FileDataSize;
                            _destFile.FileName = _sourceFile.FileName;
                            _destFile.ParentID = _destdir.ID;
                            _destFile.update_user_stamp = HttpContext.Current.User.Identity.Name;
                            WebDavHelper.SaveFile(_destFile);

                        }
                    }
                }
                catch (Exception)
                {
                    this._Errors.Add(new ProcessingError(_sourceFile.FileName, WebDavHelper.getEnumHttpResponse(DavCopyResponseCode.Forbidden)));

                }
            }
        }