Пример #1
0
 public static int Add(CMSControl cmsControl)
 {
     return CMSControlDataMapper.Add(cmsControl);
 }
Пример #2
0
 public static void Update(CMSControl cmsControl)
 {
     CMSControlDataMapper.Update(cmsControl);
 }
Пример #3
0
        internal static int Add(CMSControl cmsControlEntity)
        {
            using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString))
            {
                SqlCommand sqlCommand = new SqlCommand(SN_CMSCONTROL_ADD, sqlConnection);
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;

                SqlParameter sqlParameter = null;

                double days = 0;
                double seconds = 0;
                CMSCoreHelper.GetDaySecondsNumber(cmsControlEntity.CreationDate, out days, out seconds);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_CREATION_DAY, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = (int)days;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_CREATION_SEC, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = (int)seconds;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_DESCRIPTION, System.Data.SqlDbType.NVarChar);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = cmsControlEntity.Description;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_USER_CONTROL_PATH, System.Data.SqlDbType.NVarChar);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = cmsControlEntity.UserControlPath;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_ID, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Output;
                sqlParameter.Value = 0;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_IS_DELETED, System.Data.SqlDbType.Bit);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = cmsControlEntity.IsDeleted;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_NAME, System.Data.SqlDbType.NVarChar);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = cmsControlEntity.Name;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_MODULE_ID, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = cmsControlEntity.ModuleID;
                sqlCommand.Parameters.Add(sqlParameter);

                sqlParameter = new SqlParameter(PN_CMSCONTROL_CREATED_BY, System.Data.SqlDbType.Int);
                sqlParameter.Direction = System.Data.ParameterDirection.Input;
                sqlParameter.Value = cmsControlEntity.CreatedBy;
                sqlCommand.Parameters.Add(sqlParameter);

                try
                {
                    sqlCommand.Connection.Open();
                    sqlCommand.ExecuteNonQuery();
                    sqlCommand.Connection.Close();

                    cmsControlEntity.ID = Convert.ToInt32(sqlCommand.Parameters[PN_CMSCONTROL_ID].Value);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return cmsControlEntity.ID;
        }
Пример #4
0
        internal static void FillFromReader(CMSControl cmsControl, SqlDataReader reader)
        {
            int colIndex = 0;

            int days = 0, seconds = 0;
            colIndex = reader.GetOrdinal(CN_CMSCONTROL_CREATION_DAY);
            if (!reader.IsDBNull(colIndex))
                days = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_CREATION_SEC);
            if (!reader.IsDBNull(colIndex))
                seconds = reader.GetInt32(colIndex);

            cmsControl.CreationDate = CMSCoreHelper.GetDateTime(days, seconds);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_DESCRIPTION);
            if (!reader.IsDBNull(colIndex))
                cmsControl.Description = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_USER_CONTROL_PATH);
            if (!reader.IsDBNull(colIndex))
                cmsControl.UserControlPath = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_ID);
            if (!reader.IsDBNull(colIndex))
                cmsControl.ID = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_IS_DELETED);
            if (!reader.IsDBNull(colIndex))
                cmsControl.IsDeleted = reader.GetBoolean(colIndex);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_NAME);
            if (!reader.IsDBNull(colIndex))
                cmsControl.Name = reader.GetString(colIndex);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_MODULE_ID);
            if (!reader.IsDBNull(colIndex))
                cmsControl.ModuleID = reader.GetInt32(colIndex);

            colIndex = reader.GetOrdinal(CN_CMSCONTROL_CREATED_BY);
            if (!reader.IsDBNull(colIndex))
                cmsControl.CreatedBy = reader.GetInt32(colIndex);
        }
Пример #5
0
        internal static CMSControl GetCMSControl(List<CMSControl> cmsControls, SqlDataReader reader)
        {
            int colIndex = 0;
            colIndex = reader.GetOrdinal(CN_CMSCONTROL_ID);
            int value = reader.GetInt32(colIndex);

            CMSControl cmsControl = cmsControls.Where(c => c.ID == value).FirstOrDefault();
            if (cmsControl == null)
            {
                cmsControl = new CMSControl();
                cmsControls.Add(cmsControl);
            }
            return cmsControl;
        }
Пример #6
0
        internal static CMSControl GetCMSControlById(int CMSControlID)
        {
            CMSControl cmsControl = null;

            using (SqlConnection sqlConnection = new SqlConnection(CMSCoreBase.CMSCoreConnectionString))
            {
                SqlCommand sqlCommand = new SqlCommand(SN_CMSCONTROL_GET_BY_ID, sqlConnection);
                sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;

                SqlParameter parameter = new SqlParameter(PN_CMSCONTROL_ID, System.Data.SqlDbType.Int);
                parameter.Direction = System.Data.ParameterDirection.Input;
                parameter.Value = CMSControlID;
                sqlCommand.Parameters.Add(parameter);

                sqlCommand.Connection.Open();
                using (SqlDataReader reader = sqlCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection))
                {
                    while (reader.Read())
                    {
                        if (cmsControl == null)
                            cmsControl = new CMSControl();
                        FillFromReader(cmsControl, reader);
                    }
                    reader.Close();
                    sqlCommand.Connection.Close();
                }
            }
            return cmsControl;
        }