コード例 #1
0
        public JsonResult Upload(int OrgID, System.Web.HttpPostedFileBase UplXl)
        {
            string Msg = "Uploaded Successfully";

            if (OrgID <= 0)
            {
                return(Json(new { msg = "Select Organization First" }));
            }
            if (UplXl == null)
            {
                return(Json(new { msg = "Upload Excel File First" }));
            }
            try
            {
                var userInfo = Request.Cookies["UserInfo"];
                var EntryBy  = int.Parse(userInfo["UserCode"]);
                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);
                    List <HG_Category>     ListCategory = new HG_Category().GetAll(ObjOrg.OrgID);
                    List <HG_Items>        ListItem     = new HG_Items().GetAll(ObjOrg.OrgID);
                    for (int i = 1; i < DT.Rows.Count; i++)
                    {
                        string CategoryName = (DT.Rows[i][0] == null ? "" : DT.Rows[i][0].ToString());
                        string ItmName      = (DT.Rows[i][1] == null ? "" : DT.Rows[i][1].ToString().Trim());
                        string ItmMode      = (DT.Rows[i][2] == null ? "1" : DT.Rows[i][2].ToString().Replace(" ", ""));
                        string Discriptn    = (DT.Rows[i][3] == null ? "" : DT.Rows[i][3].ToString());
                        string CostPriceStr = (DT.Rows[i][4] == null ? "0.0" : DT.Rows[i][4].ToString().Replace(" ", ""));
                        string Taxstr       = (DT.Rows[i][5] == null ? "0.0" : DT.Rows[i][5].ToString().Replace(" ", ""));
                        double CostPrice    = double.Parse(CostPriceStr);
                        double Tax          = double.Parse(Taxstr);
                        double TaxAmt       = (CostPrice * Tax) / 100;
                        double price        = CostPrice + TaxAmt;
                        if (ItmMode.ToUpper() == "VEG")
                        {
                            ItmMode = "1";
                        }
                        else if (ItmMode.ToUpper() == "NON-VEG")
                        {
                            ItmMode = "2";
                        }
                        HG_Category ObjCategory = ListCategory.Find(x => x.Category.ToUpper() == CategoryName.ToUpper());
                        if (ObjCategory == null && CategoryName.Replace(" ", "") != "")
                        {
                            ObjCategory = new HG_Category()
                            {
                                Category = CategoryName, OrgID = ObjOrg.OrgID, CategoryID = 0, CategoryType = 1, EntryBy = EntryBy
                            };
                            ObjCategory.Save();
                            ListCategory.Add(ObjCategory);
                        }
                        HG_Items ObjItem = ListItem.Find(x => x.Items.ToUpper() == ItmName.ToUpper());
                        if (ObjItem == null && ItmName.Replace(" ", "") != "" && ObjCategory != null)
                        {
                            ObjItem = new HG_Items()
                            {
                                ItemID    = 0, CategoryID = ObjCategory.CategoryID, Items = ItmName, ItemMode = ItmMode, ItemDiscription = Discriptn, CostPrice = CostPrice, Tax = Tax, Price = price, ApplyAddOn = 1, Image = ""
                                , EntryBy = EntryBy, OrgID = OrgID, Qty = "", Type = 1, Status = true
                            };
                            ObjItem.Save();
                            ListItem.Add(ObjItem);
                        }
                        else if (ObjItem != null && ItmName.Replace(" ", "") != "" && ObjCategory != null)
                        {
                            ObjItem.Items    = ItmName;
                            ObjItem.ItemMode = ItmMode;
                            if ((ObjItem.CostPrice != CostPrice) || (ObjItem.Tax != Tax))
                            {
                                ObjItem.CostPrice = CostPrice;
                                ObjItem.Tax       = Tax;
                                ObjItem.Price     = price;
                            }
                            ObjItem.ItemDiscription = Discriptn;
                            ObjItem.Save();
                            ListItem.Add(ObjItem);
                        }
                        else if (ItmName.Replace(" ", "") == "" || ObjCategory == null)
                        {
                            Msg = "Uploaded Successfully 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));
        }
コード例 #2
0
        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));
        }