public ActionResult AddEFProperty()
        {
            AddEFPropertyModel model = new AddEFPropertyModel();

            model.ValidStartTime = DateTime.Now.ToString("yyyy-MM-dd 00:00:00");
            model.ValidEndTime   = DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd 23:59:59");
            model.FenceState     = true;
            return(PartialView("_AddElectricFenceProperty", model));
        }
 public ActionResult AddEFProperty(AddEFPropertyModel model)
 {
     if (ModelState.IsValid)
     {
         var result = ElectricFencePropertyBLL.AddEFProperty(model, base.CurrentUserID);
         base.DoLog(OperationTypeEnum.Add, result, "PropertyName:" + model.PropertyName);
         return(Json(result));
     }
     else
     {
         return(PartialView("_AddElectricFenceProperty", model));
     }
 }
示例#3
0
        public static OperationResult AddEFProperty(AddEFPropertyModel model, int currentUserID)
        {
            int len = 0;

            for (int i = 0; i < model.EFPropertyPeriod.Count; i++)
            {
                if (model.EFPropertyPeriod[i].Week != null)
                {
                    len++;
                }
            }
            //插入主表1条记录+插入关联表len条记录
            len = len + 1;
            string[]         sqls  = new string[len];
            SqlParameter[][] paras = new SqlParameter[len][];
            int num = 1;

            #region 添加ElectricFenceProperty表
            sqls[0] = @" INSERT  INTO dbo.ElectricFenceProperty
                ( [PropertyName]
                  ,[FenceState]
                  ,[ValidStartTime]
                  ,[ValidEndTime]
                  ,[AlarmType]
                  ,[IsSpeed]
                  ,[MaxSpeed]
                  ,[IsPeriod]
                  ,[Status]
                  ,[CreateUser]
                  ,[CreateTime]
                )
        VALUES  ( @PropertyName , 
                    @FenceState, 
                    @ValidStartTime,
                    @ValidEndTime , 
                    @AlarmType, 
                    @IsSpeed , 
                    @MaxSpeed, 
                    @IsPeriod , 
                    @Status , 
                    @CreateUser, 
                    @CreateTime 
                );SELECT  SCOPE_IDENTITY();";

            paras[0]    = new SqlParameter[11];
            paras[0][0] = new SqlParameter()
            {
                ParameterName = "@PropertyName",
                SqlDbType     = SqlDbType.NVarChar,
                Value         = model.PropertyName.Trim()
            };
            paras[0][1] = new SqlParameter()
            {
                ParameterName = "@FenceState",
                SqlDbType     = SqlDbType.Bit,
                Value         = model.FenceState
            };
            paras[0][2] = new SqlParameter()
            {
                ParameterName = "@ValidStartTime",
                SqlDbType     = SqlDbType.DateTime,
                Value         = model.ValidStartTime
            };
            paras[0][3] = new SqlParameter()
            {
                ParameterName = "@ValidEndTime",
                SqlDbType     = SqlDbType.DateTime,
                Value         = model.ValidEndTime
            };
            if (model.AlarmType == null)
            {
                paras[0][4] = new SqlParameter()
                {
                    ParameterName = "@AlarmType",
                    SqlDbType     = SqlDbType.Bit,
                    Value         = DBNull.Value
                };
            }
            else
            {
                paras[0][4] = new SqlParameter()
                {
                    ParameterName = "@AlarmType",
                    SqlDbType     = SqlDbType.Bit,
                    Value         = model.AlarmType
                };
            }
            paras[0][5] = new SqlParameter()
            {
                ParameterName = "@IsSpeed",
                SqlDbType     = SqlDbType.Bit,
                Value         = model.IsSpeed
            };
            if (model.MaxSpeed == null)
            {
                paras[0][6] = new SqlParameter()
                {
                    ParameterName = "@MaxSpeed",
                    SqlDbType     = SqlDbType.Float,
                    Value         = DBNull.Value
                };
            }
            else
            {
                paras[0][6] = new SqlParameter()
                {
                    ParameterName = "@MaxSpeed",
                    SqlDbType     = SqlDbType.Float,
                    Value         = model.MaxSpeed
                };
            }
            paras[0][7] = new SqlParameter()
            {
                ParameterName = "@IsPeriod",
                SqlDbType     = SqlDbType.Bit,
                Value         = model.IsPeriod
            };
            paras[0][8] = new SqlParameter()
            {
                ParameterName = "@Status",
                SqlDbType     = SqlDbType.Int,
                Value         = 0
            };
            paras[0][9] = new SqlParameter()
            {
                ParameterName = "@CreateUser",
                SqlDbType     = SqlDbType.Int,
                Value         = currentUserID
            };
            paras[0][10] = new SqlParameter()
            {
                ParameterName = "@CreateTime",
                SqlDbType     = SqlDbType.DateTime,
                Value         = DateTime.Now
            };
            #endregion

            #region 添加ElectricFencePropertyPeriod表
            if (model.IsPeriod == true)
            {
                for (int i = 0; i < model.EFPropertyPeriod.Count; i++)
                {
                    if (model.EFPropertyPeriod[i].Week != null)
                    {
                        string tempSql = string.Empty;
                        tempSql       = @"INSERT  INTO dbo.ElectricFencePropertyPeriod
                ( EFPropertyID
                ,[Week]
              ,[StartTime]
              ,[EndTime]
                )
        VALUES  ( @EFPropertyID,
                     @Week , 
                    @StartTime, 
                    @EndTime
                );";
                        sqls[num]     = tempSql;
                        paras[num]    = new SqlParameter[4];
                        paras[num][0] = new SqlParameter {
                            ParameterName = "@EFPropertyID", SqlDbType = SqlDbType.Int
                        };
                        paras[num][1] = new SqlParameter()
                        {
                            ParameterName = "@Week",
                            SqlDbType     = SqlDbType.Int,
                            Value         = model.EFPropertyPeriod[i].Week
                        };
                        paras[num][2] = new SqlParameter()
                        {
                            ParameterName = "@StartTime",
                            SqlDbType     = SqlDbType.DateTime,
                            Value         = model.EFPropertyPeriod[i].StartTime
                        };
                        paras[num][3] = new SqlParameter()
                        {
                            ParameterName = "@EndTime",
                            SqlDbType     = SqlDbType.DateTime,
                            Value         = model.EFPropertyPeriod[i].EndTime
                        };
                        num++;
                    }
                }
            }

            #endregion

            bool result = MSSQLHelper.ExecuteIdentityIncludeTransaction(CommandType.Text, sqls, paras) != 0;

            return(new OperationResult()
            {
                Success = result,
                Message = result ? PromptInformation.OperationSuccess : PromptInformation.DBError
            });
        }