public ActionResult ReceiveBlackBox(BlackBoxTransaction Btx) {
      if (!exLogic.User.hasAccess("BLACKBOX.RECEIVE"))
        return RedirectToAction("NoAccess", "Home");
      string StartDate = Request.Form["hdnRentStartDate"];
      string tAmount = Request.Form["hdnTotalAmount"];
      string DroneID = Request.Form["DroneID"];
      if ((Convert.ToDateTime(Btx.RentEndDate)) < (Convert.ToDateTime(StartDate))) {
        ModelState.AddModelError("RentEndDate", "Rent End Date should be greater than Start Date!!");
        Btx.BBStatus = "IN";
        return View(Btx);
      }
      string sDate = Convert.ToDateTime(StartDate).ToString("yyyy/MM/dd");
      string eDate = Convert.ToDateTime(Btx.RentEndDate).ToString("yyyy/MM/dd");

      string ye;

      ye = " RentStartDate='" + sDate + "',  RentEndDate='" + eDate + "', Amount='" + Btx.Amount + "',TotalAmount = " + (tAmount == "" ? 0 : Util.toDecimal(tAmount)) + "";
      //ye = " Amount='" + Btx.Amount + "',TotalAmount = " + (tAmount == "" ? 0 : Util.toDecimal(tAmount)) + "";

      string SQL = "update BlackBoxTransaction set BBStatus = 'IN', Note = '" + Btx.Note + "',CreatedBy='" + Util.getLoginUserID() + "'," + ye + " where ID = " + GetLastTransactionID(Btx.BlackBoxID);
      //need to appnd after testing

      int Val = Util.doSQL(SQL);

      SQL = "update MSTR_BlackBox set LastReceiveId = '" + GetLastTransactionID(Btx.BlackBoxID) + "',CurrentStatus='IN',CurrentUserID = '" + Util.getLoginUserID() + "',CurrentDroneID=31 where BlackBoxID = " + Btx.BlackBoxID;
      Val = Util.doSQL(SQL);

      SQL = "update dbo.MSTR_Drone set BlackBoxID = 0 where DroneId = " + Btx.DroneID;
      Val = Util.doSQL(SQL);


      return RedirectToAction("BlackBoxList", "Blackbox");
      //return View();
    }
    public ActionResult Acknowledgement([Bind(Prefix = "ID")] int TransactionID = 0) {
      //   if (!exLogic.User.hasAccess("BLACKBOX.EDIT")) return RedirectToAction("NoAccess", "Home");
      ViewBag.Title = "Blackbox Rental";

      BlackBoxTransaction btx = new BlackBoxTransaction();
      if (TransactionID != 0) {
        btx = db.BlackBoxTransactions.Find(TransactionID);
        if (btx == null)
          return RedirectToAction("Error", "Home");
      }
      return View(btx);

    }
    public ActionResult Acknowledgement(BlackBoxTransaction BBTransaction) {
      string sqlscript = "select count(*) from dbo.BlackBoxTransaction where ID = " + BBTransaction.ID + " and isnull(verifycode,'') = '" + BBTransaction.VerifyCode + "' ";

      int Count = Util.getDBRows(sqlscript).Count;
      if (Count > 0) {
        sqlscript = "update dbo.BlackBoxTransaction set RentAcknowledged = 1 where ID = " + BBTransaction.ID;
        Count = Util.doSQL(sqlscript);
        return RedirectToAction("Index", "Home");
      } else {
        BlackBoxTransaction btx = new BlackBoxTransaction();
        ViewBag.ErrorStatus = 1;
        return View(btx);
      }
    }
    public int GetLastTransactionID(int BlackBoxID = 0) {
      try {
        var lastID = (
           from y in db.MSTR_BlackBox
           where y.BlackBoxID == BlackBoxID
           select y.LastRentalId
             ).FirstOrDefault();

        BlackBoxTransaction btx = (
            from n in db.BlackBoxTransactions
            where n.ID == lastID
            select n
          ).FirstOrDefault();
        return btx.ID;
      } catch  {
        return 0;
      }
    }
    //Get:BlackBoxCost/Rent
    public ActionResult Rent([Bind(Prefix = "ID")] int BlackBoxID = 0) {
      if (!exLogic.User.hasAccess("BLACKBOX.RENT"))
        return RedirectToAction("NoAccess", "Home");

      //BlackBoxViewModel BV = new BlackBoxViewModel();
      //BV.BlackBoxCostList = new List<List<BlackBoxCostCalucation>>();


      BlackBoxTransaction btx = new BlackBoxTransaction();
      if (BlackBoxID != 0) {
        btx = db.BlackBoxTransactions.Find(BlackBoxID);
        if (btx == null)
          return RedirectToAction("Error", "Home");
      }
      btx.BBStatus = "OUT";
            btx.Note = "Given";
      return View(btx);

    }
    public JsonResult BlackBoxInfo(
      [Bind(Prefix = "ID")] int BlackBoxID = 0,
      DateTime? StartDate = null,
      DateTime? EndDate = null ) {

      var lastID = (
          from y in db.MSTR_BlackBox
          where y.BlackBoxID == BlackBoxID
          select y.LastRentalId
            ).FirstOrDefault();

      BlackBoxTransaction btx = (
          from n in db.BlackBoxTransactions
          where n.ID == lastID
          select n
        ).FirstOrDefault();

      //if (btx == null)
      //  return Json(new BlackBox(), JsonRequestBehavior.AllowGet);

      if(btx != null) { 
        if (StartDate == null)
          StartDate = btx.RentStartDate == null ? System.DateTime.Now : btx.RentStartDate;
        if (EndDate == null)
          EndDate = btx.RentEndDate == null ? System.DateTime.Now : btx.RentEndDate;
        //get the information of calucation for the dates
        //ViewData["RAmount"] = btx.Amount == null ? 0 : btx.Amount;
      }

      if (StartDate == null || EndDate == null)
        return Json(new BlackBox(), JsonRequestBehavior.AllowGet);

      var NumDays = (int)((TimeSpan)(StartDate - EndDate)).TotalDays;
      if (NumDays < 0)
        NumDays = -1 * NumDays;
      var BB = new BlackBox();
      var BBInfo = new {
        Cost = BB.getBlackBoxCost(NumDays),
        Info = btx
      };
      //      ViewData["BalanceAmount"] = totalAmt;
      return Json(BBInfo, JsonRequestBehavior.AllowGet);
    }
    public JsonResult BlackBoxTransAmountPaidVal([Bind(Prefix = "ID")] int BlackBoxID = 0) {
      var lastID = (
          from y in db.MSTR_BlackBox
          where y.BlackBoxID == BlackBoxID
          select y.LastRentalId
            ).FirstOrDefault();

      BlackBoxTransaction btx = (
          from n in db.BlackBoxTransactions
          where n.ID == lastID
          select n
        ).FirstOrDefault();

      decimal? Amount = 0;
      if (btx != null)
        Amount = btx.Amount;

      return Json(Amount, JsonRequestBehavior.AllowGet);

    }
    public ActionResult ReceiveBlackBox([Bind(Prefix = "ID")] int BlackBoxTransID = 0) {
      if (!exLogic.User.hasAccess("BLACKBOX.RECEIVE"))
        return RedirectToAction("NoAccess", "Home");
      BlackBoxTransaction btx = new BlackBoxTransaction();
      if (BlackBoxTransID != 0) {
        btx = db.BlackBoxTransactions.Find(BlackBoxTransID);
        if (btx == null)
          return RedirectToAction("Error", "Home");

        //BlackBoxTransaction btxTran = (
        //                 from n in db.BlackBoxTransactions
        //                 where n.ID == BlackBoxTransID
        //                 select n
        //               ).FirstOrDefault();
        //btx.ID = btxTran.BlackBoxID;
      }
      btx.RentStartDate = btx.RentStartDate == null ? System.DateTime.Now : btx.RentStartDate;
      btx.RentEndDate = btx.RentEndDate == null ? System.DateTime.Now : btx.RentEndDate;
      btx.BBStatus = "IN";
      return View(btx);
    }
    public JsonResult BlackBoxTransDroneVal([Bind(Prefix = "ID")] int BlackBoxID = 0) {
      var lastID = (
          from y in db.MSTR_BlackBox
          where y.BlackBoxID == BlackBoxID
          select y.LastRentalId
            ).FirstOrDefault();

      BlackBoxTransaction btx = (
          from n in db.BlackBoxTransactions
          where n.ID == lastID
          select n
        ).FirstOrDefault();


      int? DroneID = 0;
      if (btx != null)
        DroneID = btx.DroneID;

      return Json(DroneID, JsonRequestBehavior.AllowGet);

    }
Beispiel #10
0
    public ActionResult Rental(BlackBoxTransaction BBTransaction) {
      if (!exLogic.User.hasAccess("BLACKBOX.RENT"))
        return RedirectToAction("NoAccess", "Home");
      ModelState.Remove("Note");
      ModelState.Remove("VerifyCode");
      if (ModelState.IsValid) {
        BBTransaction.BBStatus = "OUT";
        BBTransaction.CreatedBy = Session["UserID"].ToString();
        BBTransaction.DroneID = Convert.ToInt32(TempData["Droneid"]);
        BBTransaction.ApprovalID = Convert.ToInt32(TempData["Approvalid"]);


        string insertsql = "insert into[BlackBoxTransaction] ([BlackBoxID] \n" +
                 ",[BBStatus] \n" +
                 ",[CollectionMode] \n" +
                 ",[NameOnCard] \n" +
                 ",[BankName] \n" +
                 ",[Amount] \n" +
                 ",[ChequeNumber] \n" +
                 ",[CreatedDate] \n" +
                 ",[CreatedBy] \n" +
                 ",[DroneID] \n" +
                 ",[RentType] \n" +
                 ",[RentAmount] \n" +
                 ",[ApprovalID])values( \n" +
                 BBTransaction.BlackBoxID + ",'OUT','" + BBTransaction.CollectionMode + "','" + BBTransaction.NameOnCard + "','" + BBTransaction.BankName + "',\n" +
                 BBTransaction.Amount + ",'" + BBTransaction.ChequeNumber + "'," + "sysdatetime()" + ",'\n" +
                 BBTransaction.CreatedBy + "'," + BBTransaction.DroneID + ",'" + BBTransaction.RentType + "','" + BBTransaction.RentAmount + "'," + BBTransaction.ApprovalID + ")";
        int bbtransctionid = Util.InsertSQL(insertsql);
        string bbupdatesql = "update [MSTR_BlackBox] set [LastRentalId]=" + bbtransctionid + ",[CurrentStatus]='OUT',CurrentUserID=" + Convert.ToInt32(Session["UserID"].ToString()) + ",CurrentDroneID=" + Convert.ToInt32(TempData["Droneid"]) + " where [BlackBoxID]=" + BBTransaction.BlackBoxID;
        Util.doSQL(bbupdatesql);
        string droneupdatesql = "update [MSTR_Drone] set [BlackBoxID]=" + BBTransaction.BlackBoxID + " where [DroneId]=" + BBTransaction.DroneID;
        Util.doSQL(droneupdatesql);
        return RedirectToAction("AllApplications", "Rpas");
      }
      return View();
    }
Beispiel #11
0
    public ActionResult Rent(BlackBoxTransaction Btx) {
      if (!exLogic.User.hasAccess("BLACKBOX.RENT"))
        return RedirectToAction("NoAccess", "Home");
      Nullable<int> DroneID = Btx.DroneID;
      Nullable<int> BlackBoxID = Btx.BlackBoxID;
      ModelState.Remove("Amount");
      if (Btx.DroneID < 1 || Btx.DroneID == null) {
        ModelState.AddModelError("DroneID", "You must select a Drone.");
        Btx.BBStatus = "OUT";
        return View(Btx);
      }

      if ((Btx.RentStartDate == null) || (Btx.RentEndDate == null)) {
        ModelState.AddModelError("RentStartDate", "Please select both dates!!");
        Btx.BBStatus = "OUT";
        return View(Btx);
      }

      string sDate = Convert.ToDateTime(Btx.RentStartDate).ToString("yyyy/MM/dd");
      string eDate = Convert.ToDateTime(Btx.RentEndDate).ToString("yyyy/MM/dd");
      if (Convert.ToDateTime(Btx.RentEndDate).Date < Convert.ToDateTime(Btx.RentStartDate).Date) {
        ModelState.AddModelError("RentEndDate", "Rent end date should be greater than rent start date!!");
        Btx.BBStatus = "OUT";
        return View(Btx);
      }
      string SQL = "insert into blackboxtransaction(DroneID,BBstatus,Note,createdby,Blackboxid,amount,rentamount,RentStartDate,RentEndDate,UserID) values(" + Btx.DroneID + ",'OUT','" + Btx.Note + "'," + Util.getLoginUserID() + "," + BlackBoxID + "," + Util.toInt(Btx.Amount) + "," + Util.toInt(Btx.RentAmount) + ",'" + sDate + "','" + eDate + "',"+Btx.UserID+")";
      //  string SQL = "update BlackBoxTransaction set DroneID = '0', BBStatus = '" + Btx.BBStatus + "', Note = '" + Btx.Note + "',CreatedBy='" + Util.getLoginUserID() + "' where ID = " + Btx.ID;

      int bbtransctionid = Util.InsertSQL(SQL);


      SQL = "update MSTR_BlackBox  set [LastRentalId]=" + bbtransctionid + ", CurrentStatus='OUT',CurrentUserID = '" + Btx.UserID + "',CurrentDroneID=" + Btx.DroneID + " where BlackBoxID = " + BlackBoxID;
      int Val = Util.doSQL(SQL);

      SQL = "update MSTR_Drone set BlackBoxID =" + BlackBoxID + " where DroneId = " + Btx.DroneID;
      Val = Util.doSQL(SQL);

            SQL = "select DroneSetupId from MSTR_Drone_Setup where DroneId=" + Btx.DroneID;
            int DroneSetupId = Util.getDBInt(SQL);
            if (DroneSetupId == 0)
            {
                SQL = @"INSERT INTO MSTR_Drone_Setup (
            DroneID,
            CreatedBy,
            CreatedOn,
            [ModifiedOn]
          ) VALUES (
            " + DroneID + @",
            " + Util.getLoginUserID() + @",
            GETDATE(),
            GETDATE()
          )";
                Util.doSQL(SQL);
            }
            SQL = @"update 
          MSTR_Drone_Setup 
        set 
          PilotUserId=" + Btx.UserID + @",
          GroundStaffUserId=" + Btx.UserID + @",        
          [ModifiedBy]=" + Util.getLoginUserID() + @",
          [ModifiedOn]=GETDATE()
        where 
          [DroneId]=" + DroneID;
            Util.doSQL(SQL);

            return RedirectToAction("BlackBoxList", "Blackbox");
    }