Exemplo n.º 1
0
        private bool Remove(Img data, SqlConnection oConn)
        {
            string sql = "SELECT AttachFilePath FROM Attachments WHERE AttachId = @id ";

            SqlDataAdapter da = new SqlDataAdapter(sql, oConn);

            da.SelectCommand.Parameters.Add("@id", SqlDbType.Int).Value = data.AttachId;

            DataSet ds = new DataSet();

            try
            {
                da.Fill(ds);
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                return(false);
            }

            DataTable dt;

            dt = ds.Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                string file = row[0].ToString();

                File.Delete(file);
            }

            sql = "DELETE FROM Attachments WHERE (AttachId = @id)";
            SqlCommand cmd = new SqlCommand(sql, oConn);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value = Convert.ToInt32(data.AttachId);

            int number = Convert.ToInt32(cmd.ExecuteNonQuery());

            if (number > 0)
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        public Img Update(IDictionary <String, object> data, User currentUser, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                throw;
            };
            string userId = (currentUser != null) ? currentUser.UserId : "";
            int    id     = Convert.ToInt32(data["AttachId"]);

            string sql = "UPDATE Attachments SET AttachName = @ImageDesc WHERE AttachId = @id";

            SqlCommand cmd = new SqlCommand(sql, oConn);

            cmd.Parameters.Add("@id", SqlDbType.Int).Value             = id;
            cmd.Parameters.Add("@ImageDesc", SqlDbType.NVarChar).Value = data["ImageDesc"];

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ConnManager.CloseConn(oConn);
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            }

            Img returnData = Get(id, oConn);

            ConnManager.CloseConn(oConn);

            return(returnData);
        }
Exemplo n.º 3
0
        public Img Get(int id, ref string msgError)
        {
            SqlConnection oConn = null;

            try
            {
                oConn = ConnManager.OpenConn();
            }
            catch (Exception ex)
            {
                LogManager.Write("ERROR:" + Environment.NewLine + "\tMETHOD = " + this.GetType().FullName + "." + MethodBase.GetCurrentMethod().Name + Environment.NewLine + "\tMESSAGE = " + ex.Message);
                msgError = ex.Message;
                return(null);
            };

            Img data = Get(id, oConn);

            ConnManager.CloseConn(oConn);

            return(data);
        }