Exemple #1
0
        public frmApiEdit(int id = 0)
        {
            InitializeComponent();
            _lit = new xl_rp.Sqlite();
            listDb.DisplayMember    = "name";
            listUser.DisplayMember  = "name";
            listRight.DisplayMember = "name";

            dgParam.ColumnCount                 = 4;
            dgParam.ColumnHeadersVisible        = true;
            dgParam.Columns[0].DataPropertyName = "name";
            dgParam.Columns[0].HeaderText       = "名称";
            dgParam.Columns[1].DataPropertyName = "key";
            dgParam.Columns[1].HeaderText       = "sql标记";
            dgParam.Columns[2].DataPropertyName = "defValue";
            dgParam.Columns[2].HeaderText       = "默认值";
            dgParam.Columns[3].DataPropertyName = "note";
            dgParam.Columns[3].HeaderText       = "备注";

            if (id == 0)
            {
                _apiObj   = new Entity.ApiObj();
                this.Text = "新增";
            }
            else
            {
                _apiObj   = ApiObj.Load(_lit, id);
                this.Text = _apiObj.name;
            }
            txtName.DataBindings.Add("Text", _apiObj, "name");
            txtNumber.DataBindings.Add("Text", _apiObj, "number");
            txtNote.DataBindings.Add("Text", _apiObj, "note");

            dgParam.DataSource   = _apiObj.param;
            listRight.DataSource = _apiObj.right;
            listDb.DataSource    = Db.Load(_lit);
            List <User> users = User.Load(_lit);

            for (int i = users.Count - 1; i >= 0; --i)
            {
                for (int j = 0; j < _apiObj.right.Count; j++)
                {
                    if (_apiObj.right[j].id == users[i].id)
                    {
                        users.RemoveAt(i);
                    }
                }
            }
            listUser.DataSource = users;
        }
Exemple #2
0
        private void Srv_requestHandler(HttpListenerContext ctx)
        {
            try
            {
                List <string> sl = new List <string>();
                if (txtInfo.Text != "")
                {
                    sl = new List <string>(txtInfo.Lines);
                }
                string info = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "  " + ctx.Request.Url.OriginalString;
                if (sl.Count >= 1000)
                {
                    sl.RemoveAt(sl.Count - 1);
                }
                sl.Insert(0, info);
                txtInfo.Lines = sl.ToArray();

                string route = ctx.Request.RawUrl.Split('?')[0];
                ApiObj ao    = ApiObj.Load(new xl_rp.Sqlite(), route);
                if (ao == null)
                {
                    ctx.Response.StatusCode        = 404;
                    ctx.Response.StatusDescription = "Url Not Found";
                    ctx.Response.Close();
                    return;
                }

                ctx.Response.StatusCode = 200;
                //接收Get参数
                string type     = ctx.Request.QueryString["type"];
                string userId   = ctx.Request.QueryString["userId"];
                string password = ctx.Request.QueryString["password"];
                string filename = Path.GetFileName(ctx.Request.RawUrl);
                string userName = "******";//HttpUtility.ParseQueryString(filename).Get("userName");//避免中文乱码
                Dictionary <string, string> param = new Dictionary <string, string>();
                foreach (string k in ctx.Request.QueryString.AllKeys)
                {
                    param.Add(k, ctx.Request.QueryString[k]);
                }
                //进行处理
                //Console.WriteLine("收到数据:" + userName);

                //接收POST参数
                Stream stream = ctx.Request.InputStream;
                System.IO.StreamReader reader = new System.IO.StreamReader(stream, Encoding.UTF8);
                String body = reader.ReadToEnd();
                //Console.WriteLine("收到POST数据:" + HttpUtility.UrlDecode(body));
                //Console.WriteLine("解析:" + HttpUtility.ParseQueryString(body).Get("userName"));

                //使用Writer输出http响应代码,UTF8格式
                using (StreamWriter writer = new StreamWriter(ctx.Response.OutputStream, Encoding.UTF8))
                {
                    string rst = Newtonsoft.Json.JsonConvert.SerializeObject(ao.Exec(param));
                    writer.Write(rst);
                    writer.Close();
                    ctx.Response.Close();
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }