Пример #1
2
        private String saveFile(HttpPostedFile postedFile)
        {
            int userID = 0;
            string userName = getUserNameFromFile(postedFile);
            EReceiptLINQDataContext context = new EReceiptLINQDataContext();

            var lastReceiptNumber = from num in context.Receipts
                                    select num;

            int maxReceiptValue = (from c in lastReceiptNumber select c.RECEIPT_ID).Max();

            string savePath = ("~/IMG/receiptImage/" + userName + "/receipt" + (maxReceiptValue + 1) + ".jpg");
            DirectoryCheck(userName);
            FileUpload1.SaveAs(Server.MapPath(savePath));

            string pathOfFile = "http://localhost:49765/" + savePath.Substring(savePath.IndexOf("~") + 2);

            Receipt receiptImage = new Receipt
            {
                RECEIPT_URL = pathOfFile,
                UPLOAD_DATE = DateTime.Now,

            };
            context.Receipts.InsertOnSubmit(receiptImage);
            context.SubmitChanges();

            var userIDNumber = from u in context.Customers
                               where u.USER_NAME == userName
                               select u;

            foreach (var x in userIDNumber)
            {
                userID = x.USER_ID;
                break;
            }

            CustomerReceipt custRec = new CustomerReceipt
            {
                USER_ID = userID,
                RECEIPT_ID = (maxReceiptValue + 1),

            };
            context.CustomerReceipts.InsertOnSubmit(custRec);
            context.SubmitChanges();

            context.Connection.Close();
            Label1.Text = "Upload Successful";
            return savePath;
        }
Пример #2
0
        public CustomerReceipt UpdateCustomerReceipt(CustomerReceipt objCustomerReceipt)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                if (objCustomerReceipt.Against == "JC")
                {
                    objCustomerReceipt.SaleOrderId    = null;
                    objCustomerReceipt.SalesInvoiceId = null;
                }
                if (objCustomerReceipt.Against == "SO")
                {
                    objCustomerReceipt.JobCardId      = null;
                    objCustomerReceipt.SalesInvoiceId = null;
                }
                if (objCustomerReceipt.Against == "SI")
                {
                    objCustomerReceipt.JobCardId   = null;
                    objCustomerReceipt.SaleOrderId = null;
                }

                string sql = @" UPDATE CustomerReceipt SET CustomerReceiptRefNo = @CustomerReceiptRefNo ,CustomerReceiptDate=@CustomerReceiptDate,CustomerId=@CustomerId,
                                SaleOrderId=@SaleOrderId,JobCardId=@JobCardId,SalesInvoiceId=@SalesInvoiceId,SaleOrderAmount=@SaleOrderAmount,Amount=@Amount,
                                SpecialRemarks=@SpecialRemarks,CreatedBy = @CreatedBy,CreatedDate = @CreatedDate,OrganizationId = @OrganizationId
                                WHERE CustomerReceiptId = @CustomerReceiptId";

                var id = connection.Execute(sql, objCustomerReceipt);
                InsertLoginHistory(dataConnection, objCustomerReceipt.CreatedBy, "Update", "Customer Receipt", id.ToString(), "0");
                return(objCustomerReceipt);
            }
        }
Пример #3
0
        public int DeleteCustomerReceipt(CustomerReceipt objCustomerReceipt)
        {
            int result = 0;

            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string sql = @" UPDATE CustomerReceipt SET isActive=0 WHERE CustomerReceiptId=@CustomerReceiptId";
                try
                {
                    var id = connection.Execute(sql, objCustomerReceipt);
                    objCustomerReceipt.CustomerReceiptId = id;
                    result = 0;
                    InsertLoginHistory(dataConnection, objCustomerReceipt.CreatedBy, "Delete", "Customer Receipt", id.ToString(), "0");
                }
                catch (SqlException ex)
                {
                    int err = ex.Errors.Count;
                    if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error
                    {
                        switch (ex.Errors[0].Number)
                        {
                        case 547:     // Foreign Key violation
                            result = 1;
                            break;

                        default:
                            result = 2;
                            break;
                        }
                    }
                }

                return(result);
            }
        }
        public ActionResult Delete(CustomerReceipt model)
        {
            int result = new CustomerReceiptRepository().DeleteCustomerReceipt(model);

            if (result == 0)
            {
                TempData["Success"] = "Deleted Successfully!";
                TempData["CustomerReceiptRefNo"] = model.CustomerReceiptRefNo;
                return(RedirectToAction("Index"));
            }
            else
            {
                if (result == 1)
                {
                    TempData["error"] = "Sorry!! You Cannot Delete This Customer Receipt. It Is Already In Use";
                    TempData["CustomerReceiptRefNo"] = null;
                }
                else
                {
                    TempData["error"] = "Oops!!..Something Went Wrong!!";
                    TempData["CustomerReceiptRefNo"] = null;
                }
                return(RedirectToAction("Index"));
            }
        }
        public ActionResult Edit(CustomerReceipt model, int Code = 0)
        {
            ViewBag.Title        = "Edit";
            model.OrganizationId = OrganizationId;
            model.CreatedDate    = System.DateTime.Now;
            model.CreatedBy      = UserID.ToString();

            var repo = new CustomerReceiptRepository();
            //bool isexists = repo.IsFieldExists(repo.ConnectionString(), "CustomerReceipt", "CustomerReceiptRefNo", model.CustomerReceiptRefNo, "CustomerReceiptId", model.CustomerReceiptId);
            //if (!isexists)
            {
                var result = new CustomerReceiptRepository().UpdateCustomerReceipt(model);
                if (result.CustomerReceiptId > 0)
                {
                    TempData["Success"] = "Updated Successfully!";
                    TempData["CustomerReceiptRefNo"] = result.CustomerReceiptRefNo;
                    return(RedirectToAction("Index"));
                }

                else
                {
                    FillCustomer();
                    FillSaleOrder(Code);
                    FillJobCard(Code);
                    FillSalesInvoice(Code);
                    //FillSO();
                    //FillJC();
                    //FillSI();
                    TempData["error"] = "Oops!!..Something Went Wrong!!";
                    TempData["CustomerReceiptRefNo"] = null;
                    return(View("Create", model));
                }
            }
        }
        public CustomerReceiptVM(ObservableCollection <Product> products)
        {
            Window window = new CustomerReceipt();

            window.Show();
            window.DataContext   = this;
            HandleLogoutBtn      = new DelegateCommand(Logout, CanLogout);
            purchasedProductList = products;
            TotalAmount          = "Total Amount = " + GetTotalAmount();
        }
Пример #7
0
        private String saveFile(HttpPostedFile postedFile)
        {
            int    userID   = 0;
            string userName = getUserNameFromFile(postedFile);
            EReceiptLINQDataContext context = new EReceiptLINQDataContext();

            var lastReceiptNumber = from num in context.Receipts
                                    select num;

            int maxReceiptValue = (from c in lastReceiptNumber select c.RECEIPT_ID).Max();



            string savePath = ("~/IMG/receiptImage/" + userName + "/receipt" + (maxReceiptValue + 1) + ".jpg");

            DirectoryCheck(userName);
            FileUpload1.SaveAs(Server.MapPath(savePath));

            string pathOfFile = "http://localhost:49765/" + savePath.Substring(savePath.IndexOf("~") + 2);

            Receipt receiptImage = new Receipt
            {
                RECEIPT_URL = pathOfFile,
                UPLOAD_DATE = DateTime.Now,
            };

            context.Receipts.InsertOnSubmit(receiptImage);
            context.SubmitChanges();

            var userIDNumber = from u in context.Customers
                               where u.USER_NAME == userName
                               select u;


            foreach (var x in userIDNumber)
            {
                userID = x.USER_ID;
                break;
            }


            CustomerReceipt custRec = new CustomerReceipt
            {
                USER_ID    = userID,
                RECEIPT_ID = (maxReceiptValue + 1),
            };

            context.CustomerReceipts.InsertOnSubmit(custRec);
            context.SubmitChanges();

            context.Connection.Close();
            Label1.Text = "Upload Successful";
            return(savePath);
        }
Пример #8
0
        public int InsertCustomerReceipt(CustomerReceipt model)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                IDbTransaction txn = connection.BeginTransaction();
                try
                {
                    int internalId = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, txn, typeof(CustomerReceipt).Name, "0", 1);

                    model.CustomerReceiptRefNo = "CR/" + internalId;

                    if (model.Against == "JC")
                    {
                        model.SaleOrderId    = null;
                        model.SalesInvoiceId = null;
                    }
                    if (model.Against == "SO")
                    {
                        model.JobCardId      = null;
                        model.SalesInvoiceId = null;
                    }
                    if (model.Against == "SI")
                    {
                        model.JobCardId   = null;
                        model.SaleOrderId = null;
                    }
                    string sql = @"INSERT INTO CustomerReceipt
                                 (CustomerReceiptRefNo,CustomerReceiptDate,CustomerId,
	                             SaleOrderId,JobCardId,SalesInvoiceId,SaleOrderAmount,
                                 Amount,SpecialRemarks,CreatedBy,CreatedDate,OrganizationId,isActive)
                                 VALUES
                                (@CustomerReceiptRefNo,@CustomerReceiptDate,@CustomerId,
                                 @SaleOrderId,@JobCardId,@SalesInvoiceId,@SaleOrderAmount,
                                 @Amount,@SpecialRemarks,@CreatedBy,@CreatedDate,@OrganizationId,1)
                                 SELECT CAST(SCOPE_IDENTITY() AS INT)";
                    var    id  = connection.Query <int>(sql, model, txn).Single();
                    InsertLoginHistory(dataConnection, model.CreatedBy, "Create", "Customer Receipt", id.ToString(), "0");
                    txn.Commit();
                    return(id);
                }
                catch (Exception)
                {
                    txn.Rollback();
                    return(0);
                }
            }
        }
 public ActionResult CreateRequest(CustomerReceipt model, int Code = 0)
 {
     FillSaleOrder(Code);
     FillJobCard(Code);
     FillSalesInvoice(Code);
     //FillSO();
     //FillJC();
     //FillSI();
     model.OrganizationId = OrganizationId;
     model.CreatedDate    = System.DateTime.Now;
     model.CreatedBy      = UserID.ToString();
     if (new CustomerReceiptRepository().InsertCustomerReceipt(model) > 0)
     {
         TempData["success"] = "Saved successfully";
         TempData["error"]   = "";
         return(RedirectToAction("CreateRequest"));
     }
     else
     {
         TempData["success"] = "";
         TempData["error"]   = "Some error occured. Please try again.";
         return(View("Create", model));
     }
 }