public ActionResult EditEFProperty(EditEFPropertyModel model)
 {
     if (ModelState.IsValid)
     {
         var result = ElectricFencePropertyBLL.EditEFProperty(model, base.CurrentUserID);
         base.DoLog(OperationTypeEnum.Edit, result, "PropertyID:" + model.ID);
         return(Json(result));
     }
     else
     {
         return(PartialView("_EditElectricFenceProperty", model));
     }
 }
예제 #2
0
        public static SelectResult <EditEFPropertyModel> GetEFPropertyByID(int id)
        {
            List <SqlParameter> paras = new List <SqlParameter>()
            {
                new SqlParameter()
                {
                    ParameterName = "@ID",
                    SqlDbType     = SqlDbType.Int,
                },
            };

            paras[0].Value = id;
            string sql = @"SELECT ID,PropertyName,FenceState,ValidStartTime,ValidEndTime,AlarmType,IsSpeed,MaxSpeed,IsPeriod 
FROM dbo.ElectricFenceProperty WHERE Status<>9 AND ID=@ID";
            List <EditEFPropertyModel> list = ConvertToList <EditEFPropertyModel> .Convert(MSSQLHelper.ExecuteDataTable(CommandType.Text, sql, paras.ToArray()));

            EditEFPropertyModel data = null;
            string msg = string.Empty;

            if (list == null)
            {
                msg = PromptInformation.DBError;
            }
            else if (list.Count == 0)
            {
                msg = PromptInformation.NotExists;
            }
            else
            {
                data = list[0];
            }
            return(new SelectResult <EditEFPropertyModel>()
            {
                DataResult = data,
                Message = msg
            });
        }
예제 #3
0
        public static OperationResult EditEFProperty(EditEFPropertyModel model, int currentUserID)
        {
            int result = 0;

            #region 更新ElectricFenceProperty表
            var            updateSql   = @"UPDATE dbo.ElectricFenceProperty
                      SET PropertyName = @PropertyName ,
                      FenceState = @FenceState ,
                      ValidStartTime = @ValidStartTime ,
                      ValidEndTime = @ValidEndTime ,
                      AlarmType = @AlarmType ,
                      IsSpeed = @IsSpeed ,
                      MaxSpeed = @MaxSpeed ,
                      IsPeriod = @IsPeriod ,
                      UpdateTime = GetDate() ,
                      UpdateUser = @UpdateUser 
                     WHERE  ID = @ID ";
            SqlParameter[] updateParas = new SqlParameter[10];
            updateParas[0] = new SqlParameter()
            {
                ParameterName = "@PropertyName",
                SqlDbType     = SqlDbType.NVarChar,
                Value         = model.PropertyName.Trim()
            };
            updateParas[1] = new SqlParameter()
            {
                ParameterName = "@FenceState",
                SqlDbType     = SqlDbType.Bit,
                Value         = model.FenceState
            };
            updateParas[2] = new SqlParameter()
            {
                ParameterName = "@ValidStartTime",
                SqlDbType     = SqlDbType.DateTime,
                Value         = model.ValidStartTime
            };
            updateParas[3] = new SqlParameter()
            {
                ParameterName = "@ValidEndTime",
                SqlDbType     = SqlDbType.DateTime,
                Value         = model.ValidEndTime
            };
            if (model.AlarmType == null)
            {
                updateParas[4] = new SqlParameter()
                {
                    ParameterName = "@AlarmType",
                    SqlDbType     = SqlDbType.Bit,
                    Value         = DBNull.Value
                };
            }
            else
            {
                updateParas[4] = new SqlParameter()
                {
                    ParameterName = "@AlarmType",
                    SqlDbType     = SqlDbType.Bit,
                    Value         = model.AlarmType
                };
            }
            updateParas[5] = new SqlParameter()
            {
                ParameterName = "@IsSpeed",
                SqlDbType     = SqlDbType.Bit,
                Value         = model.IsSpeed
            };
            if (model.MaxSpeed == null)
            {
                updateParas[6] = new SqlParameter()
                {
                    ParameterName = "@MaxSpeed",
                    SqlDbType     = SqlDbType.Float,
                    Value         = DBNull.Value
                };
            }
            else
            {
                updateParas[6] = new SqlParameter()
                {
                    ParameterName = "@MaxSpeed",
                    SqlDbType     = SqlDbType.Float,
                    Value         = model.MaxSpeed
                };
            }
            updateParas[7] = new SqlParameter()
            {
                ParameterName = "@IsPeriod",
                SqlDbType     = SqlDbType.Bit,
                Value         = model.IsPeriod
            };
            updateParas[8] = new SqlParameter()
            {
                ParameterName = "@UpdateUser",
                SqlDbType     = SqlDbType.Int,
                Value         = currentUserID
            };
            updateParas[9] = new SqlParameter()
            {
                ParameterName = "@ID",
                SqlDbType     = SqlDbType.Int,
                Value         = model.ID
            };
            int updateResult = MSSQLHelper.ExecuteNonQuery(CommandType.Text, updateSql, updateParas);
            #endregion

            #region  除ElectricFencePropertyPeriod表关联数据
            int    delResult          = 0;
            string sql                = @"SELECT COUNT(0) FROM dbo.ElectricFencePropertyPeriod WHERE EFPropertyID=@EFPropertyID ";
            List <SqlParameter> paras = new List <SqlParameter>()
            {
                new SqlParameter("@EFPropertyID", SqlDbType.Int),
            };
            paras[0].Value = model.ID;
            var count = MSSQLHelper.ExecuteScalar(CommandType.Text, sql, paras.ToArray());
            if ((int)count > 0)
            {
                var            delSql   = @"DELETE FROM dbo.ElectricFencePropertyPeriod WHERE EFPropertyID=@EFPropertyID";
                SqlParameter[] delParas = new SqlParameter[1];
                delParas[0] = new SqlParameter()
                {
                    ParameterName = "@EFPropertyID",
                    SqlDbType     = SqlDbType.Int,
                    Value         = model.ID
                };
                delResult = MSSQLHelper.ExecuteNonQuery(CommandType.Text, delSql, delParas);
            }
            else
            {
                delResult = 1;
            }
            #endregion

            #region 添加ElectricFencePropertyPeriod表关联数据
            bool insertResult = false;
            //插入关联表len条记录
            int len = 0;
            if (model.IsPeriod == true)
            {
                for (int i = 0; i < model.EFPropertyPeriod.Count; i++)
                {
                    if (model.EFPropertyPeriod[i].Week != null && model.EFPropertyPeriod[i].StartTime != null && model.EFPropertyPeriod[i].EndTime != null)
                    {
                        len++;
                    }
                }
            }
            if (model.IsPeriod == false || len == 0)
            {
                insertResult = true;
            }
            else
            {
                string[]         sqls     = new string[len];
                SqlParameter[][] addParas = new SqlParameter[len][];
                int num = 0;
                if (model.IsPeriod == true)
                {
                    for (int i = 0; i < model.EFPropertyPeriod.Count; i++)
                    {
                        if (model.EFPropertyPeriod[i].Week != null && model.EFPropertyPeriod[i].StartTime != null && model.EFPropertyPeriod[i].EndTime != null)
                        {
                            string tempSql = string.Empty;
                            tempSql          = @"INSERT  INTO dbo.ElectricFencePropertyPeriod
                                    ( EFPropertyID
                                    ,[Week]
                                  ,[StartTime]
                                  ,[EndTime]
                                    )
                            VALUES  ( @PropertyID,
                                         @Week , 
                                        @StartTime, 
                                        @EndTime
                                    );";
                            sqls[num]        = tempSql;
                            addParas[num]    = new SqlParameter[4];
                            addParas[num][0] = new SqlParameter
                            {
                                ParameterName = "@PropertyID",
                                SqlDbType     = SqlDbType.Int,
                                Value         = model.ID
                            };
                            addParas[num][1] = new SqlParameter()
                            {
                                ParameterName = "@Week",
                                SqlDbType     = SqlDbType.Int,
                                Value         = model.EFPropertyPeriod[i].Week
                            };
                            addParas[num][2] = new SqlParameter()
                            {
                                ParameterName = "@StartTime",
                                SqlDbType     = SqlDbType.DateTime,
                                Value         = model.EFPropertyPeriod[i].StartTime
                            };
                            addParas[num][3] = new SqlParameter()
                            {
                                ParameterName = "@EndTime",
                                SqlDbType     = SqlDbType.DateTime,
                                Value         = model.EFPropertyPeriod[i].EndTime
                            };
                            num++;
                        }
                    }
                }
                insertResult = MSSQLHelper.ExecuteTransaction(CommandType.Text, sqls, addParas);
            }
            #endregion

            if (updateResult > 0 && delResult != 0 && insertResult == true)
            {
                result = 1;
            }

            string msg = string.Empty;
            switch (result)
            {
            case 1:
                msg = PromptInformation.OperationSuccess;
                break;

            case 0:
                msg = PromptInformation.NotExists;
                break;

            case -1:
                msg = PromptInformation.DBError;
                break;
            }
            return(new OperationResult()
            {
                Success = result > 0,
                Message = msg
            });
        }