when developing a system, decisions are often made based on various problems. For example, whether logs are written to text files or databases, whether the email reminder function is automatically sent by the system or actively sent by the user. The following lists my frequently encountered problems and my strategies.
1. How to first test the user account of the system before the system starts running
this problem is common. Before developing the system, create a user table, create your account, and set the corresponding permissions to the highest level of administrator permissions, then, write the Code , and use the SQL Enterprise Manager to create a user table. Later, we developed a user role management tool for the system and directly used the management tool to create users. This is more efficient than directly operating the SQL Enterprise Manager. Another advantage is that you can assign the user management responsibilities to others to facilitate others and yourself.
later, for user management, almost all applications Program needed, it is a general user role management tool that is constantly improved. Until now, if you start a new project, the first step to create a user is not to open the SQL Enterprise Manager to create a user table, but to directly use common management tools to create roles and users in turn, and assign permissions to users. In this way, my work has been relatively easy and I don't need to add many classes.
after using this model for a while, you may not even know the basic information of your potential users, or even the data that uniquely identifies the users. Taking our company as an example, the company uses the domain model to manage the company's network. After completing the web program, place it on the Intranet and set the Windows verification method. When a user accesses our company's system, all information except the user's login ID cannot be obtained, and the role permission information cannot be obtained. Ask the company's predecessors, refer to the user management mode of other systems of the company, you need to write a Wizard program. If the user currently logged in does not exist in the System user table, it is automatically redirected to the Wizard Page, guiding the user to enter their own information, such as department and role. After you click the submit button, an email is automatically forwarded to the system administrator. The Administrator logs on to the application for review (confirmed by phone and email.
on the basis of the Common User role management tool, write another wizard to guide the user to create their own role permission information. You only need to review and confirm the information in the background. Compared with other policies, for example, if the system table does not have the current user, directly go to the error page or throw an exception. Compared with these methods, the above method will be much more intelligent and make users feel much better.
2. How to deal with the problem that the system cannot connect to the database or an exception occurs?
There are several processing methods: the program does not have any processing, if you cannot connect to the database, the exception page is displayed directly.
You can set the error handling configuration section in Web. config to jump to the specified error page. The settings are as follows:
<Customerrors mode = "off" defaultredirect = "error. aspx">
<Error statuscode = "403" Redirect = "noaccess.htm"/>
<Error statuscode = "404" Redirect = "filenotfound.htm"/>
</Customerrors>
When an error occurs, the error prompt page is displayed. For example, the error handling method of the blog Garden
This method is greatly improved compared with the previous processing strategy.
I remember that when I entered a system, an error occurred. The system only prompts text or images such as an error. However, the system did not put correct clickable links like the above picture, it does not make users feel at a loss. Users do not know what to do with common errors.
After some system errors occur, the browser will be redirected to other pages of the system at the specified time. For example, in the irrigation area of the csdn Forum, sometimes the topic of a post is very attractive, so I clicked in and found that the post has been deleted by the Administrator. The error page is several seconds later, redirect to the homepage of the Forum.
It is inevitable to record the error log. In my handling method, I will automatically send an email to the system administrator. The email contains detailed information about exceptions. You only need to check the content of the email to see if the system has any exceptions. When a user calls me, I can check the email to find out what went wrong and solve the problem quickly. Generally, after the system has been running for a few months, the system rarely receives an exception notification email.
3. How to Handle System string Resources
I mean, when an operation is completed or fails, the location of the string that is prompted to the user is stored. The following code
MessageBox. Show ("the Excel data format is incorrect. The specified Excel work form cannot be found. Please reselect the Excel file "," XX-System ", messageboxbuttons. OK, messageboxicon. information );
This code tells the user that the operation has failed due to an error.
The code I used to write is usually to pass the string directly to the MessageBox. Show method. This processing method has no problems in running the program.
The interface operation prompt string is distributed in each file on the interface. This is a problem. If the system does not write it by yourself, sometimes the user calls the phone and does not understand what this prompt means during development. The solution usually needs to be directly debugged into the Code. If there are similar prompts in multiple places in the system, the user's error should also be reproduced to find out the problem is more complicated. Then re-construct the following method
Private String title = "XX-system ";
Private string formaterror = "Excel Data Format error. The specified Excel work form cannot be found. Please reselect the Excel file ";
MessageBox. Show (formaterror, title, messageboxbuttons. OK, messageboxicon. information );
Compared with the previous version, this approach has made significant progress. When a user asks us a question, it is easier to find the cause of the error. You can locate the code based on the string value and determine what the problem is.
Later, I found that a friend's system handled the string resource prompt in this way.
Write all the prompts to a static class and number them in sequence. This method is more advanced than the above method.
It really takes time to make progress.
There is another problem with this practice, that is, it cannot adapt to programs with multi-language requirements. If you are using a program that supports both Chinese and English, you can select your preferred language. If the user chooses English, the English message should be displayed. users who are used to Chinese should prompt Chinese information as needed.
This requirement can be solved by using the resx resource file. You can view related content online. I added a method that I learned from an open-source system. The article address is as follows:
Application open-source project stringresourcetool2 to implement. Net multi-language solutions
The annoyance of using resx files is that vs's smart prompt function cannot be used. In the above applicationmessage class, when you knock on the parameters of the MessageBox. Show method, you can find the corresponding msgxx using the smart prompts of IDE.
If you choose to use stringresourcetool2, it is not only as convenient as applicationmessage, but also supports the needs of multiple languages by using ide smart prompts. The following code shows
[Strings]
Raw = raw string
Stringarg (string name) = with name argument {0}
[Strings. ZH-cn]
Raw = original string
Stringarg (string name) = Simplified Chinese parameter {0}
This solution is the most perfect solution I have found for storing string resources. Generally, I compile the string resources required by each project into an assembly for each project.
4. Are logs written to text files or databases?
This issue depends on specific scenarios. I will write the system business operation logs to the database. If an exception log is generated, the exception log is written to a text file based on the log occurrence date as the file name. During the fixed period of each month, the system obtains the exception occurred in the last month based on the file name and solves it in a centralized manner.
For hierarchical applications, such as using ORM middleware in the system, if logs are to be written, they are directly written to text files. Generally, erroneous SQL statements are directly written to the execution directory of the application, this facilitates problem diagnosis and the use of middleware class libraries.
The practice of MS in the. NET Framework is throw an exception, which is a policy of the system framework. The exception log text that it throws each time is very standard, and is usually copied directly to Google to search for the answer.
5. For values of the date type, use the string type (varchar) in the database, or use the datetime type (datetime)
Maybe this question is naive. Let me talk about the Application Scenario first.
In the input form of a work instruction sheet of a production management system, a field in the form is FOB and the meaning of the field is to enter the delivery date of the part. For parts that know the delivery date, simply select a time. However, sometimes I don't know which day to deliver the goods. I may need to have a meeting with the Logistics Department to discuss it. The manager asks you to fill in the work instruction form first, open the materials first, and then confirm the FOB date.
(Note: After receiving the work instruction sheet, the factory can start processing as required in the instruction sheet; otherwise, the factory will not dare to process and produce the work)
The problem arises. It is converted into a programmer's language, that is, to write a value to the database now. This value is blank temporarily, but will be updated to the date value later, is the string type (varchar) or datetime type selected as the Field Type of the column?
if you select a string, if you do not know the FOB date, you can directly empty the value (null) or string. empty, and then display it as the date value type on the interface. If REPORT query is involved, for example, to query orders with FOB instances in the last month, you also need to convert this field to the date and time type for comparison. It is not convenient to query reports.
if you select the date and time type, you can leave the value null when you do not know the FOB date ). If the field is not allowed to be blank in the database, you can put a "distant" date, which has no practical effect and is equivalent to a placeholder. In later discussions, if you know the specific FOB date, update it to the actual date. When reading the date value on the interface, it is found to be a special value, you need to convert it.
if you do not know the time value, and you must enter another date and time value in the database, there are two solutions. Select a value that is much larger than the current value, or select a value that is much smaller than the current value. When selecting the minimum value, you should note that the minimum value of datetime. min in. NET is in the first year of the year, while the minimum value of the date type in SQL Server is in the Founding Day of the United States, 1753-01-01. For null values, the default value of datetime in SQL Server 2000 is 00:00:00, while that of datetime in C # is the minimum value of 0001-01-01 00:00:00.
when reading data in a program, if the date is null, you can define datetime? This type is used to store date null values.
Another solution is to store date values using integer data. You can use the datetime. internalticks attribute to obtain the long integer value corresponding to the date type. In the past, when delphi5 was used to debug the program, the date type value in the watch window was displayed as an integer. You need to convert it to see the specific time .. Net Framework datetime type is also a long integer to process the date and time.
6 for the interface, make it usercontrol or form
this problem also applies to ASP. net web, whether to make the interface into the ascx user control, or directly into the web form.
Let's Talk About win forms. There is little difference between them. The reason for making a usercontrol is usually to reuse it and directly nest it into another form. However, usercontrol cannot be tested independently and must be loaded by a form to run it. Make the interface into a form. You can run the test independently. You can also nest the interface in the pannel control of another form using the following techniques.
frmabout FRM = new frmabout ();
frm. toplevel = false;
frm. parent = Panel;
frm. dock = dockstyle. fill;
frm. show ();
for example, region information management on the right is an independent form that is loaded into the pannel control on the right.
it is convenient for testing and can be nested into another form for reuse. Therefore, in win form, we recommend making the interface form.
let's take a look at the web and put some interfaces into the ascx file to reuse them. However, ascx has two problems in the Web
1) If ascx references image script resources, the path to search for resources starts with the relative path of the web form to load it.
2) The ascx control needs to be re-loaded every time the PostBack is sent.
similarly to usercontrol of win forms, the user control of ascx cannot run directly, and must be loaded by web form to run. I have not compared the performance of using ascx and web form, but I have a personal meeting.
when it's okay, I will go to my friend's QQ space. I found that as long as I remember my friend's QQ number, I can find all his logs and album addresses. The address format of the QQ space is 36xxxx.qzone.qq.com. I only need to remember this address to find his recent log, his mood, and photos of his recent marriage. According to the program design method, the display of photos and display logs must be completed on two pages. However, it seems from the address bar that they are the same page. This function can be implemented using frameset or the ascx control.
frameset is used in the QQ space. If. NET is used as the QQ space, you can use ascx to achieve the same effect.
my conclusion is that if you want to improve the user experience, especially for systems that are very valuable to URL addresses, we recommend using the ascx control.
7. data verification plan
Some code is usually used to verify user input. Although sqlparameter can omit to verify whether the string entered by the user contains single quotes, there is still a considerable amount of code to perform business verification. Verify that the name entered by the user is valid.
If the verification fails and the data entered by the user does not meet the requirements, there are usually two methods.
1) The system directly prompts that the data entered by the user is illegal and requires the user to re-enter the data
2) store user input data in the grass and help the user Save the data first. After the User goes to the relevant manual or asks the colleague why the data has a problem. The user calls out the draft data that has been previously entered, re-adjusts the data, and then converts the data to available business data.
This problem comes from the following scenarios.
Assume that you create a new purchase application form, apply to purchase 10 computers, and enter the purchase application form in the purchase system. After the input is complete, submit and save. If the storage fails, the system prompts that the purchase order number is incorrect. The person applying for a computer does not know how to handle this error, because he does not understand the production rules of the purchase order number, and does not need to understand it. He will call the Development Department, or go directly to the Development Department to ask relevant personnel for help. After understanding the information, he will return to his position. He will be confident in unlock the computer, re-enter the purchase order number, and click "save, the system prompts that the session has expired. You must enter the user name and password again. The system is very intelligent. It knows that the client will stop the session if there is no connection response within half an hour. However, all the data that the user has lost will be pushed by the system's cleverness, the user needs to complete the input data again.
The user was opposed to this type of data input form, but it was not convenient to use Excel. Now, this problem occurs again. Next time, let him fill in system comments in the user feedback form, he must be the first to raise an objection.
When verifying the data, if the data is found invalid, you can save it as a temporary file first. For example, you can use binary serialization to save the current data into a temporary file, so that you can directly call it and modify it. After the modification, the data is verified and then saved to the database.
However, I know this idea too late, and many of my systems also adopt the first data verification scheme. If the verification fails, they directly refuse to save it.
Human learning requires a process, and sometimes they are in a hurry. It is not an overnight task to get in touch with ideas, understand, and use them.
I have written a sentence in this book. When encountering problems, I should say to myself, boy and slowly.
I would like to share this sentence with you.