Beispiel #1
0
        public IDictionary<string, string> Inject(Dictionary<string, object> param)
        {
            var prjService = new ProjectService();
            var codes = new Dictionary<string, string>();
            var jsonParam = new object[] { param }.ToJson();
            string r = prjService.CommonQuery("CodeBS", "findCode", jsonParam);

            if (r.Length > 4) {
                var jsonText = r.Substring(1, r.Length - 2);
                var jsonResult = JsonConvert.DeserializeObject<dynamic>(jsonText);
                foreach (JProperty item in jsonResult.options) {
                    codes.Add(item.Name, item.Value.GetJsonValue());
                }
            }

            return codes;
        }
Beispiel #2
0
        private void btnSyncData_Click(object sender, EventArgs e)
        {
            try {
                var table = (string)cboSyncType.SelectedValue;
                var setting = sds.FirstOrDefault(c=> c.Name == table);

                var projectService = new ProjectService();
                var findMethod = typeof(ProjectService).GetMethod("Find" + table);

                if (string.IsNullOrWhiteSpace(txtID.Text)) {
                    MessageBox.Show("请输入查询值!");
                    return;
                }

                dynamic jsonResult = findMethod.Invoke(projectService, new object[] { txtID.Text.Trim() });

                //获取主键
                var pks = setting.PKey.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                //根据主键拼装查询条件
                var whereStatement = string.Join(" And ", pks
                                                     .Select(c => string.Format("{0} = @{0}", c))
                                                     .ToArray());

                var checkedRecordSql = string.Format("select top 1 1 from {0} where {1}", setting.TableName, whereStatement);

                if (setting.DataType == DataType.Item) {
                    //主键值作为参数
                    SaveRecord(setting, pks, jsonResult, checkedRecordSql);
                }
                else if (setting.DataType == DataType.List) {
                    foreach (var item in jsonResult.data) {
                        SaveRecord(setting, pks, item, checkedRecordSql);
                    }
                }
                MessageBox.Show("同步成功!");
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message + " " + ex.StackTrace);
            }
        }