10 Replies - 544 Views - Last Post: 07 December 2019 - 04:22 PM Rate Topic: -----

#1 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 815
  • Joined: 15-December 14

Can you write a txt and then write over it with new txt?

Posted 06 December 2019 - 12:14 AM

My office manager knows nothing about IT/programming, his father is in a higher position and got him that job without him having any technical knowledge. He wanted me to make an inventory program and I started learning about mysql, thinking that would be the best option. He refused and wanted it done in C# (He doesn't want to have to learn how to enter things to use mysql). He just basically wants to enter data and forget about it (Not saving it). Yes, I also mentioned using excel and he refused.

I have an idea how to make an inventory program, I was going to save the data as txt files and then when the information changes write over it, like you would a VCR or audio cassette. My question is whether its possible to do it and how would I write over the old txt?

Is This A Good Question/Topic? 0
  • +

Replies To: Can you write a txt and then write over it with new txt?

#2 maceysoftware   User is offline

  • Member Title
  • member icon

Reputation: 394
  • View blog
  • Posts: 1,649
  • Joined: 07-September 13

Re: Can you write a txt and then write over it with new txt?

Posted 06 December 2019 - 01:36 AM

Database would be the way to go.

But seeing as you have already mentioned that's a no go, what about XML instead of text files? At least it has some sort of structure then, you can read the XML into a object structure, modify the objects through the application and when it's time to save, serialise the XML to text file.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7244
  • View blog
  • Posts: 24,556
  • Joined: 05-May 12

Re: Can you write a txt and then write over it with new txt?

Posted 06 December 2019 - 04:58 AM

Actually, I think the issue is that the boss thinks he needs to use MySQL directly. There is no need. You can still write your custom C# code to provide the UI, but save the data into MySQL, or SQLite, or SQL Server Express, or BerkleyDB, or horror of horrors a text file.

The main issue with saving to a text file is that you can't overwrite records easily. There is a very high risk of data corruption as you try to do that overwrite.
Was This Post Helpful? 0
  • +
  • -

#4 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3071
  • View blog
  • Posts: 11,783
  • Joined: 03-December 12

Re: Can you write a txt and then write over it with new txt?

Posted 06 December 2019 - 06:27 AM

I wouldn't use a txt file for that for a number of reasons. Chief among them, if you have even a lite product list, importing and updating the file will get tedious. Without knowing more details, I would probably go with a SQLite datastore so you don't have to add hardware support like a computer on the network acting as a server for the sql instance. SQLite is text files anyway, it's just done where you can query and manipulate the data better. Then do a frontend in whatever and simplify it as much as possible. But you may be fighting a losing battle unless you can get buy in from someone above him regardless.
Was This Post Helpful? 0
  • +
  • -

#5 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 815
  • Joined: 15-December 14

Re: Can you write a txt and then write over it with new txt?

Posted 06 December 2019 - 12:01 PM

Ok, all good ideas, I have a few questions.

maceysoftware
1.I looked up XML and I see what to do with it. I've never heard of XML before and this seems to be the best tutorial for it, would you agree?
https://www.c-sharpc...xml-in-C-Sharp/

Skydiver
I've never used MYSQL or any of the other data bases before. To make sure I understand you, I can store the information in sql and have the user just input data without having to do the following?
(Sorry if this isn't right, I just barely began to learn mysql and this is from memory.
SELECT computers
FROM machines working

astonecipher
Looks like a good idea, but he doesn't want to have to enter queries or learn how to do anything.


He just basically wants to enter information, see the information thats up to date and change the information. Kind of like this, for example.

Total number of computers
38
change total <y/n>
//if he selects yes
Enter new total of computers
//he enters the information
//the program updates and then shows
Total number of computers
40
Was This Post Helpful? 0
  • +
  • -

#6 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3071
  • View blog
  • Posts: 11,783
  • Joined: 03-December 12

Re: Can you write a txt and then write over it with new txt?

Posted 06 December 2019 - 12:07 PM

You are talking about a basic CRUD (Create Read Update Delete) application. You never mentioned if it would be web or desktop, so my assumption was web, is it?
Was This Post Helpful? 0
  • +
  • -

#7 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 815
  • Joined: 15-December 14

Re: Can you write a txt and then write over it with new txt?

Posted 07 December 2019 - 11:32 AM

My idea was to have it as a desktop program that people could input changes to the inventory. Later on, I'd like to put it in an azure account so it would be accessible by cell or by desktop (laptop) computer.

I actually found out through ms visual studios I can make a GUI. So I see what you guys meant by using sql with c#. I can make a GUI so he can input data and then save it in a sql program. Best of all, he won't have to learn how to use sql.

This post has been edited by albert003: 07 December 2019 - 11:57 AM

Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7244
  • View blog
  • Posts: 24,556
  • Joined: 05-May 12

Re: Can you write a txt and then write over it with new txt?

Posted 07 December 2019 - 01:29 PM

Out of curiosity, what needs to be inventoried? Is it just a small set of well-known class of items and you simply need a count of these items like you showed in your post #5. E.g. "computers", "monitors", "pencils", etc. ? Or is the class of items variable overtime and you need the ability to add new item classes?

If the item classes are fixed (or the probability of adding new item classes is very low), then you may just get by with using the settings support provided by the IDE project templating code. See
Manage application settings (.NET)
Application Settings Overview

Alternatively, as previously mentioned previously, just use object serialization to save to XML or JSON.

If you need the flexibility of a true inventory system where the item classes are not hardcoded, then a database is the correct thing to use.
Was This Post Helpful? 0
  • +
  • -

#9 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7506
  • View blog
  • Posts: 15,556
  • Joined: 16-October 07

Re: Can you write a txt and then write over it with new txt?

Posted 07 December 2019 - 02:23 PM

The nature of your data store should be irrelevant to the rest of your program. Start by defining interfaces. e.g.:
public interface IQryTruck {
    Truck GetTruckForId(int id);
    IEnumerable<(int id, string name)> GetAllTrucks();
}

public interface ICmdTruck {
    void TruckAdd(TruckEntry entry);
    void TruckEdit(int id, TruckEntry entry);
}



Those methods can point to a live db, or some in memory mockup, depending on what's going. You, the developer, can point those at any data store you like, memory, database, flat file, whatever. The point is, it shouldn't matter to the rest of your program or the suit who doesn't know what a program is.

If you're leaning toward flat file, I'd go for SQLite. It basically is a single file with no server requirement, tends to behave better than something that will ultimately use System.IO.Stream, an comfortable straddles the domain of simple text fields and RDBMS.
Was This Post Helpful? 1
  • +
  • -

#10 albert003   User is offline

  • D.I.C Addict

Reputation: 37
  • View blog
  • Posts: 815
  • Joined: 15-December 14

Re: Can you write a txt and then write over it with new txt?

Posted 07 December 2019 - 03:34 PM

Originally I was hired as a python developer but the David is adamant that I use C#. I argued that it would be better to use python to make this program till I was blue in the face but he won't budge.

Skydiver

David wants an inventory of the computers that are working, the ones that are down, the computers that are down to put whats wrong/parts missing/start date the computer was down.

Right now, its all done on paper and its messy.

I will look through all of the links you gave me tonight.

baavgai

I was actually learning mysql I've actually never heard of sqlite, if its something you guys recommend I use, I will stop learning mysql and learn it.
Was This Post Helpful? 0
  • +
  • -

#11 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7506
  • View blog
  • Posts: 15,556
  • Joined: 16-October 07

Re: Can you write a txt and then write over it with new txt?

Posted 07 December 2019 - 04:22 PM

View Postalbert003, on 07 December 2019 - 06:34 PM, said:

I was actually learning mysql I've actually never heard of sqlite

Same thing, mostly. Which is to say, you know that data store abstraction thing I was talking about? Well, ADO.NET has a similar mechanism.

While your database provider might have extra bonus methods, chances are it extends System.Data.Common. If you work at the DbCommand level for all things, then the implementing connector doesn't matter so much.

Some can be picky about how bind variables are aliased in SQL, when it might be @name instead of :name, but it's minor. Now, if you want some real fun, auto generate entity framework objects and work at that level. Don't like databases, do code first. Like databases, point dotnet ef dbcontext scaffold at it and watch the magic happen.

A NoSQL database is a rarefied beast. However, any SQL database functions on similar logic. Rather than learning MSSQL, or MySql, or, SQLite, or Oracle, or whatever, learn SQL, ADO.NET, entity framework, and don't worry about the SQL datastore so much.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1