Ejemplo n.º 1
0
        public int updateModel(BookTicketInfoModel model)
        {
            string sql = @"UPDATE dbo.BookTicketInfo
                            SET TrainNumber = @TrainNumber
                                ,StartStation = @StartStation
                                ,EndStation = @EndStation
                                ,BookDate = @BookDate
                                ,Phone = @Phone
                                ,Remark = @Remark
                            WHERE Id = @Id";

            SqlParameter[] pars = new SqlParameter[] {
                new SqlParameter("@TrainNumber", SqlDbType.VarChar),
                new SqlParameter("@StartStation", SqlDbType.NVarChar),
                new SqlParameter("@EndStation", SqlDbType.NVarChar),
                new SqlParameter("@BookDate", SqlDbType.DateTime),
                new SqlParameter("@Phone", SqlDbType.NVarChar),
                new SqlParameter("@Remark", SqlDbType.NVarChar),
                new SqlParameter("@Id", SqlDbType.Int)
            };
            pars[0].Value = model.TrainNumber;
            pars[1].Value = model.StartStation;
            pars[2].Value = model.EndStation;
            pars[3].Value = model.BookDate;
            pars[4].Value = model.Phone;
            pars[5].Value = model.Remark;
            pars[6].Value = model.Id;
            // continuing
            int result = MSSQL.noQuery(sql, pars);

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids">1,2,4,6</param>
        /// <returns></returns>
        public int batchDel(string ids)
        {
            // where in 参数化
            // 参考 https://www.cnblogs.com/lymi/p/4279978.html
            string sql = "update Student set IsStop = 1 where Id in ";

            string[]       idArr = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            SqlParameter[] pars  = new SqlParameter[idArr.Length];
            StringBuilder  sb    = new StringBuilder("(");

            for (int i = 0; i < idArr.Length; i++)
            {
                // (@id1,@id2,@id3,
                sb.Append("@id" + (i + 1) + ",");
                // 勿忘new 每个参数对象,不能为par直接赋值,因为他们还为 null
                // 这也是对象的区别,也可以直接将一个SqlParameter赋值过去, eg. pars[i] = parObj;
                // 但直接为对象的属性赋值并不会创建对象
                pars[i] = new SqlParameter();
                pars[i].ParameterName = "@id" + (i + 1);
                pars[i].Value         = idArr[i];
            }
            // (@id1,@id2,@id3
            sb.Remove(sb.Length - 1, 1);
            // (@id1,@id2,@id3)
            sb.Append(")");
            sql += sb.ToString();
            return(MSSQL.noQuery(sql, pars));
        }
Ejemplo n.º 3
0
        public int insert(StudentModel model)
        {
            // ??问题记录:
            string sql = "insert into Student(StudentNumber, StudentName, Password, Gender, Identification, Telephone, ClassName, RoleId, IsStop) values(@StudentNumber, @StudentName, @Password, @Gender, @Identification, @Telephone, @ClassName, @RoleId, 0)";

            SqlParameter[] pars = new SqlParameter[]
            {
                new SqlParameter("@StudentNumber", SqlDbType.NVarChar),
                new SqlParameter("@StudentName", SqlDbType.NVarChar),
                new SqlParameter("@Password", SqlDbType.NVarChar),
                new SqlParameter("@Gender", SqlDbType.Bit),
                new SqlParameter("@Identification", SqlDbType.NVarChar),
                new SqlParameter("@Telephone", SqlDbType.NVarChar),
                new SqlParameter("@ClassName", SqlDbType.NVarChar),
                new SqlParameter("@RoleId", SqlDbType.Int)
            };
            pars[0].Value = model.StudentNumber;
            pars[1].Value = model.StudentName;
            pars[2].Value = model.Password;
            pars[3].Value = model.Gender;
            pars[4].Value = model.Identification;
            pars[5].Value = model.Telephone;
            pars[6].Value = model.ClassName;
            pars[7].Value = model.RoleId;
            return(MSSQL.noQuery(sql, pars));
        }
Ejemplo n.º 4
0
        public int disableTicket(int bookTicketInfoId)
        {
            string       sql = "update BookTicketState set TicketSate = 0 where BookTicketInfoId = @BookTicketInfoId";
            SqlParameter par = new SqlParameter("@BookTicketInfoId", System.Data.SqlDbType.Int);

            par.Value = bookTicketInfoId;
            return(MSSQL.noQuery(sql, par));
        }
Ejemplo n.º 5
0
        public int update(StudentModel model)
        {
            string sql = @"UPDATE dbo.Student
                            SET StudentNumber = @StudentNumber
                                ,StudentName = @StudentName
                                ,Gender = @Gender
                                ,Identification = @Identification
                                ,Telephone = @Telephone
                                ,ClassName = @ClassName
                                ,Password = @Password
                                ,RoleId = @RoleId
                            WHERE Id=@Id";

            SqlParameter[] pars = new SqlParameter[]
            {
                new SqlParameter("@StudentNumber", SqlDbType.NVarChar),
                new SqlParameter("@StudentName", SqlDbType.NVarChar),
                new SqlParameter("@Gender", SqlDbType.Bit),
                new SqlParameter("@Identification", SqlDbType.NVarChar),
                new SqlParameter("@Telephone", SqlDbType.NVarChar),
                new SqlParameter("@ClassName", SqlDbType.NVarChar),
                new SqlParameter("@Password", SqlDbType.NVarChar),
                new SqlParameter("@RoleId", SqlDbType.Int),
                new SqlParameter("@Id", SqlDbType.Int),
            };
            pars[0].Value = model.StudentNumber;
            pars[1].Value = model.StudentName;
            pars[2].Value = model.Gender;
            pars[3].Value = model.Identification;
            pars[4].Value = model.Telephone;
            pars[5].Value = model.ClassName;
            pars[6].Value = model.Password;
            pars[7].Value = model.RoleId;
            pars[8].Value = model.Id;
            return(MSSQL.noQuery(sql, pars));
        }