private void Form1_Load(object sender, EventArgs e) { textBox_host.Text = OkayApiClient.instance().host; textBox_app_key.Text = OkayApiClient.instance().app_key; textBox_app_secrect.Text = OkayApiClient.instance().app_secrect; /** * // 读取配置 * IniFileHelper iniFileHelper = new IniFileHelper(); * StringBuilder sb = new StringBuilder(200); * iniFileHelper.GetIniString("Product", "host", "", sb, sb.Capacity); * host = sb.ToString(); * if (host.Length == 0) * { * host = "http://api.okayapi.com/"; * } * textBox_host.Text = host; * * iniFileHelper.GetIniString("Product", "app_key", "", sb, sb.Capacity); * app_key = sb.ToString(); * textBox_app_key.Text = app_key; * * iniFileHelper.GetIniString("Product", "app_secrect", "", sb, sb.Capacity); * app_secrect = sb.ToString(); * textBox_app_secrect.Text = app_secrect; */ }
public static OkayApiClient instance() { if (OkayApiClient.client == null) { OkayApiClient.client = new OkayApiClient(); } return(OkayApiClient.client); }
private void btn_save_cfg_Click(object sender, EventArgs e) { String host = textBox_host.Text.ToString(); String appKey = textBox_app_key.Text.ToString(); String appSecrect = textBox_app_secrect.Text.ToString(); if (host.Length == 0 || appKey.Length == 0 || appSecrect.Length == 0) { MessageBox.Show("配置不能为空,请补全", "提示", MessageBoxButtons.OK); return; } Dictionary <String, String> paramsDict = new Dictionary <String, String>(); paramsDict.Add("name", "dogstar"); PhalApiClientResponse response = OkayApiClient.instance().go("Hello.World", paramsDict); /** * PhalApiClientResponse response = PhalApiClient.create() * .withHost(host) * .withService("Site.Index") * .withParams("name", "dogstar") * .withTimeout(3000) * .request(); */ Console.WriteLine("response ret", response.ret + ""); if (response.ret == 200) { OkayApiClient.instance().updateConfig(host, appKey, appSecrect); /** * bool tmpWrite = false; * IniFileHelper iniFileHelper = new IniFileHelper(); * tmpWrite = iniFileHelper.WriteIniString("Product", "host", host); * tmpWrite = iniFileHelper.WriteIniString("Product", "app_key", appKey); * tmpWrite = iniFileHelper.WriteIniString("Product", "app_secrect", appSecrect); */ MessageBox.Show("配置检测通过!更新成功", "小白套餐", MessageBoxButtons.OK); } else { MessageBox.Show("配置检测不正确,错误信息:" + response.msg, "小白套餐有误", MessageBoxButtons.OK); } }
private void button_import_now_Click(object sender, EventArgs e) { String model = textBox_model.Text.ToString(); if (model.Length == 0) { MessageBox.Show("请输入你的模型名称!", "模型未填", MessageBoxButtons.OK); return; } if (csvPath == null || csvPath.Length == 0) { MessageBox.Show("请选择将要批量导入的CSV文件!", "CSV文件未选", MessageBoxButtons.OK); return; } //DataTable dt = ReadExcel(path); DataTable dt = CSVHelper.OpenCSV(csvPath); if (dt == null) { return; } // 先临时这样取配置 // 读取配置 IniFileHelper iniFileHelper = new IniFileHelper(); StringBuilder sb = new StringBuilder(200); iniFileHelper.GetIniString("Product", "host", "", sb, sb.Capacity); String host = sb.ToString(); if (host.Length == 0) { host = "http://api.okayapi.com/"; } // 重置进度条 progressBar_import.Maximum = dt.Rows.Count; //设置最大长度值 progressBar_import.Value = 0; //设置当前值 progressBar_import.Step = 1; //设置没次增长多少 foreach (DataRow dr in dt.Rows) { ///遍历所有的行 Dictionary <String, String> data = new Dictionary <string, string>(); SetrichTextBox("开始导入……\r\n"); foreach (DataColumn dc in dt.Columns) { //遍历所有的列 Console.WriteLine("{0}, {1}, {2}", dt.TableName, dc.ColumnName, dr[dc]); //表名,列名,单元格数据 SetrichTextBox(String.Format("读取数据:{0}: {1}\r\n", dc.ColumnName, dr[dc])); data.Add(dc.ColumnName, dr[dc].ToString()); } String dataJson = JsonHelper.SerializeDictionaryToJsonString(data); // 开始上传数据 // http://api.okayapi.com/docs.php?service=App.Table.Create&detail=1&type=fold Dictionary <String, String> paramsDict = new Dictionary <String, String>(); paramsDict.Add("model_name", textBox_model.Text.ToString()); paramsDict.Add("data", dataJson); PhalApiClientResponse response = OkayApiClient.instance().go("App.Table.Create", paramsDict); if (response.ret == 200) { if (response.data.err_code == 0) { SetrichTextBox("导入成功……\r\n"); } else { System.Threading.Thread.Sleep(500);//暂停0.5秒 SetrichTextBox("导入失败:" + response.data.err_msg + " ……\r\n"); } } else { String tmp = "导入失败,请修正后重新导入。错误信息:" + response.msg; SetrichTextBox(tmp + "\r\n"); MessageBox.Show(tmp, "导入有失败", MessageBoxButtons.OK); break; } progressBar_import.Value += progressBar_import.Step; SetrichTextBox(">>>>>>>>>>>>>>>>>>>\r\n"); } }