ASP.NET implements credit card check and custom confirmation control (2)

zhaozj2021-02-16  53

ASP.NET implements credit card check and custom confirmation control (2)

Welcome to the second part. I realized that if you have finished writing these code more modular to you will be more helpful. I said that modular means: don't have to copy, paste the same code each time The simpler solution is to build a custom control inherited .NET server control function. This not only makes us customize some events we want, but also uses powerful features in the inheritance control. Let's come Establish a credit card authentication control. First we need to inherit the function of BasevaliDator's. Of course you can write it yourself, but isn't it a strict custom control, not? Not only this, you will take you a lot of time. So use ready-made things More cost-effective to us. Now let's get started. First, we build a class file that contains our control functions.

Pre.Showcode {Background-Color: #fffffff; Padding-Right: 3px; Border: 0px; font-size: 11px; padding-bottom: 0px; padding-top: 0px; font-family: "Courier new"; ColorLineNumber {color: red;} .DefaultFontFace {color: arial;} .DefaultFontSize {size: 3;} .ColorBackGroundLine {color: #EEEECC;} .ColorAlternatingBackGroundLine {color: #FFFFEE;} .ColorComment {color: green;}. ColorServerSideTag {color: green;} .ColorDataBinding {color: dodgerblue;} .ColorControlTag {color: maroon;} .ColorAspTemplateTag {color: green;} .ColorStartHtmlTag {color: blue;} .ColorEndHtmlTag {color: blue;} .ColorVBKeyword { color: blue;} .ColorVBComment {color: green;} .ColorCSKeyword {color: blue;} .ColorSQLKeyword {color: blue;} .ColorCSComment {color: green;} .ColorSQLComment {color: green;} .ColorSQLFunctions {color: Maroon;} .colorsqldatatypes {color: green;} 1: using system; 2: use system.Web.ui; 3: using system.web.ui.webcontrols; 4: 5: Namespace CustomValidators6: {7: /// < Summary> 8: // / Summary description for class1.9: /// 10: 11: // - From the BaseValidator class, it can be found to be found in the base class. 12: Public class CreditcardValidator: basevaliDator13: {14: protected override Bool evataSvalid () 15: {16: // Trink the control of the Validation control to valuetovalidate.17: string valueetovalidate = this.getControlValidationValue (this.ControlTovAlidate; 18: int indeicator = 1; // One-digit tag 19: int firstnumToadd = 0; // - Used to store the first set of numbers and 20: int secondnumToadd = 0; // - Used to store the second set of numbers and 21: String Num1; // - Used to store the leftmost integer 22: 23: String Num2 when each one is added and greater than 10

// - Used to save the rightmost integer 24: 25: 25: 25: char number 27: char []: Credit card number string is converted to a character array 27: char [] Ccarr = valuetovalidate.tochararray (); 28: 29: for (int i = ccarr.length-1; i> = 0; i -) 30: {31: char ccnoadd = ccarr [i]; 32: int CCADD = INT32.PARS (ccNoadd.toString ()); 33: if (Indicator == 1) 34: {35: // - Add it to the gross value when we encounter odd bits 36: firstnumToadd = CCADD ; 37: // - Set the tag to 0 so that the next cycle skips this block 38: Indicator = 0; 39:} 40: Else41: {42: // - If the current integer is multiplied by 2 10, will be divided into two integers and add them, 43: // - Add value to the total value. 44: 45: IF ((CCADD CCADD)> = 10) 46: {47: int Temporary = (CCADD CCADD); 48: Num1 = Temporary.toString (). Substring (0, 1); 49: Num2 = Temporary.toString (). Substring (1, 1); 50: SecondNumToadd = (Convert.Toint 32 (Num1) Convert.Toint32 (Num2)); 51:} 52: Else53: {54: // - Otherwise, add them, add value to the total value .55 : Secondnum ToAdd = CCADD CCADD; 56:} 57: // - // - Set the tag to 1, we can perform different code to the next integer 58: 59: indeicator = 1; 60:} 61: } 62: // - If the two numbers are 10, then the card is effective, otherwise, invalid. 63: 64: bool isvalid = false; 65: if ((FirstnumToadd SECondNumToadd)% 10 == 0 66: {67: isvalid = true; 68:} 69: Else70: {71: isvalid = false; 72:} 73: Return isvalid;

74:} 75:} 76:} 77: Next, save it to validator.cs in your project folder. Now, in order to use it, we can build it into a DLL. Do this you can build a batch Processing file (.bat), you can also open the Windows command line to enter the following characters: CSC / Target: library /out:c:/inetpub/wwwroot/bin/Validator.dll * .cs /R :system.dll ,system.Web .dll has a DLL file you might use this control. Just open a editor you like, enter the following code:

转载请注明原文地址:https://www.9cbs.com/read-23623.html

New Post(0)