public ActionResult EditShip(string ref_id)
        {
            ShipData shipData = ShipData.GetShipData();

            string createdBy = shipData.GetCreatedBy(ref_id);

            if (User.Identity.Name == createdBy || User.IsInRole("admin"))
            {

                Ship ship = new Ship();
                ship = shipData.GetShip(ref_id);
                ShipUrlData shipUrlData = ShipUrlData.GetShipUrlData();
                List<ShipUrl> shipPhotos = shipUrlData.GetPhotos(ref_id);
                ViewBag.Photos = shipPhotos;

                TanimData tanimData = TanimData.GetTanimData();
                ViewBag.tanimlar = tanimData.GetTanimlar();

                return View(ship);
            }
            else
            {
                TempData["Message"] = "Bu kayıt başkası tarafından oluşturulduğu için düzenleyemezsiniz";
                return RedirectToAction("Index","Home");
            }
        }
        public ActionResult GetShip(string ref_id)
        {
            ShipData shipData = ShipData.GetShipData();
            Ship ship = new Ship();
            ship = shipData.GetShip(ref_id);

            if (ship.refId == null)
            {
                TempData["Message"] = "Bulunamadı";
                return RedirectToAction("Index","Home");
            }
            else
            {
                TanimData tanimData = TanimData.GetTanimData();
                Dictionary<int,string> tanimlar =  tanimData.GetTanimlar();
                ViewBag.tanimlar = tanimlar;
                ShipUrlData shipUrlData = ShipUrlData.GetShipUrlData();
                List<ShipUrl> shipPhotos = shipUrlData.GetPhotos(ref_id);
                ViewBag.Photos = shipPhotos;
                ViewBag.Ship = ship;
                return View();
            }
        }
        public bool UpdateUploadShip(string ref_id, int ship_id, string description, string time, HttpPostedFileBase[] files, string choice)
        {
            string savingPath = Server.MapPath("~/Content/images/");
            System.IO.Directory.CreateDirectory(savingPath);

            Ship ship = new Ship();
            ship.refId = ref_id;
            ship.shipId = ship_id;
            ship.time = Convert.ToDateTime(time + ",00:00:00").Date;
            ship.description = description;
            ship.createdBy = User.Identity.Name;
            ship.createdPc = Request.UserHostName;
            ship.createdDatetime = DateTime.Now;

            //System.IO.Directory.CreateDirectory(Server.MapPath("~/Content/images"));
            ShipUrlData shipUrlData = ShipUrlData.GetShipUrlData();
            ShipData shipData = ShipData.GetShipData();

            ImageResize resizer = new ImageResize();
            FileMethods filer = new FileMethods();

            System.Drawing.Image photo;
            System.Drawing.Image preview;
            if (choice == "upload")
            {
                shipData.AddGemi(ship);
            }

            else if (choice == "update")
            {
                shipData.UpdateShip(ship);
            }

            foreach (HttpPostedFileBase file in files)
            {
                if (file == null) { continue; }
                if (shipUrlData.CheckDuplicateUrl(ref_id, file.FileName, Server.MapPath("~/Content/images/")))
                {
                    if (filer.CompareSizeOfFile(file, Server.MapPath("~/Content/images/" + ref_id + "_" + file.FileName)))
                    {
                        continue;
                    }
                }
                ShipUrl shipUrl = new ShipUrl();

                photo = filer.FileToImage(file);
                preview = resizer.Resize(photo, 320, 240);
                byte[] previewByte = filer.ImageToBytes(preview);

                shipUrl.refId = ref_id;
                shipUrl.preview = previewByte;

                string filename = savingPath + ref_id + "_" + file.FileName;

                /*if (filer.FileExists("", filename))
                {
                    while (filer.FileExists("", filename))
                    {
                        filename = filer.renameFile("", filename);
                    }
                }*/ //başına ref_id eklendiğinden kullanımına gerek kalmadı

                filer.SaveFile(photo, "", filename); //filename'e zaten dosya adından öncesi eklendi
                shipUrl.imageUrl = filename;

                shipUrlData.AddShipUrl(shipUrl);
                photo.Dispose();
                preview.Dispose();
            }

            return true;
        }
Пример #4
0
        /// <summary>
        /// Bir gemi kaydına ait bilgileri günceller.
        /// </summary>
        /// <param name="ship"></param>
        /// <returns></returns>
        public void UpdateShip(Ship ship)
        {
            string query = "update ship set ship_id=@ship_id,date_time=@date_time,description=@description,updated_by=@updated_by,updated_pc=@updated_pc,updated_datetime=@updated_datetime where ref_id=@ref_id";

            MySqlCommand cmd = new MySqlCommand(query, con);
            cmd.Parameters.AddWithValue("@ship_id", ship.shipId);
            cmd.Parameters.AddWithValue("@date_time", ship.time);
            cmd.Parameters.AddWithValue("@description", ship.description);
            cmd.Parameters.AddWithValue("@updated_by", ship.updatedBy);
            cmd.Parameters.AddWithValue("@updated_pc", ship.updatedPc);
            cmd.Parameters.AddWithValue("@updated_datetime", ship.updatedDatetime);
            cmd.Parameters.AddWithValue("@ref_id",ship.refId);

            Open();
            cmd.ExecuteNonQuery();
            Close();
        }
Пример #5
0
        /// <summary>
        /// Bir tanım ID'sine sahip gemileri döndürür.
        /// </summary>
        /// <param name="ship_id"></param>
        /// <returns>Ship sınıfından nesnelerin listesini döndürür.</returns>
        public List<Ship> GetShipsByName(int ship_id)
        {
            List<Ship> ships = new List<Ship>();
            string query = "select ref_id,date_time from ship where ship_id=@ship_id";

            MySqlCommand cmd = new MySqlCommand(query, con);
            cmd.Parameters.AddWithValue("@ship_id", ship_id);

            Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Ship ship = new Ship();
                ship.refId = Convert.ToString(reader["ref_id"]);
                ship.shipId = ship_id;
                ship.time = Convert.ToDateTime(reader["date_time"]);
                ships.Add(ship);
            }
            Close();
            return ships;
        }
Пример #6
0
        /// <summary>
        /// Başlangıç ve bitiş tarihi verilen gemi kayıtlarını döndürür.
        /// </summary>
        /// <param name="begin"></param>
        /// <param name="end"></param>
        /// <returns>Ship sınıfından nesnelerin listesini döndürür.</returns>
        public List<Ship> GetShipsBetweenDate(DateTime begin, DateTime end)
        {
            List<Ship> ships = new List<Ship>();

            string query = "select ref_id,ship_id,date_time from ship where date_time between @begin and @end";

            MySqlCommand cmd = new MySqlCommand(query, con);
            cmd.Parameters.AddWithValue("@begin", begin);
            cmd.Parameters.AddWithValue("@end", end);

            Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Ship ship = new Ship();
                ship.refId = Convert.ToString(reader["ref_id"]);
                ship.shipId = Convert.ToInt32(reader["ship_id"]);
                ship.time = Convert.ToDateTime(reader["date_time"]);
                ships.Add(ship);
            }
            Close();
            return ships;
        }
Пример #7
0
        /// <summary>
        /// Gemi veritabanından, Referans ID'si verilen bir geminin istenen özelliklerini, Ship sınıfından bir nesneye atar.
        /// </summary>
        /// <param name="ref_id"></param>
        /// <returns>İstenen özelliklerle birlikte bir Ship nesnesi döndürür.</returns>
        public Ship GetShip(string ref_id)
        {
            Ship ship = new Ship();

            string query = "select * from ship where ref_id = @ref_id";

            MySqlCommand cmd = new MySqlCommand(query, con);
            cmd.Parameters.AddWithValue("@ref_id", ref_id);

            Open();
            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ship.refId = Convert.ToString(reader["ref_id"]);
                ship.shipId = Convert.ToInt32(reader["ship_id"]);
                ship.time = Convert.ToDateTime(reader["date_time"]);
                ship.description = Convert.ToString(reader["description"]);
                ship.createdBy = Convert.ToString(reader["created_by"]);
            }
            Close();

            return ship;
        }
Пример #8
0
        /// <summary>
        /// Bir kullanıcının girdiği tüm gemi kayıtlarını çeker.
        /// </summary>
        /// <param name="username"></param>
        /// <returns>Ship listesi döndürür.</returns>
        public List<Ship> GetRecords(string username)
        {
            string query = "select ref_id,ship_id,date_time,description from ship where created_by=@created_by";

            List<Ship> records = new List<Ship>();

            MySqlCommand cmd = new MySqlCommand(query, con);
            cmd.Parameters.AddWithValue("@created_by", username);

            Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Ship ship = new Ship();
                ship.refId = Convert.ToString(reader["ref_id"]);
                ship.shipId = Convert.ToInt32(reader["ship_id"]);
                ship.time = Convert.ToDateTime(reader["date_time"]);
                ship.description = Convert.ToString(reader["description"]);
                records.Add(ship);
            }
            Close();

            return records;
        }