Exemple #1
0
        void populateGridview()
        {
            c   = new ConnectionDAO();
            con = c.GetConnection();
            con.Open();
            SqlDataAdapter sda = new SqlDataAdapter("select * from Login1", con);
            DataTable      dtb = new DataTable();

            sda.Fill(dtb);
            if (dtb.Rows.Count > 0)
            {
                AdminAdd.DataSource = dtb;
                AdminAdd.DataBind();
            }
            else
            {
                dtb.Rows.Add(dtb.NewRow());
                AdminAdd.DataSource = dtb;
                AdminAdd.DataBind();
                AdminAdd.Rows[0].Cells.Clear();
                AdminAdd.Rows[0].Cells.Add(new TableCell());
                AdminAdd.Rows[0].Cells[0].ColumnSpan      = dtb.Columns.Count;
                AdminAdd.Rows[0].Cells[0].Text            = "No Data Found...!";
                AdminAdd.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
            }
            con.Close();
        }
        public ApiResult AddAdmin([FromBody] AdminAdd model)
        {
            result = AccessToken.Check(model.access_token, "api/account/addadmin");
            if (result == null)
            {
                #region 参数验证
                result = ParameterCheck.CheckParameters(model);
                if (result != null)
                {
                    return(result);
                }
                #endregion

                #region 逻辑操作
                var accountModel = from T_Account in db.T_Account where (T_Account.AccountID == model.AccountID) select T_Account;
                if (accountModel.Any())
                {
                    return(Error("该账号已存在"));
                }
                else
                {
                    if (model.RoleID == "2" || model.RoleID == "3")
                    {
                        try
                        {
                            T_Account account = new T_Account();
                            account.AccountID = model.AccountID.Trim();
                            account.Name      = model.AccountName.Trim();
                            account.OrgID     = model.OrgID.Trim();
                            account.Tel       = model.Tel.Trim();
                            account.RoleID    = model.RoleID;
                            account.Password  = model.AccountID.Substring(model.AccountID.Length - 6, 6);
                            account.State     = "1";//1代表可使用

                            db.T_Account.Add(account);
                            db.SaveChanges();

                            return(Success("添加账号成功,默认密码为账号后六位"));
                        }
                        catch
                        {
                            return(Error("添加失败,请检查参数是否正确"));
                        }
                    }
                    else
                    {
                        return(Error("此接口只能设置校团委助理账号或学院账号"));
                    }
                }
                #endregion
            }
            return(result);
        }