Example #1
0
        public ActionResult SheetCreateEdit(HG_Tables_or_Sheat ObjTable)
        {
            if (ObjTable.QrCode == null || ObjTable.QrCode.Replace(" ", "") == "")
            {
                return(Json(new { msg = "Please Enter Qr Code" }));
            }
            List <HG_Tables_or_Sheat> ListOfSeat = new HG_Tables_or_Sheat().GetAll(2);//Sheat
            var SeatExt = ListOfSeat.Find(x => x.Table_or_SheetName.ToUpper() == ObjTable.Table_or_SheetName.ToUpper() && (x.Floor_or_ScreenId == ObjTable.Floor_or_ScreenId) && (x.FloorSide_or_RowNoID == ObjTable.FloorSide_or_RowNoID) && x.Table_or_RowID != ObjTable.Table_or_RowID);

            if (SeatExt != null)
            {
                return(Json(new { msg = "Same Seating Already Exist" }));
            }
            HG_Tables_or_Sheat TorSAlreadyObj = new HG_Tables_or_Sheat().GetOne(QrOcde: ObjTable.QrCode);

            if (ObjTable.OrgId == 0)
            {
                var ObjOrg = Request.Cookies["UserInfo"];
                ObjTable.OrgId = int.Parse(ObjOrg["OrgId"]);
            }
            if (TorSAlreadyObj != null && TorSAlreadyObj.QrCode != "0" && TorSAlreadyObj.Table_or_RowID > 0 && TorSAlreadyObj.Table_or_RowID != ObjTable.Table_or_RowID)
            {
                string QrMsg = "Qr Code Already used ";
                if (TorSAlreadyObj.OrgId != ObjTable.OrgId)
                {
                    QrMsg = "Qr Code Already used For Other Organization";
                }
                return(Json(new { msg = QrMsg }));
            }
            Int64 i = ObjTable.save();

            if (i > 0)
            {
                HG_Floor_or_ScreenMaster ObjScr     = new HG_Floor_or_ScreenMaster().GetOne(ObjTable.Floor_or_ScreenId);
                HG_FloorSide_or_RowName  ObjRowName = new HG_FloorSide_or_RowName().GetOne(ObjTable.FloorSide_or_RowNoID);
                JObject jObject = JObject.FromObject(ObjTable);
                jObject.Add("ScreenName", ObjScr.Name);
                jObject.Add("RowName", ObjRowName.FloorSide_or_RowName);
                return(Json(new { data = jObject.ToString() }, JsonRequestBehavior.AllowGet));
            }

            return(RedirectToAction("Error"));
        }
        public JsonResult Upload(int OrgID, System.Web.HttpPostedFileBase UplXl)
        {
            string msg = "Uploaded Succesfully";

            if (OrgID <= 0)
            {
                return(Json(new { msg = "Select Organization First" }));
            }
            if (UplXl == null)
            {
                return(Json(new { msg = "Upload Excel File First" }));
            }
            try
            {
                UplXl.SaveAs(System.IO.Path.Combine(Server.MapPath("~/Image/"), UplXl.FileName));
                var DT = ReadExl.ReadExcelFileDT("~/Image/" + UplXl.FileName);
                if (DT.Rows.Count > 0)
                {
                    HG_OrganizationDetails ObjOrg = new HG_OrganizationDetails().GetOne(OrgID);
                    int OrgType = int.Parse(ObjOrg.OrgTypes);
                    List <HG_Tables_or_Sheat>       ListTorS           = new HG_Tables_or_Sheat().GetAll(OrgType, OrgID);
                    List <HG_Floor_or_ScreenMaster> ListFlrScr         = new HG_Floor_or_ScreenMaster().GetAll(OrgType, OrgID);
                    List <HG_FloorSide_or_RowName>  ListFsideorRowName = new HG_FloorSide_or_RowName().GetAll(OrgType, OrgID);
                    for (int i = 1; i < DT.Rows.Count; i++)
                    {
                        string TableorSheatName = (DT.Rows[i][0] == null ? "" : DT.Rows[i][0].ToString());
                        string FlrOrScrName     = (DT.Rows[i][1] == null?"": DT.Rows[i][1].ToString());
                        string FlrSideOrRowName = (DT.Rows[i][2] == null ? "" : DT.Rows[i][2].ToString());
                        string QrCode           = (DT.Rows[i][3] == null ? "" : DT.Rows[i][3].ToString().Replace(" ", ""));
                        string QrCodeOld        = QrCode;
                        if (QrCode == "" || QrCode.Trim() == "" || QrCode == "0")
                        {
                            QrCode = "0";
                        }
                        else
                        {
                            HG_Tables_or_Sheat TorSAlreadyObj = new HG_Tables_or_Sheat().GetOne(QrOcde: QrCode);
                            if (TorSAlreadyObj != null && TorSAlreadyObj.QrCode != "0" && TorSAlreadyObj.QrCode != "" && TorSAlreadyObj.Table_or_RowID > 0)
                            {
                                QrCode = "0";
                            }
                        }

                        var ObjFlrScr        = ListFlrScr.Find(x => x.Name.ToUpper() == FlrOrScrName.ToUpper());
                        var ObjFsideOrRoName = ListFsideorRowName.Find(x => x.FloorSide_or_RowName.ToUpper() == FlrSideOrRowName.ToUpper());
                        if (ObjFlrScr == null && FlrOrScrName.Replace(" ", "") != "")
                        {
                            ObjFlrScr       = new HG_Floor_or_ScreenMaster();
                            ObjFlrScr.Name  = FlrOrScrName;
                            ObjFlrScr.Type  = ObjOrg.OrgTypes;
                            ObjFlrScr.OrgID = OrgID;
                            ObjFlrScr.save();
                            ListFlrScr.Add(ObjFlrScr);
                        }
                        if (ObjFsideOrRoName == null && FlrSideOrRowName.Replace(" ", "") != "")
                        {
                            ObjFsideOrRoName = new HG_FloorSide_or_RowName();
                            ObjFsideOrRoName.FloorSide_or_RowName = FlrSideOrRowName;
                            ObjFsideOrRoName.OrgID = OrgID;
                            ObjFsideOrRoName.Type  = ObjOrg.OrgTypes;
                            ObjFsideOrRoName.save();
                            ListFsideorRowName.Add(ObjFsideOrRoName);
                        }
                        if (ObjFsideOrRoName != null && ObjFlrScr != null)
                        {
                            var ObjTblOrShtExit = ListTorS.Find(x => x.Table_or_SheetName.ToUpper() == TableorSheatName.ToUpper() && (x.Floor_or_ScreenId == ObjFlrScr.Floor_or_ScreenID) && (x.FloorSide_or_RowNoID == ObjFsideOrRoName.ID));
                            if (ObjTblOrShtExit == null && TableorSheatName.Replace(" ", "") != "")
                            {
                                HG_Tables_or_Sheat hG_Tables_Or_Sheat = new HG_Tables_or_Sheat();
                                hG_Tables_Or_Sheat.OrgId = OrgID;
                                hG_Tables_Or_Sheat.Type  = ObjOrg.OrgTypes;
                                hG_Tables_Or_Sheat.Table_or_SheetName   = TableorSheatName;
                                hG_Tables_Or_Sheat.QrCode               = QrCode;
                                hG_Tables_Or_Sheat.Floor_or_ScreenId    = ObjFlrScr.Floor_or_ScreenID;
                                hG_Tables_Or_Sheat.FloorSide_or_RowNoID = ObjFsideOrRoName.ID;
                                hG_Tables_Or_Sheat.save();
                                ListTorS.Add(hG_Tables_Or_Sheat);
                            }
                            else if (ObjTblOrShtExit != null && (ObjTblOrShtExit.QrCode != QrCodeOld) && (QrCode != ""))
                            {
                                ObjTblOrShtExit.QrCode = QrCode;
                                ObjTblOrShtExit.save();
                            }
                        }
                        else
                        {
                            msg = "Uploaded Succesfully. With Some Data Missing";
                        }
                    }
                }
                else
                {
                    return(Json(new { msg = "No Any Row Founds" }));
                }
            }
            catch (Exception e)
            {
                return(Json(new { msg = "Error " + e.Message }));
            }
            return(Json(new { msg = msg }, JsonRequestBehavior.AllowGet));
        }