private Dictionary <Entities.ServerInfo, DbDataSet.额度分配DataTable> ChangeToDict(DataTable dtImport, out string errMsg) { errMsg = string.Empty; var dictServerDT = new Dictionary <Entities.ServerInfo, DbDataSet.额度分配DataTable>(); StringBuilder sb = new StringBuilder(); try { List <int> lstErrorRow = new List <int>(); int i = 0; foreach (DataRow row in dtImport.Rows) { i++; 买模式 买模式1 = (买模式)Enum.Parse(typeof(买模式), row[6].ToString(), false); 卖模式 卖模式1 = (卖模式)Enum.Parse(typeof(卖模式), row[7].ToString(), false); var serverInfo = row[10].ToString(); var server = ServiceConnectHelper.Instance.ServerInfoList.FirstOrDefault(_ => _.Remark == serverInfo || _.Ip == serverInfo); if (server != null) { if (dictServerDT.ContainsKey(server)) { dictServerDT[server].Add额度分配Row(row[0].ToString(), row[1].ToString(), row[2].ToString(), byte.Parse(row[3].ToString()), row[4].ToString(), row[5].ToString(), (int)买模式1, (int)卖模式1, decimal.Parse(row[8].ToString()), decimal.Parse(row[9].ToString())); } else { var dt = new DbDataSet.额度分配DataTable(); dt.Add额度分配Row(row[0].ToString(), row[1].ToString(), row[2].ToString(), byte.Parse(row[3].ToString()), row[4].ToString(), row[5].ToString(), (int)买模式1, (int)卖模式1, decimal.Parse(row[8].ToString()), decimal.Parse(row[9].ToString())); dictServerDT.Add(server, dt); } } else { lstErrorRow.Add(i); } } if (lstErrorRow.Count > 0) { sb.Append("第").Append(string.Join(",", lstErrorRow)).Append("行未找到匹配的服务器信息,无法导入!"); errMsg = sb.ToString(); } else { return(dictServerDT); } } catch (Exception ex) { errMsg = ex.Message; } return(null); }
private void 导入ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult DialogResult1 = this.openFileDialog1.ShowDialog(); if (DialogResult1 != System.Windows.Forms.DialogResult.OK) { return; } string[] FileContent = File.ReadAllLines(this.openFileDialog1.FileName, Encoding.Default); StringBuilder sbErr = new StringBuilder(128); Task.Run(() => { AASClient.AASServiceReference.DbDataSet.平台用户DataTable 平台用户DataTable1 = Program.AASServiceClient.QueryUser(); for (int i = 1; i < FileContent.Length; i++) { string[] Data = FileContent[i].Split(','); try { string stockID = UpdateStockCode(Data[1].Trim()); 买模式 买模式1 = (买模式)Enum.Parse(typeof(买模式), Data[6], false); 卖模式 卖模式1 = (卖模式)Enum.Parse(typeof(卖模式), Data[7], false); byte 市场 = byte.Parse(Data[3].Replace("深圳", "0").Replace("上海", "1")); decimal 交易额度 = decimal.Parse(Data[8]); decimal 手续费率 = decimal.Parse(Data[9]); var userInfo = 平台用户DataTable1.FirstOrDefault(r => r.用户名.Equals(Data[0].Trim())); if (userInfo != null) { Program.AASServiceClient.AddTradeLimit(Data[0], Data[1], Data[2], 市场, Data[4], Data[5], 买模式1, 卖模式1, 交易额度, 手续费率); } else { this.Invoke(new Action(() => { labelLoading.Text = string.Format("导入第{0}条记录[{1} {2}]失败,未找到该用户", i, Data[0], Data[1]); })); } } catch (Exception ex) { this.Invoke(new Action(() => { MessageBox.Show(string.Format("导入第{0}条记录[{1} {2}]异常,{3}", i, Data[0], Data[1], ex.Message)); })); break; } } var dt = Program.AASServiceClient.QueryTradeLimit(); this.Invoke(new Action(() => { this.bindingSource交易额度.DataSource = dt; })); }); }
private void ImportToServer(string[] FileContent) { StringBuilder sb = new StringBuilder(); int i = 0; foreach (var item in FileContent) { if (item.Contains("组合号")) { continue; } try { var members = Regex.Split(item, "[,,]+"); 买模式 买模式1 = (买模式)Enum.Parse(typeof(买模式), members[6], false); 卖模式 卖模式1 = (卖模式)Enum.Parse(typeof(卖模式), members[7], false); var stock = new StockLimitItem() { StockID = members[1], GroupAccount = members[2], //市场代码自动计算,不导入。 StockName = members[4], //拼音缩写不导入 BuyType = ((int)买模式1).ToString(), SaleType = ((int)卖模式1).ToString(), LimitCount = members[8], Commission = members[9] }; string res = Program.AASServiceClient.AddStock(labelShareLimitGroup.Text, stock); if (!res.StartsWith("0|")) { sb.Append("导入项错误,待保存数据 ").Append(item).Append(", 返回值 ").Append(res).Append(Environment.NewLine); } } catch (Exception ex) { sb.Append("导入项异常,待保存数据 ").Append(item).Append(",Exception Message ").Append(ex.Message).Append(Environment.NewLine); } i++; } if (sb.Length > 0) { Program.logger.LogInfo(sb.ToString()); MessageBox.Show(string.Format("导入错误或异常项{0}条,详情请查看日志!", i)); } var group = Program.AASServiceClient.ShareGroupQuery().First(_ => _.GroupName == labelShareLimitGroup.Text); this.bindingSourceStocksIn.DataSource = group.GroupStockList.OrderBy(_ => _.GroupAccount).ThenBy(_ => _.StockID); }
public string UpdateLimitItem(string[] info) { if (info.Length < 3) { return(string.Format("2|0|参数列表异常!")); } string id = info[1]; //byte market = byte.Parse(info[5]); //买模式 买模式1 = (买模式)int.Parse(info[8]); //卖模式 卖模式1 = (卖模式)int.Parse(info[9]); //decimal limitQty = decimal.Parse(info[10]); //decimal commision = decimal.Parse(info[11]); //string id, string trader, string groupID, string stockID, decimal qty, byte market, string stockName, string stockFirstLetter, decimal commission, 买模式 买模式1, 卖模式 卖模式1; if (id == CommonUtils.LimitServiceID) { try { var dt = info[2].FromJson <DbDataSet.额度分配DataTable>(); var row = dt.FirstOrDefault(); //修改 //Program.db.额度分配.UpdateTradeLimit(info[2], info[3], info[4], market, info[6], info[7], 买模式1, 卖模式1, limitQty, commision); 买模式 买模式1 = (买模式)row.买模式; 卖模式 卖模式1 = (卖模式)row.卖模式; Program.db.额度分配.UpdateTradeLimit(row.交易员, row.证券代码, row.组合号, row.市场, row.证券名称, row.拼音缩写, 买模式1, 卖模式1, row.交易额度, row.手续费率); var rowUpdated = Program.db.额度分配.Get额度分配(row.交易员, row.证券代码); if (rowUpdated != null) { var dtReturn = new DbDataSet.额度分配DataTable(); dtReturn.ImportRow(rowUpdated); return("2|1|" + dtReturn.ToJson()); } else { return("2|0|修改失败"); } } catch (Exception ex) { return("2|2|修改异常" + ex.Message); } } return("2|0|无效操作!"); }
private DbDataSet.额度分配DataTable ChangeTableToLimitDt(DataTable dtImport, out string erMsg) { erMsg = string.Empty; DbDataSet.额度分配DataTable dtLimit = new DbDataSet.额度分配DataTable(); try { foreach (DataRow row in dtImport.Rows) { 买模式 买模式1 = (买模式)Enum.Parse(typeof(买模式), row[6].ToString(), false); 卖模式 卖模式1 = (卖模式)Enum.Parse(typeof(卖模式), row[7].ToString(), false); dtLimit.Add额度分配Row(row[0].ToString(), row[1].ToString(), row[2].ToString(), byte.Parse(row[3].ToString()), row[4].ToString(), row[5].ToString(), (int)买模式1, (int)卖模式1, decimal.Parse(row[8].ToString()), decimal.Parse(row[9].ToString())); } return(dtLimit); } catch (Exception ex) { erMsg = ex.Message; } return(null); }
private void dataGridView交易额度_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if ((sender as DataGridView).Columns[e.ColumnIndex].Name == "市场") { byte byte1 = (byte)e.Value; e.Value = byte1 == 0 ? "深圳" : "上海"; } else if ((sender as DataGridView).Columns[e.ColumnIndex].Name == "买模式") { 买模式 买模式1 = (买模式)e.Value; e.Value = 买模式1.ToString(); } else if ((sender as DataGridView).Columns[e.ColumnIndex].Name == "卖模式") { 卖模式 卖模式1 = (卖模式)e.Value; e.Value = 卖模式1.ToString(); } }
private void 导入ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult DialogResult1 = this.openFileDialog1.ShowDialog(); if (DialogResult1 != System.Windows.Forms.DialogResult.OK) { return; } string[] FileContent = File.ReadAllLines(this.openFileDialog1.FileName, Encoding.Default); StringBuilder sbErr = new StringBuilder(128); Dictionary <string, int> dictIndex = new Dictionary <string, int>(); Dictionary <string, List <string> > dictTraderStock = new Dictionary <string, List <string> >(); for (int i = 0; i < FileContent.Length; i++) { var item = FileContent[i]; string[] Data = FileContent[i].Split(','); if (dictTraderStock.ContainsKey(Data[0])) { if (!dictTraderStock[Data[0]].Contains(Data[1])) { dictIndex.Add(Data[0] + "_" + Data[1], i); dictTraderStock[Data[0]].Add(Data[1]); } else { var index = dictIndex[Data[0] + "_" + Data[1]]; sbErr.AppendFormat("交易员{0} 对应股票{1} 在{2}行数据有重复项, 与第{3}行数据发生冲突", Data[0], Data[1], i.ToString(), index).Append(Environment.NewLine); } } else { dictTraderStock.Add(Data[0], new List <string>() { Data[1] }); dictIndex.Add(Data[0] + "_" + Data[1], i); } } if (sbErr.Length > 0) { Program.logger.LogInfo(sbErr.ToString()); sbErr.Append("请修改至无重复项再导入!"); MessageBox.Show(sbErr.ToString()); } else { AASClient.AASServiceReference.DbDataSet.平台用户DataTable 平台用户DataTable1 = Program.AASServiceClient.QueryUser(); for (int i = 1; i < FileContent.Length; i++) { string[] Data = FileContent[i].Split(','); 买模式 买模式1 = (买模式)Enum.Parse(typeof(买模式), Data[6], false); 卖模式 卖模式1 = (卖模式)Enum.Parse(typeof(卖模式), Data[7], false); try { foreach (AASClient.AASServiceReference.DbDataSet.平台用户Row 平台用户Row1 in 平台用户DataTable1.Where(r => r.用户名.Equals(Data[0].Trim()))) { Program.AASServiceClient.AddTradeLimit(Data[0], Data[1], Data[2], byte.Parse(Data[3]), Data[4], Data[5], 买模式1, 卖模式1, int.Parse(Data[8]), decimal.Parse(Data[9])); } } catch (Exception ex) { MessageBox.Show(string.Format("导入第{0}条记录[{1} {2}]失败,{3}", i, Data[0], Data[1], ex.Message)); break; } } } this.bindingSource交易额度.DataSource = Program.AASServiceClient.QueryTradeLimit(); }
private void 导入ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult DialogResult1 = this.openFileDialog1.ShowDialog(); if (DialogResult1 != System.Windows.Forms.DialogResult.OK) { return; } string[] FileContent = File.ReadAllLines(this.openFileDialog1.FileName, Encoding.Default); StringBuilder sbErr = new StringBuilder(128); Dictionary <string, int> dictIndex = new Dictionary <string, int>(); Dictionary <string, List <string> > dictTraderStock = new Dictionary <string, List <string> >(); //for (int i = 0; i < FileContent.Length; i++) //{ // var item = FileContent[i]; // string[] Data = FileContent[i].Split(','); // if (dictTraderStock.ContainsKey(Data[0])) // { // if (!dictTraderStock[Data[0]].Contains(Data[1])) // { // dictIndex.Add(Data[0] + "_" + Data[1], i); // dictTraderStock[Data[0]].Add(Data[1]); // } // else // { // var index = dictIndex[Data[0] + "_" + Data[1]]; // sbErr.AppendFormat("交易员{0} 对应股票{1} 在{2}行数据有重复项, 与第{3}行数据发生冲突", Data[0], Data[1], i.ToString(), index).Append(Environment.NewLine); // } // } // else // { // dictTraderStock.Add(Data[0], new List<string>() { Data[1] }); // dictIndex.Add(Data[0] + "_" + Data[1], i); // } //} //if (sbErr.Length > 0) //{ // Program.logger.LogInfo(sbErr.ToString()); // sbErr.Append("请修改至无重复项再导入!"); // MessageBox.Show(sbErr.ToString()); //} //else Task.Run(() => { AASClient.AASServiceReference.DbDataSet.平台用户DataTable 平台用户DataTable1 = Program.AASServiceClient.QueryUser(); for (int i = 1; i < FileContent.Length; i++) { string[] Data = FileContent[i].Split(','); try { 买模式 买模式1 = (买模式)Enum.Parse(typeof(买模式), Data[6], false); 卖模式 卖模式1 = (卖模式)Enum.Parse(typeof(卖模式), Data[7], false); byte 市场 = byte.Parse(Data[3].Replace("深圳", "0").Replace("上海", "1")); decimal 交易额度 = decimal.Parse(Data[8]); decimal 手续费率 = decimal.Parse(Data[9]); var userInfo = 平台用户DataTable1.FirstOrDefault(r => r.用户名.Equals(Data[0].Trim())); if (userInfo != null) { Program.AASServiceClient.AddTradeLimit(Data[0], Data[1], Data[2], 市场, Data[4], Data[5], 买模式1, 卖模式1, 交易额度, 手续费率); } else { this.Invoke(new Action(() => { MessageBox.Show(string.Format("导入第{0}条记录[{1} {2}]失败,未找到该用户", i, Data[0], Data[1])); })); } //foreach (AASClient.AASServiceReference.DbDataSet.平台用户Row 平台用户Row1 in 平台用户DataTable1.Where(r => r.用户名.Equals(Data[0].Trim()))) //{ // Program.AASServiceClient.AddTradeLimit(Data[0], Data[1], Data[2], 市场, Data[4], Data[5], 买模式1, 卖模式1, 交易额度, 手续费率); //} } catch (Exception ex) { this.Invoke(new Action(() => { MessageBox.Show(string.Format("导入第{0}条记录[{1} {2}]失败,{3}", i, Data[0], Data[1], ex.Message)); })); break; } } var dt = Program.AASServiceClient.QueryTradeLimit(); this.Invoke(new Action(() => { this.bindingSource交易额度.DataSource = dt; })); }); }