Reputation: 1636
So I have a GUI using MSVS 2010 and I am creating many forms.
My main form opens up my text file "database" and concats the proper data to a different opened file. If the opened file has data that does not match in the database file then I would like to add that data to the database file.
With that being said, when a button "dataBaseSaveButton_Click" is clicked a new form will pop up that has textboxes reading: Machine, Name, PTP Name, CMP Name, T-Width, Feeder Pitch. Most of the fields will be auto-populated and others the user will have to enter in.
Also in the form there is another "save" button. Now, on this form, the save button will actually take the data in the textboxes and open up the proper file (the database file) and save it (update the database) in a certain format.
The "Save To Data Base" form looks like this:
My code from the main form looks like this (when the button is clicked):
private void dataBaseSaveButton_Click(object sender, EventArgs e)
{
int unknownCP4Counter = theCP4UnknownList.Distinct().Count();
foreach (var line in theCP4UnknownList.Distinct())
{
var splitUnknowns = line.Split(' ');
KTS_Save saveForm = new KTS_Save("CP4", splitUnknowns[0], splitUnknowns[1], splitUnknowns[3], splitUnknowns[4], openDataBase2File.FileName, unknownCP4Counter);
saveForm.ShowDialog();
unknownCP4Counter--;
}
}
The code for the Save To Data Base form looks like:
private string _Machine;
private string _Name;
private string _PtpName;
private string _TapeWidth;
private string _FeederPitch;
private string _DataBaseFileName;
public KTS_Save()
{
InitializeComponent();
}
public KTS_Save(string Machine, string Name, string PtpName, string TapeWidth, string FeederPitch, string DBFileName, int Counter)
{
InitializeComponent();
_Machine = Machine;
_Name = Name;
_PtpName = PtpName;
_TapeWidth = TapeWidth;
_FeederPitch = FeederPitch;
_DataBaseFileName = DBFileName;
machineTextBox.Text = _Machine;
nameTextBox.Text = _Name;
ptpNameTextBox.Text = _PtpName;
tapeWidthTextBox.Text = _TapeWidth;
feederPitchTextBox.Text = _FeederPitch;
counterLabel.Text = Counter.ToString();
}
private void dataBaseSaveButton_Click(object sender, EventArgs e)
{
//This is where I need help.
}
What I need help with is actually printing out all of the textbox data into the file that already exists.
I know this is probably not the most efficient way to do things, so if you have any recommendations please let me know! :)
(Oh yeah..)
I would like the program to run like so (or similar):
Upvotes: 2
Views: 204
Reputation: 40345
You can "technically" insert into a file, but you basically have to copy the entire file over every time you insert something. To be more precise: it's not a real insert, because the file system does not support inserts. There are multiple examples online, but I would actually recommend that you avoid the whole debacle and either use an embedded database or XML files.
I would highly recommend that you use an SQLite database and take advantage of the ADO .NET Entity Framework, but if that's a big hassle for you then you can do simple XML files.
Here are some examples:
Good luck.
Upvotes: 1