Esempio n. 1
0
        public static int InsertFromText(int CompanyID, int MedarbejderID, int TypeID, string Overskrift, string Filename, string Tekst, bool Ekstern = false)
        {
            Korrespondance Korr = new Korrespondance();

            Korr.CompanyID     = CompanyID;
            Korr.MedarbejderID = MedarbejderID;
            Korr.Type          = TypeID;
            Korr.Overskrift    = Overskrift;
            Korr.Status        = 1;
            Korr.Ekstern       = Ekstern;

            Korr.Mime = "text/html"; //text/plain '   getMimeFromFile(Filename) '
            if (!Filename.Contains("."))
            {
                Filename += ".txt";
            }
            Korr.Filename = Filename;
            Korr.Ext      = Filename.Substring(Filename.LastIndexOf(".") + 1);
            Korr.Size     = Tekst.Length;

            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(Tekst);
            Korr.Blob = bytes;


            return(Korrespondance.Insert(Korr));
        }
Esempio n. 2
0
        public static int Update(Korrespondance n)
        {
            DBAccess db = new DBAccess();

            db.Parameters.Add(new SqlParameter("@ID", n.ID));

            db.Parameters.Add(new SqlParameter("@Type", Funktioner.ToInt(n.Type)));
            db.Parameters.Add(new SqlParameter("@CompanyID", Funktioner.ToInt(n.CompanyID)));
            db.Parameters.Add(new SqlParameter("@MedarbejderID", Funktioner.ToInt(n.MedarbejderID)));
            db.Parameters.Add(new SqlParameter("@Status", Funktioner.ToInt(n.Status)));

            db.Parameters.Add(new SqlParameter("@Overskrift", SQLfunctions.SQLstr(n.Overskrift)));
            db.Parameters.Add(new SqlParameter("@Extern", Funktioner.ToBool(n.Ekstern)));


            db.Parameters.Add(new SqlParameter("@Mime", SQLfunctions.SQLstr(n.Mime)));
            db.Parameters.Add(new SqlParameter("@Filename", SQLfunctions.SQLstr(n.Filename)));
            db.Parameters.Add(new SqlParameter("@Ext", SQLfunctions.SQLstr(n.Ext)));
            db.Parameters.Add(new SqlParameter("@Size", Funktioner.ToInt(n.Size)));
            //Dim pictureParameter As SqlParameter = New SqlParameter("@Blob", SqlDbType.Image)
            //pictureParameter.Value = n.Blob
            //db.Parameters.Add(pictureParameter)
            //	db.AddParameter("@Blob", Blob)

            db.Parameters.Add(new SqlParameter("@RettetAf", SQLfunctions.SQLstr(CurrentUserName)));
            db.Parameters.Add(new SqlParameter("@RettetIP", SQLfunctions.SQLstr(CurrentUserIP)));
            int retval = db.ExecuteNonQuery("Co2Db_Korrespondance_Update");

            AddLog(Status: "Noter", Logtext: string.Format("Update Noter: ID:{0}", n.ID), Metode: "Update");
            return(retval);
        }
Esempio n. 3
0
        public static int Insert(int
                                 Type, int CompanyID, int MedarbejderID, int Status, string Overskrift, bool Ekstern, string Mime, string Filename, string Ext, int Size, object Blob)
        {
            Korrespondance n = new Korrespondance(Type, CompanyID, MedarbejderID, Status, Overskrift, Ekstern, Mime, Filename, Ext, Size, Blob);

            return(Insert(n));
        }
Esempio n. 4
0
        private static void AddParms(ref DBAccess db, Korrespondance k)
        {
            var with_1 = k;

            db.Parameters.Add(new SqlParameter("@Type", Funktioner.ToInt(k.Type)));
            db.Parameters.Add(new SqlParameter("@CompanyID", Funktioner.ToInt(k.CompanyID)));
            db.Parameters.Add(new SqlParameter("@MedarbejderID", Funktioner.ToInt(k.MedarbejderID)));
            db.Parameters.Add(new SqlParameter("@Status", Funktioner.ToInt(k.Status)));

            db.Parameters.Add(new SqlParameter("@Overskrift", SQLfunctions.SQLstr(k.Overskrift)));
            db.Parameters.Add(new SqlParameter("@Ekstern", Funktioner.ToBool(k.Ekstern)));

            db.Parameters.Add(new SqlParameter("@Mime", SQLfunctions.SQLstr(k.Mime)));
            db.Parameters.Add(new SqlParameter("@Filename", SQLfunctions.SQLstr(k.Filename)));
            db.Parameters.Add(new SqlParameter("@Ext", SQLfunctions.SQLstr(k.Ext)));
            db.Parameters.Add(new SqlParameter("@Size", Funktioner.ToInt(k.Size)));

            SqlParameter pictureParameter = new SqlParameter("@Blob", SqlDbType.Image);

            pictureParameter.Value = k.Blob;
            db.Parameters.Add(pictureParameter);
            //	db.AddParameter("@Blob", Blob)

            AddParmsStandard(db, k);
        }
Esempio n. 5
0
        public static int Save(Korrespondance B)
        {
            int retval = 0;

            if (B.ID > 0)
            {
                retval = Update(B);
            }
            else
            {
                retval = Insert(B);
            }
            return(retval);
        }
Esempio n. 6
0
        public static int InsertFromDisk(int CompanyID, int MedarbejderID, int TypeID, string Overskrift, string Filename, bool DeleteFile = false, bool Ekstern = false)
        {
            if (!File.Exists(Filename))
            {
                throw (new FileNotFoundException("Cannot create attachment because the file was not found : " + Filename, Filename));
            }

            Korrespondance Korr = new Korrespondance();

            Korr.CompanyID     = CompanyID;
            Korr.MedarbejderID = MedarbejderID;
            Korr.Type          = TypeID;
            Korr.Overskrift    = Overskrift;
            Korr.Status        = 1;
            Korr.Ekstern       = Ekstern;

            Korr.Mime = FileIO.getMimeFromFile(Filename); // System.Net.Mime.MediaTypeNames.Application.Pdf ' Text.Plain

            // Load file from harddrive and load into database
            FileInfo fi = new FileInfo(Filename);

            Korr.Filename = fi.Name;
            Korr.Ext      = fi.Extension.Replace(".", "");
            Korr.Size     = (int)fi.Length;
            fi            = null;

            using (FileStream reader = new FileStream(Filename, FileMode.Open))
            {
                byte[] blob = new byte[System.Convert.ToInt32(reader.Length - 1) + 1];
                reader.Read(blob, 0, (int)reader.Length);
                reader.Close();
                //reader.Dispose()
                Korr.Blob = blob;
            }


            if (DeleteFile == true)
            {
                try
                {
                    File.Delete(Filename);
                }
                catch (Exception)
                {
                }
            }

            return(Korrespondance.Insert(Korr));
        }
Esempio n. 7
0
        public static int Update(int
                                 Id, int Type, int CompanyID, int MedarbejderID, int Status, string Overskrift, bool Ekstern, string Mime, string Filename, string Ext, int Size)
        {
            Korrespondance n = Korrespondance.GetKorrespondance(Id);

            n.Type          = Type;
            n.CompanyID     = CompanyID;
            n.MedarbejderID = MedarbejderID;
            n.Status        = Status;
            n.Overskrift    = Overskrift;
            n.Ekstern       = Ekstern;
            n.Mime          = Mime;
            n.Filename      = Filename;
            n.Ext           = Ext;
            n.Size          = Size;
            return(Update(n));
        }
Esempio n. 8
0
        //Private Shared Sub PopulateKorrespondance(ByRef dr As SqlDataReader, ByRef n As Korrespondance)
        private static void Populate(SqlDataReader dr, Korrespondance n)
        {
            PopulateStandard(dr, n);
            var with_1 = n;

            with_1.Type          = System.Convert.ToInt32(dr.DBtoInt("Type"));
            with_1.CompanyID     = System.Convert.ToInt32(dr.DBtoInt("CompanyID"));
            with_1.MedarbejderID = System.Convert.ToInt32(dr.DBtoInt("MedarbejderID"));
            with_1.Status        = System.Convert.ToInt32(dr.DBtoInt("Status"));
            with_1.Overskrift    = dr.DBtoString("Overskrift");
            with_1.Ekstern       = System.Convert.ToBoolean(dr.DBtoBool("Ekstern"));
            with_1.Mime          = dr.DBtoString("Mime");
            with_1.Filename      = dr.DBtoString("Filename");
            with_1.Ext           = dr.DBtoString("Ext");
            with_1.Size          = System.Convert.ToInt32(dr.DBtoString("Size"));
            //.Blob = dr.DBtoString("Blob")
        }
Esempio n. 9
0
        public static List <Korrespondance> GetKorrespondanceSearchList(int CompanyID, int MedarbejderID = -1, bool Ekstern = false, string Search = "")
        {
            DBAccess db = new DBAccess();

            db.AddInt("CompanyID", CompanyID);
            db.AddInt("MedarbejderID", MedarbejderID);
            db.AddBoolean("Ekstern", Ekstern);
            db.AddNVarChar("Search", Search, 255);
            SqlDataReader         dr   = (SqlDataReader)(db.ExecuteReader("Co2Db_Korrespondance_SearchAll")); //cmd.ExecuteReader()
            List <Korrespondance> list = new List <Korrespondance>();

            while (dr.Read())
            {
                Korrespondance Korr = new Korrespondance();
                Populate(dr, Korr);
                list.Add(Korr);
            }
            return(list);
        }
Esempio n. 10
0
        public static List <Korrespondance> GetKorrespondancesByCriteria(string OrderBY, string criteria, params SqlParameter[] @params)
        {
            DBAccess db = new DBAccess();
            //Dim conn As SqlConnection = DataFunctions.GetConnection()
            string query = "";

            query += "SELECT ";
            if (OrderBY != "")
            {
                query += " TOP (100) PERCENT ";
            }
            query += " *";
            query += " FROM vw_Co2Db_Korrespondance ";
            if (criteria != "")
            {
                query += " WHERE (" + criteria + ")";
            }
            if (OrderBY != "")
            {
                query += " ORDER BY " + OrderBY;
            }

            //Dim cmd As New SqlCommand(query, conn)
            db.CommandType = CommandType.Text;
            db.CommandText = query;
            db.AddRange(@params);

            db.Open();
            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader());  //cmd.ExecuteReader()

            List <Korrespondance> list = new List <Korrespondance>();

            while (dr.Read())
            {
                Korrespondance Korr = new Korrespondance();
                Populate(dr, Korr);
                list.Add(Korr);
            }

            db.Dispose();

            return(list);
        }
Esempio n. 11
0
        public static int Insert(Korrespondance k)
        {
            DBAccess     db = new DBAccess();
            SqlParameter ID = new SqlParameter("@ID", 0);

            ID.Direction = ParameterDirection.Output;

            db.Parameters.Add(new SqlParameter("@Type", Funktioner.ToInt(k.Type)));
            db.Parameters.Add(new SqlParameter("@CompanyID", Funktioner.ToInt(k.CompanyID)));
            db.Parameters.Add(new SqlParameter("@MedarbejderID", Funktioner.ToInt(k.MedarbejderID)));
            db.Parameters.Add(new SqlParameter("@Status", Funktioner.ToInt(k.Status)));

            db.Parameters.Add(new SqlParameter("@Overskrift", SQLfunctions.SQLstr(k.Overskrift)));
            db.Parameters.Add(new SqlParameter("@Ekstern", Funktioner.ToBool(k.Ekstern)));

            db.Parameters.Add(new SqlParameter("@Mime", SQLfunctions.SQLstr(k.Mime)));
            db.Parameters.Add(new SqlParameter("@Filename", SQLfunctions.SQLstr(k.Filename)));
            db.Parameters.Add(new SqlParameter("@Ext", SQLfunctions.SQLstr(k.Ext)));
            db.Parameters.Add(new SqlParameter("@Size", Funktioner.ToInt(k.Size)));
            SqlParameter pictureParameter = new SqlParameter("@Blob", SqlDbType.Image);

            pictureParameter.Value = k.Blob;
            db.Parameters.Add(pictureParameter);
            //	db.AddParameter("@Blob", Blob)

            db.Parameters.Add(new SqlParameter("@RettetAf", SQLfunctions.SQLstr(CurrentUserName)));
            db.Parameters.Add(new SqlParameter("@RettetIP", SQLfunctions.SQLstr(CurrentUserIP)));
            db.Parameters.Add(ID);
            int retval = db.ExecuteNonQuery("Co2Db_Korrespondance_Insert");

            if (retval == 1)
            {
                k.ID = int.Parse(ID.Value.ToString());
                AddLog(Status: "Korrespondance", Logtext: string.Format("Create Korrespondance: ID:{0}", k.ID), Metode: "Insert");
                return(k.ID); //Integer.Parse(ID.Value.ToString)
            }
            else
            {
                AddLog(Status: "Korrespondance", Logtext: string.Format("Failure to Create Korrespondance:"), logtype: LogTypeEnum.Error, Metode: "Insert");
                return(-1);
            }
        }
Esempio n. 12
0
        public static Korrespondance GetKorrespondance(int ID)
        {
            DBAccess       db = new DBAccess();
            Korrespondance n  = new Korrespondance();

            db.Parameters.Add(new SqlParameter("@ID", ID));
            SqlDataReader dr = (SqlDataReader)(db.ExecuteReader("Co2Db_Korrespondance_SelectOne"));

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    Populate(dr, n);
                }
            }
            if (!dr.IsClosed)
            {
                dr.Close();
            }
            return(n);
        }
Esempio n. 13
0
 public static int Delete(Korrespondance n)
 {
     return(Delete(n.ID));
 }