private void gridView1_Click(object sender, EventArgs e) { try { needfix = false; if (dttabledetail.Rows.Count != 0) { DataSet dsconnstr = DALUse.Query(string.Format("select * from PT_Setting where pt_id ='{0}'", cmb_ptname.SelectedValue.ToString())); if (dsconnstr.Tables.Count > 0 && dsconnstr.Tables[0].Rows.Count > 0) { connstr = dsconnstr.Tables[0].Rows[0]["connstr"].ToString(); } string sqltemp = string.Format("select * from pt_target_field where table_name ='{0}' and pt_id = '{1}'", gridView1.GetDataRow(gridView1.FocusedRowHandle)["TABLE_NAME"].ToString(), ((DataRowView)cmb_ptname.SelectedItem).Row["pt_id"].ToString()); string sqltarget = string.Format("select * from {0} where 1=0 ", gridView1.GetDataRow(gridView1.FocusedRowHandle)["TABLE_NAME"].ToString()); DataSet dstarget = DALUseSpecial.Query(sqltarget, connstr); if (dstarget.Tables.Count > 0) { dttarget = dstarget.Tables[0]; } DataSet dstemp = DALUse.Query(sqltemp); if (dstemp.Tables.Count > 0) { dttemp = dstemp.Tables[0]; } CheckTargetDict(dttemp, dttarget); gc_pt_target.DataSource = dttemp; } } catch (Exception ex) { //MessageBox.Show(ex.ToString()); } }
//将目标表的字段同步到本地 public void SynTargetField() { try { string sqltarget = string.Format("select * from {0} where 1=0 ", gridView1.GetDataRow(gridView1.FocusedRowHandle)["TABLE_NAME"].ToString()); DataSet dstarget = DALUseSpecial.Query(sqltarget, connstr); if (dstarget.Tables.Count > 0) { foreach (DataColumn dc in dstarget.Tables[0].Columns) { string columntype = ""; if (dc.DataType.Name.ToString().Contains("String")) { columntype = "STRING"; } else if (dc.DataType.Name.ToString().Contains("Decimal") || dc.DataType.Name.ToString().Contains("Int")) { columntype = "NUMBER"; } else if (dc.DataType.Name.ToString().Contains("DateTime")) { columntype = "DATE"; } else { MessageBox.Show(dc.DataType.Name.ToString()); } string sql = string.Format("insert into PT_TARGET_FIELD(compare_id,pt_name,table_name,field_name,field,field_type,compare_name,pt_id) values('{7}','{0}','{1}','{2}','{3}','{4}','{5}','{6}')", cmb_ptname.Text, gridView1.GetDataRow(gridView1.FocusedRowHandle)["TABLE_NAME"].ToString(), dc.ColumnName, dc.ColumnName, columntype, "", cmb_ptname.SelectedValue.ToString(), Guid.NewGuid()); string sql1 = string.Format("select * from PT_TARGET_FIELD where pt_id = '{0}' and table_name = '{1}' and field = '{2}'", cmb_ptname.SelectedValue.ToString(), gridView1.GetDataRow(gridView1.FocusedRowHandle)["TABLE_NAME"].ToString(), dc.ColumnName); DataSet ds = DALUse.Query(sql1); if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count == 0) { DALUse.ExecuteSql(sql); } } } else { MessageBox.Show("目标库不存在表:" + gridView1.GetDataRow(gridView1.FocusedRowHandle)["TABLE_NAME"].ToString()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }