コード例 #1
0
        public int AddFlats(int TotalFloor, int FlatOrder, List <int> FlatNo, List <bool> PreIncrement, List <PLCModel> pmodel, string username, int towerID, string FltType, string FltTSize)
        {
            PLCService pservice = new PLCService();
            int        plcCount = pservice.GetPLCCount();

            using (REMSDBEntities context = new REMSDBEntities())
            {
                try
                {
                    for (int i = 1; i <= TotalFloor; i++)
                    {
                        int   kk  = 0;
                        Floor flo = new Floor();
                        flo.CrBy      = username; flo.CrDate = DateTime.Now;
                        flo.TowerID   = towerID;
                        flo.FloorName = i.ToString();
                        flo.FloorNo   = i;
                        context.Floors.Add(flo);
                        context.SaveChanges();
                        int jj = 0;
                        foreach (int flat in FlatNo)
                        {
                            int  fno = GenFlatNo(i, flat, PreIncrement[jj]);
                            Flat fl  = new Flat();
                            fl.FlatOrder    = FlatOrder;
                            fl.FlatNo       = fno.ToString();
                            fl.FlatName     = fno.ToString();
                            fl.FloorID      = flo.FloorID;
                            fl.FlatType     = FltType;
                            fl.FlatSizeUnit = "SqFt";
                            fl.FlatSize     = Convert.ToDecimal(FltTSize);
                            fl.Status       = "Available";
                            context.Flats.Add(fl);
                            context.SaveChanges();

                            for (int k = 0; k <= plcCount - 1; k++)
                            {
                                var pl = pmodel[kk];
                                if (pl.PLCID != 0)
                                {
                                    FlatPLC fpcl = new FlatPLC();
                                    fpcl.CrDate = DateTime.Now;
                                    fpcl.FlatID = fl.FlatID;
                                    fpcl.PLCID  = pl.PLCID;
                                    context.FlatPLCs.Add(fpcl);
                                    context.SaveChanges();
                                }
                                kk++;
                            }
                            jj++;
                        }
                    }
                    return(1);
                }
                catch (Exception ex)
                {
                    return(0);
                }
            }
        }
コード例 #2
0
        public string UpdateFlat(FlatModel flat)
        {
            Mapper.CreateMap <FlatModel, Flat>().ForMember(dest => dest.FlatPLCs, sec => sec.Ignore());
            Flat           fl        = Mapper.Map <FlatModel, Flat>(flat);
            int            i         = fservice.EditFlat(fl);
            FlatPLCService fpservice = new FlatPLCService();
            var            model     = fpservice.GetFlatPLCListByFlatID(fl.FlatID);

            foreach (var ft in model)
            {
                FlatPLC md = new FlatPLC();
                md.FlatPLCID = ft.FlatPLCID;
                int ii = fpservice.DeleteFlatPLC(md);
            }
            foreach (string st in flat.FlatPLCs)
            {
                if (st != "0")
                {
                    FlatPLC fpm = new FlatPLC();
                    fpm.FlatID = fl.FlatID;
                    fpm.PLCID  = Convert.ToInt32(st);
                    int ii = fpservice.AddFlatPLC(fpm);
                }
            }
            return(i.ToString());
        }
コード例 #3
0
 public int AddFlatPLC(FlatPLC model)
 {
     using (REMSDBEntities context = new REMSDBEntities())
     {
         try
         {
             context.FlatPLCs.Add(model);
             int i = context.SaveChanges();
             return(i);
         }
         catch (Exception ex)
         {
             Helper hp = new Helper();
             hp.LogException(ex);
             return(0);
         }
     }
 }
コード例 #4
0
 public int EditFlatPLC(FlatPLC model)
 {
     using (REMSDBEntities context = new REMSDBEntities())
     {
         try
         {
             context.FlatPLCs.Add(model);
             context.Entry(model).State = EntityState.Modified;
             int i = context.SaveChanges();
             return(i);
         }
         catch (Exception ex)
         {
             Helper hp = new Helper();
             hp.LogException(ex);
             return(0);
         }
     }
 }
コード例 #5
0
 public int DeleteFlat(int flatid)
 {
     using (REMSDBEntities context = new REMSDBEntities())
     {
         try
         {
             FlatPLCService    fpservice = new FlatPLCService();
             FlatChargeService fcservice = new FlatChargeService();
             var model = fpservice.GetFlatPLCListByFlatID(flatid);
             foreach (var md in model)
             {
                 FlatPLC plc = new FlatPLC();
                 plc.FlatPLCID = md.FlatPLCID;
                 context.FlatPLCs.Add(plc);
                 context.Entry(plc).State = EntityState.Deleted;
                 context.SaveChanges();
             }
             var fmodel = fcservice.GetFlatChargeListByFlatID(flatid);
             foreach (var md in fmodel)
             {
                 FlatCharge plc = new FlatCharge();
                 plc.FlatChargeID = md.FlatChargeID;
                 context.FlatCharges.Add(plc);
                 context.Entry(plc).State = EntityState.Deleted;
                 context.SaveChanges();
             }
             Flat ft = new Flat();
             ft.FlatID = flatid;
             context.Flats.Add(ft);
             context.Entry(ft).State = EntityState.Deleted;
             int i = context.SaveChanges();
             return(i);
         }
         catch (Exception ex)
         {
             Helper hp = new Helper();
             hp.LogException(ex);
             return(0);
         }
     }
 }
コード例 #6
0
        public string SaveFat(FlatModel flat)
        {
            Mapper.CreateMap <FlatModel, Flat>().ForMember(dsd => dsd.FlatPLCs, df => df.Ignore());
            Flat fl = Mapper.Map <FlatModel, Flat>(flat);

            fl.CrBy   = User.Identity.Name;
            fl.CrDate = DateTime.Now;
            int            i         = fservice.AddNewFlat(fl);
            FlatPLCService fpservice = new FlatPLCService();

            foreach (string st in flat.FlatPLCs)
            {
                if (st != "0")
                {
                    FlatPLC fpm = new FlatPLC();
                    fpm.FlatID = fl.FlatID;
                    fpm.PLCID  = Convert.ToInt32(st);
                    int ii = fpservice.AddFlatPLC(fpm);
                }
            }
            return(i.ToString());
        }
コード例 #7
0
 public bool IsPLCinFlat(int plcid, int flatid)
 {
     using (REMSDBEntities context = new REMSDBEntities())
     {
         try
         {
             FlatPLC model = context.FlatPLCs.Where(pl => pl.PLCID == plcid && pl.FlatID == flatid).FirstOrDefault();
             if (model.FlatID == null)
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
         catch (Exception ex)
         {
             Helper hp = new Helper();
             hp.LogException(ex);
             return(false);
         }
     }
 }