通过单击“同步”按钮,我们将收集2个表的库存号并将它们打印在第1个表的库存号上。
我有两个并排的excel文件,我无法更新它们 (添加+转移)。
同步
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Excel;
using Microsoft.Office.Core;
namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
DataSet ds;
DataSet ds2;
OpenFileDialog of;
OpenFileDialog ofl;
FileStream fs;
FileStream fst;
IExcelDataReader okuyucu;
IExcelDataReader okuyucu1;
DataTable dt;
DataTable dts;
DataRow new_data_row;
int adet;
int adet2;
int StokNo1;
int StokNo2;
private void button3_Click(object sender, EventArgs e)//Synchronize Button
{
int Adet = Int32.Parse(dataGridView1.Columns[2].Index.ToString());
int Adet2 = Int32.Parse(dataGridView2.Columns[2].Index.ToString());
int StokNo1 = Int32.Parse(dataGridView1.Columns[0].Index.ToString());
int StokNo2 = Int32.Parse(dataGridView2.Columns[0].Index.ToString());
foreach (DataTable dt in ds.Tables)
{
for (int i = 0; i < ds.Tables.Count; i++)
{
StokNo1 = Int32.Parse(dataGridView1.Columns[0].Index.ToString());//The StokNo belonging to DataGridWiew1.
Adet = Int32.Parse(dataGridView1.Columns[2].Index.ToString());//The number belonging to DataGridWiew1.
}
}
foreach (DataTable dt2 in ds2.Tables)
{
for (int j = 0; j < ds2.Tables.Count; j++)
{
StokNo2 = Int32.Parse(dataGridView2.Columns[0].Index.ToString());//The StokNo belonging to DataGridWiew2.
Adet2 = Int32.Parse(dataGridView2.Columns[2].Index.ToString());//The number belonging to DataGridWiew2.
}
}
if ((StokNo1 == StokNo2))//StokNo is Equal
{
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
int toplam = adet + adet2;
ds.Tables[0].Rows.Add(toplam);
}
}
else
{
ds.Tables[0].Rows.Add();//If stokno is not equal add to the last listed
}
}
private void button4_Click(object sender, EventArgs e)
{
SaveFileDialog save = new SaveFileDialog();
save.Filter = "Excel|*.xls";
save.OverwritePrompt = true;
save.CreatePrompt = true;
if (save.ShowDialog() == DialogResult.OK)
{
StreamWriter kayıt = new StreamWriter(save.FileName);
kayıt.WriteLine(dataGridView1.ToString());
kayıt.Close();
}
}
}
}
如果库存编号等于添加到列表中,我想根据库存编号更新编号,如果库存编号不同,则在末尾添加它。