Build a back-end management system for ASP.-easyui defect Repair and extension in mvc4+ef5+easyui+unity2.x

Source: Internet
Author: User
Tags httpcontext string format

Unconsciously already over 13 said, (originally also to speak more about is, the data validation of the custom validation, based on the park friends or on the authority of this block more daring interest, say not to verify or to see everyone's reflection), we should have a summary of the system.
First of all, this is a team development project, based on interface programming, we started with the framework of the Easyui build system, started a sample program to operate on the Easyui DataGrid, and implemented unity injection into the container, so that the program
Improved performance, improved code quality, better unit testing, use of logs and exceptions, robust system stability, and more ....


Of course, you should feel that there are a lot of deficiencies in the system, we should try to optimize it.
Below I have listed the need to optimize the project, if you think there is optimization, please submit, I will join in future articles

    1. UI aspect, our Easyui window popup form, is not not center, good ugly Ah;
    2. DataGrid Although I am binding when I write to adapt to the frame according to the change of the first form, when you click the Zoom out or enlarge button of the viewer, then your DataGrid is deformed;
    3. JS we introduced the details page JS, should we embed him in the _layout_----inside? and to bundle?
    4. The date format of our DataGrid return is/date (20130450000365) can you read it?
    5. Our BLL is going to be instantiated every time. Dbcontainer db = new Dbcontainer (); Repeat, should we write a BASEBLL base class class inheritance
    6. Many of our front-end tips are the same, should not be encapsulated, such as click: Details when not selected Prompt "Please select the record to operate"
    7. Toolbar add, delete, change the button like every time you paste the code also a lot, we should extend the HtmlHelper of the MVC package, then we @html. It's coming out. More convenient, later also used for permission control

The optimized system will probably be the last release source version, if no longer provide the source code download, but the content, will all contain complete source code, you will complete the system "treasure" up, because
For this is the result of your labor

Finally, we will accept a larger goal challenge, a rights management system. I think this is the most concern of all, but before that, we will have to add some knowledge.

    • The filter usage that comes with MVC
    • MVC Routing Rotun Concept

The authority system is finished, we speak T4 template, export reports and charts, file upload, system settings and so on. Let our system come out and be able to use it as a project.
Since the logic and coding of the next thing is much more complex than before, the update may be slower than before. Please wait patiently, thank you for the support of the park, no matter how busy I will continue to update

Now let's deal with the above 7 questions first!

1.UI aspect, our Easyui window pop-up form, is not not center, good ugly Ah;

  

easyui1.3.2 version, window pop-up will not be centered. And dialog is centered, we have to expand for window's Open event.

The code is as follows: Just add the following code. If you're looking at the MVC Project series, put him in the jquery.easyui.plus.js.

//to center the windowvarEasyuipanelonopen =function (left, top) {varIframewidth = $ ( This). Parent (). Parent (). width (); varIframeheight = $ ( This). Parent (). Parent (). height (); varWindowWidth = $ ( This). Parent (). width (); varWindowHeight = $ ( This). Parent (). height (); varSetWidth = (iframewidth-windowwidth)/2; varSetHeight = (iframeheight-windowheight)/2; $( This). Parent (). CSS ({/*Fix panel position*/left:setwidth, top:setheight}); if(Iframeheight <windowheight) {        $( This). Parent (). CSS ({/*Fix panel position*/left:setwidth, Top:0        }); }    $(". Window-shadow"). Hide ();}; $.fn.window.defaults.onopen= Easyuipanelonopen;
Jquery.easyui.plus.js

Perfectly centered.

When you click Maximize, the resize will also occur when minimized again, and we must expand the event.

var easyuipanelonresize = function (left, top) {    var iframewidth = $ (this). Parent (). Parent (). width ();    var iframeheight = $ (this). Parent (). Parent (). height ();    var windowwidth = $ (this). Parent (). width ();    var WindowHeight = $ (this). Parent (). height ();    var setwidth = (iframewidth-windowwidth)/2;    var setheight = (iframeheight-windowheight)/2;    $ (this). Parent (). CSS ({/* correction panel position */        left:setwidth-6,        top:setheight-6    });    if (Iframeheight < WindowHeight) {        $ (this). Parent (). CSS ({/* correction panel position */            left:setwidth,            top:0        }) ;    }    $ (". Window-shadow"). Hide ();    $ (". Window-mask"). Hide (). width (1). Height (in.). Show ();}; $.fn.window.defaults.onresize = easyuipanelonresize;

The window component can be compatible with


2.DataGrid Although I have written in the binding time to adapt to the frame according to the changes of the first form, when you click the zoom in or out of the browser button, then your DataGrid is deformed;

  

The DataGrid has a 100%-width setting, but sometimes it's not very satisfying, like if you zoom in or out of your browser, then the DataGrid only maintains the width of the first load, very ugly

$ (' #List '). DataGrid ({            URL: '/syssample/getlist ',            Width: $ (window). Width ()-Ten,            Methord: ' Post ',            Height: $ (window). Height ()-            fitcolumns:true,.................................

You see $ (window). Width ()-10 and $ (window). Height ()-35

This is the first time I have set the page load, go to the form after the width and height of the calculation, then the first load display is normal, but to enlarge or stretch the browser, the DataGrid will not change, we are going to use a jquery method, called resize ()

Parameters

fnFunction V1.0

The handler function that is bound in each of the resize events of the matching element.

[Data],fnString,function V1.4.3

Data: Resize ([data], FN) can pass in data for function fn processing.

FN: The handler function that is bound in the Resize event of each matching element.

See the events that are fired when the browser changes, so we want to add:

!--automatic DataGrid events that occur when the form is first loaded and resized: Partial view--><script type= "Text/javascript" >    $ (function () {$ (        window). Resize (function () {            $ (' #List '). DataGrid (' resize ', {                width: $ (window). Width ()-Ten,                Height: $ ( window). Height ()-().            DataGrid (' Resize ', {                width: $ (window). Width ()-Ten,                Height: $ (window). Height ()- );});            </script>

OK, let's make a comparison (first load)

When you zoom out of your browser

Perfect display


3.JS we introduced JS on the details page, should we embed him in the _layout_----? and to bundle?

I've been compressing it. Source code out.
4. The date format of our DataGrid return is/date (20130450000365) do you understand?

MVC resolves the format of the date returned by the JSON DataGrid is/date (20130450000365)

is actually a JSON format problem, we should be formatted when we return the JSON, we need to rewrite the system's Jsonresult class, new references system.web and system.web.extensions

Using system;using system.collections.generic;using system.linq;using system.text;using System.Web.Mvc;using System.text.regularexpressions;using system.web;using system.web.script.serialization;namespace App.Common{Public Class Tojsonresult:jsonresult {const string error = "The request was blocked because sensitive information was disclosed to a third-party web site, which is used when a GET request is made." In order to be able to get requests, set Jsonrequestbehavior allowget.        ";             <summary>///format string///</summary> public string Formatestr {get;        Set            public override void Executeresult (ControllerContext context) {if (context = = null)            {throw new ArgumentNullException ("context"); } if (Jsonrequestbehavior = = Jsonrequestbehavior.denyget && string.equals (context. HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)) {throw new Invalido            Perationexception (Error); }           Httpresponsebase response = context.            Httpcontext.response; if (! String.IsNullOrEmpty (ContentType)) {response.            ContentType = ContentType; } else {response.            ContentType = "Application/json"; } if (contentencoding! = null) {response.            ContentEncoding = contentencoding;                if (Data! = null) {JavaScriptSerializer serializer = new JavaScriptSerializer (); String jsonstring = serializer.                Serialize (Data);                String p = @ "\\/date\ ((\d+) \+\d+\) \\/";                String p = @ "\\/date\ (\d+\) \\/";                MatchEvaluator matchevaluator = new MatchEvaluator (convertjsondatetodatestring);                Regex reg = new regex (p); jsonstring = Reg.                Replace (jsonstring, MatchEvaluator); Response.            Write (jsonstring); }}///<summaRy>///Convert JSON serialized time from/date (1294499956278+0800) to string///</summary> private string Convertjson Datetodatestring (Match m) {string result = string.            Empty;            String p = @ "\d";            var CArray = M.value.tochararray ();            StringBuilder sb = new StringBuilder ();            Regex reg = new regex (p); for (int i = 0; i < carray.length; i++) {if (reg. IsMatch (Carray[i]. ToString ())) {sb.                Append (Carray[i]); }}//Reg.            Replace (M.value;            DateTime dt = new DateTime (1970, 1, 1); DT = dt. Addmilliseconds (Long. Parse (sb.)            ToString ())); DT = dt.            ToLocalTime (); result = dt.            ToString ("Yyyy-mm-dd HH:mm:ss");        return result; }    }}

Create the base class for the controller, Basecontroller let the controller inherit the controller

Using system;using system.collections.generic;using system.linq;using system.text;using System.Web;using         System.web.mvc;using app.common;using app.models.sys;namespace app.admin{public class Basecontroller:controller {        <summary>///get current User ID//</summary>//<returns></returns>  public string GetUserId () {if (session[' account ']! = null) {Accountmodel                info = (Accountmodel) session["account"]; return info.            Id;            } else {return ""; }}///<summary>//Get current user name////</summary>//<returns></ret                Urns> public String Getusertruename () {if (session["Account"]! = null) {                Accountmodel info = (Accountmodel) session["account"]; return info.            Truename;        } else    {return ""; }}///<summary>//Get current User information///</summary>//<returns> user Information </r                Eturns> public Accountmodel Getaccount () {if (session[' account ']! = null) {            Return (Accountmodel) session["account";        } return null;  } protected override Jsonresult Json (object data, String ContentType, Encoding contentencoding, Jsonrequestbehavior Behavior) {return new Tojsonresult {data = data, Contentenco                Ding = contentencoding, ContentType = ContentType, Jsonrequestbehavior = behavior,        Formatestr = "Yyyy-mm-dd HH:mm:ss"}; }///<summary>//return jsonresult.24//</summary>/<param name= "Data" > number According to </param>//<param name= "behavior" > Behavior </param&Gt <param format for datetime types in name= "format" >json </param>///<returns>Json</returns> Prot ected jsonresult Myjson (object data, jsonrequestbehavior behavior, string format) {return new tojsonres ult {data = data, Jsonrequestbehavior = behavior, formatestr = fo        Rmat}; }///<summary>//return JSONRESULT42//</summary>/<param name= "Data" >        </param>//<param name= "format" > Data format </param>//<returns>Json</returns>                Protected Jsonresult Myjson (object data, string format) {return new Tojsonresult {        data = data, FORMATESTR = format}; }///<summary>///Check the legality of SQL statements///</summary>//<param name= "SQL" ></par am>//<returns&Gt;</returns> public bool Validatesql (String sql, ref string msg) {if (SQL. ToLower ().                IndexOf ("delete") > 0) {msg = "Query parameter contains illegal statement delete";            return false; } if (SQL. ToLower ().                IndexOf ("Update") > 0) {msg = "Query parameter contains illegal statement update";            return false; } if (SQL. ToLower ().                IndexOf ("Insert") > 0) {msg = "The query parameter contains an illegal statement insert";            return false;        } return true; }    }}

Well, we run, in fact, that's what happened!


5. Our BLL is going to be instantiated every time. Dbcontainer db = new Dbcontainer (); Repeat, should we write a BASEBLL base class class inheritance

I have been separated and the source is brought out.
6. We have a lot of tips on the front end is the same, should not be encapsulated, such as click: Details when not selected Prompt "Please select the record to operate"

Add the following classes to the App.common suggestion

View Code

Using in a view

$ ("#btnDelete"). Click (function () {            var row = $ (' #List '). DataGrid (' getselected ');            if (row! = null) {                $.messager.confirm (' Hint ', ' @Suggestion. Youwanttodeletetheselectedrecords ', function (r) {                        if (r) {                            $.post ("/syssample/delete?id=" + row. Id, function (data) {                                if (Data.type = = 1)                                    $ ("#List"). DataGrid (' Load ');                                $.messagebox5s (' hint ', data.message);                            }, "json");                        }                    );                else {$.messagebox5s (' hint ', ' @Suggestion. plasechoosetooperatingrecords ');}            });

@Suggestion. Plasechoosetooperatingrecords '

7. Toolbar add, Delete, change button like every time you paste the code also a lot, we should extend the htmlhelper of MVC, and then we @html. It came out. More convenient, later also used for permission control

This must return mvchtmlstring and introduce namespaces in the view. Create a new class in the core folder of App.admin extendmvchtml

and add the following code

View Code

and use it in the view, using the example!

@Html. Toolbutton ("Btnquery", "Icon-search", "Query", True) @Html. Toolbutton ("Btncreate", "Icon-add", "new", True) @ Html.toolbutton ("Btnedit", "Icon-edit", "edit", True) @Html. Toolbutton ("Btndetails", "Icon-details", "verbose", True) @ Html.toolbutton ("Btndelete", "Icon-remove", "delete", true) @Html. Toolbutton ("Btnexport", "Icon-export", "Export", true)

Build a back-end management system for ASP.-easyui defect Repair and extension in mvc4+ef5+easyui+unity2.x

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.