示例#1
0
        private void RemoveOldImageAndThenSaveImageDuringClientUpdate(ref Deposit deposit_Db, Deposit deposit_Details, string type, HttpPostedFileBase image)
        {
            RemoveImageFromServerFolder(type, deposit_Db);



            byte[] imagebyte = null;

            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(image.FileName);
            string extension = Path.GetExtension(image.FileName);
            var    fileName  = deposit_Db.DepositID + "_" + type + "" + extension;

            string fileSaveInFolder = Path.Combine(Server.MapPath("~/images/Deposit"), fileName);

            image.SaveAs(fileSaveInFolder);


            BinaryReader reader = new BinaryReader(image.InputStream);

            imagebyte = reader.ReadBytes(image.ContentLength);

            Image  returnImage = byteArrayToImage(imagebyte);
            Bitmap bp          = ResizeImage(returnImage, 200, 200);

            imagebyte = imageToByteArray(bp);

            if (type == "DescriptionFile")
            {
                deposit_Db.DescriptionFilePath = "/images/Deposit/" + fileName;
            }
        }
示例#2
0
        private void SaveImageInFolderAndAddInformationInVendorTable(ref Deposit depositInfo, string Type, HttpPostedFileBase descriptionImage)
        {
            if (!IsValidContentType(descriptionImage.ContentType))
            {
                ViewBag.Error = "Only PNG image are allowed";
            }

            byte[] imagebyte = null;

            string fileNameWithExtension    = Path.GetFileName(descriptionImage.FileName);
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(descriptionImage.FileName);
            string extension = Path.GetExtension(descriptionImage.FileName);
            var    fileName  = depositInfo.DepositID + "_" + Type + "" + extension;

            string fileSaveInFolder = Path.Combine(Server.MapPath("~/images/Deposit"), fileName);

            descriptionImage.SaveAs(fileSaveInFolder);


            BinaryReader reader = new BinaryReader(descriptionImage.InputStream);

            imagebyte = reader.ReadBytes(descriptionImage.ContentLength);

            Image  returnImage = byteArrayToImage(imagebyte);
            Bitmap bp          = ResizeImage(returnImage, 200, 200);

            imagebyte = imageToByteArray(bp);

            depositInfo.DescriptionFileByte = imagebyte;
            depositInfo.DescriptionFilePath = "/images/Deposit/" + fileName;
        }
示例#3
0
        public ActionResult UpdateDeposit(FormCollection form, HttpPostedFileBase DepositUpdateImage)
        {
            Deposit Deposit_Details = JsonConvert.DeserializeObject <Deposit>(form["Deposit_details"]);
            Deposit Deposit_Db      = db.Deposit.Where(s => s.DepositID == Deposit_Details.DepositID).FirstOrDefault();

            try
            {
                AddGivenImageInCurrentRow(ref Deposit_Db, Deposit_Details, "DescriptionFile", DepositUpdateImage, form["DescriptionFilePath"]);

                if (Deposit_Db.DepositID > 0)
                {
                    SetClientDepositToDatabaseDB(ref Deposit_Db, Deposit_Details);

                    db.Entry(Deposit_Db).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    AccountingHistory accountingHistory = db.AccountingHistory.Where(x => x.DepositID == Deposit_Db.DepositID).FirstOrDefault();
                    //Mode 1 mean Create 2 mean Update
                    SetInformationForAccountHistory(ref accountingHistory, Deposit_Db, 2);
                    db.AccountingHistory.Add(accountingHistory);
                    db.SaveChanges();
                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
 private void SetClientDepositToDatabaseDB(ref Deposit Deposit_Db, Deposit Deposit_Details)
 {
     Deposit_Db.AccountListID = Deposit_Details.AccountListID;
     Deposit_Db.DepositDate   = Deposit_Details.DepositDate;
     Deposit_Db.Description   = Deposit_Details.Description;
     Deposit_Db.Amount        = Deposit_Details.Amount;
     Deposit_Db.HeadID        = Deposit_Details.HeadID;
     Deposit_Db.CompanyID     = Deposit_Details.CompanyID;
     Deposit_Db.PayerID       = Deposit_Details.PayerID;
     Deposit_Db.PaymentByID   = Deposit_Details.PaymentByID;
     Deposit_Db.DepositStatus = Deposit_Details.DepositStatus;
     Deposit_Db.References    = Deposit_Details.References;
     Deposit_Db.UpdateBy      = AppUtils.GetLoginUserID();
     Deposit_Db.UpdateDate    = AppUtils.GetDateTimeNow();
 }
示例#5
0
        private void RemoveImageFromServerFolder(string type, Deposit deposit_Db)
        {
            string removeImageName = "";

            if (type == "DescriptionFile")
            {
                removeImageName = !string.IsNullOrEmpty(deposit_Db.DescriptionFilePath) ? deposit_Db.DescriptionFilePath.Split('/')[3] : "";
            }

            var filePath = Server.MapPath("~/images/Deposit/" + removeImageName);

            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
        }
示例#6
0
 private void AddGivenImageInCurrentRow(ref Deposit deposit_Db, Deposit deposit_Details, string type, HttpPostedFileBase image, string imagePath)
 {
     if (type == "DescriptionFile")
     {
         if (image != null && imagePath != null)
         {
             RemoveOldImageAndThenSaveImageDuringClientUpdate(ref deposit_Db, deposit_Details, "DescriptionFile", image);
         }
         else if (!string.IsNullOrEmpty(imagePath))
         {
             deposit_Details.DescriptionFilePath = deposit_Db.DescriptionFilePath;
         }
         else
         {
             RemoveImageFromServerFolder(type, deposit_Db);
             deposit_Db.DescriptionFilePath = null;
             deposit_Db.DescriptionFileByte = null;
         }
     }
 }
示例#7
0
        public ActionResult InsertNewDeposit(FormCollection form, HttpPostedFileBase DescriptionImage)
        {
            Deposit DepositInfo   = JsonConvert.DeserializeObject <Deposit>(form["NewDepositInformation"]);
            Deposit DepositReturn = new Deposit();

            try
            {
                DepositInfo.Status     = AppUtils.TableStatusIsActive;
                DepositInfo.CreateBy   = AppUtils.GetLoginUserID();
                DepositInfo.CreateDate = AppUtils.GetDateTimeNow();
                DepositReturn          = db.Deposit.Add(DepositInfo);
                db.SaveChanges();
                if (DescriptionImage != null)
                {
                    SaveImageInFolderAndAddInformationInVendorTable(ref DepositInfo, "Description", DescriptionImage);
                }
                if (DepositReturn.DepositID > 0)
                {
                    db.SaveChanges();

                    AccountingHistory accountingHistory = new AccountingHistory();
                    //Mode 1 mean Create 2 mean Update
                    SetInformationForAccountHistory(ref accountingHistory, DepositReturn, 1);
                    db.AccountingHistory.Add(accountingHistory);
                    db.SaveChanges();

                    return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { success = false }, JsonRequestBehavior.AllowGet));
            }
        }
示例#8
0
        private void SetInformationForAccountHistory(ref Models.AccountingHistory accountingHistory, Deposit Deposit, int CreateOrUpdate)
        {
            DateTime dt = AppUtils.GetDateTimeNow();

            accountingHistory.Amount = Convert.ToDouble(Deposit.Amount);
            if (CreateOrUpdate == 1)//mean create
            {
                accountingHistory.DepositID    = Deposit.DepositID;
                accountingHistory.ActionTypeID = (int)AppUtils.AccountingHistoryType.Deposit;
                accountingHistory.Date         = AppUtils.GetDateTimeNow();
                accountingHistory.DRCRTypeID   = (int)AppUtils.AccountTransactionType.CR;
                accountingHistory.Description  = !string.IsNullOrEmpty(Deposit.Description) ? Deposit.Description : db.Head.Find(Deposit.HeadID).HeadeName;
                accountingHistory.Year         = dt.Year;
                accountingHistory.Month        = dt.Month;
                accountingHistory.Day          = dt.Day;
                accountingHistory.CreateBy     = AppUtils.GetLoginUserID();
                accountingHistory.CreateDate   = dt;
                accountingHistory.Status       = AppUtils.TableStatusIsActive;
            }
            else
            {
                accountingHistory.UpdateBy   = AppUtils.GetLoginUserID();
                accountingHistory.UpdateDate = dt;
            }
        }