using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace eye4 { public partial class Form3 : Form { public Form3() { InitializeComponent(); } private void Form3_Load(object sender, EventArgs e) { string sql = "select * from pinpai"; DataSet ds = DBHelper.getset(sql); this.comboBox1.DisplayMember = "NAME"; this.comboBox1.ValueMember = "NAME"; DataTable dt = ds.Tables[0]; this.comboBox1.DataSource = dt; } public string sql { get; set; } private void query() { sql = "select * from text1"; DataTable dt1 = DBHelper.getset(sql).Tables[0]; sql = "select * from text2"; DataTable dt2 = DBHelper.getset(sql).Tables[0]; sql = "select pinpai.NAME,AA_Inventory.name,ST_CurrentStock.baseQuantity,"" as a,"" as b " + " from pinpai left join AA_Inventory on pinpai.id = AA_Inventory.productInfo " + " left join ST_CurrentStock on ST_CurrentStock.idinventory = AA_Inventory.id where pinpai.NAME="1.56阳光快车混合散光""; DataTable dt3 = DBHelper.getset(sql).Tables[0]; foreach (DataRow dr in dt3.Rows) { int iindex1 = dr["name1"].ToString().IndexOf("-", 0); int iindex2 = dr["name1"].ToString().IndexOf("-", iindex1 + 1); if (iindex1 > 0) { string a = ""; string b = ""; if (iindex2 > 0) { a = dr["name1"].ToString().Substring(iindex1 + 1, iindex2 - iindex1 - 1); b = dr["name1"].ToString().Substring(iindex2 + 1, dr["name1"].ToString().Trim().Length - iindex2 - 1); } else if (iindex2 == -1) { a = dr["name1"].ToString().Substring(iindex1 + 1); b = "0"; } dr["a"] = Convert.ToDecimal(a); dr["b"] = Convert.ToDecimal(b); } // string a =dr["name1"].ToString ().Trim ().Substring ( dr["name1"].ToString().IndexOf("-", 0); } DataTable dt = new DataTable(); dt.Columns.Add("球镜柱镜", typeof(System.String)); foreach (DataRow dr in dt1.Rows) { dt.Columns.Add(dr["value"].ToString().Trim(), typeof(System.Double)); } foreach (DataRow dr in dt2.Rows) { DataRow dradd = dt.NewRow(); dradd["球镜柱镜"] = dr["value"]; dt.Rows.Add(dradd); } this.dataGridView1.DataSource = dt; foreach (DataRow dr in dt3.Rows) { foreach (DataRow dr1 in dt.Rows) { if (dr["a"].ToString().Trim() == dr1["球镜柱镜"].ToString().Trim()) { dr1[dr["b"].ToString().Trim()] = dr["baseQuantity"]; } } } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { query(); } } }
解决方案
20
str=”-“+str;