var t = document.querySelector("table"); var banks = {}, bankInfo = null; for (var i = 0; i < t.rows.length; i++) { var trElement = t.rows[i]; var binCode; if (trElement.cells.length == 3) { var bankName = trElement.cells[0].innerText.trim(); binCode = trElement.cells[2].innerText.trim(); bankInfo = { name: bankName, binCodes: binCode }; banks[bankName] = bankInfo; } else { binCode = trElement.cells[trElement.cells.length - 1].innerText.trim(); bankInfo.binCodes = bankInfo.binCodes + "," + binCode; } } console.info(banks)
前台代码
var listCode = [{ "name": "中国工商银行", "binCodes": "620302,620402,620403,620404,620406,620407,620409,620410,620411,620412,620502,620503,620405,620408,620512,620602,620604,620607,620611,620612,620704,620706,620707,620708,620709,620710,620609,620712,620713,620714,620802,620711,620904,620905,621001,620902,621103,621105,621106,621107,621102,621203,621204,621205,621206,621207,621208,621209,621210,621302,621303,621202,621305,621306,621307,621309,621311,621313,621211,621315,621404,621405,621406,621407,621408,621409,621410,621502,621317,621511,621602,621603,621604,621605,621608,621609,621610,621611,621612,621613,621614,621615,621616,621617,621607,621606,621804,621807,621813,621814,621817,621901,621904,621905,621906,621907,621908,621909,621910,621911,621912,621913,621915,622002,621903,622004,622005,622006,622007,622008,622010,622011,622012,621914,622015,622016,622003,622018,622019,622020,622102,622103,620200,622013,622111,622114,622017,622110,622303,622304,622305,622306,622307,622308,622309,622314,622315,622317,622302,622402,622403,622404,622313,622504,622505,622509,622513,622517,622502,622604,622605,622606,622510,622703,622715,622806,622902,622903,622706,621304,621402,623008,623011,623012,622904,623015,623100,623202,623301,623400,623500,623602,623803,623901,623014,624100,624200,624301,624402,623700,624000,622104,622105,623002,623006,623062,621376,621423,621428,621434,621761,621749,621300,621378,621379,621720,621762,621240,621724,621371,621414,621375,621734,621433,621370,621733,621732,621764,621372,621765,621369,621750,621377,621367,621374,621781,625929,625927,625930,625114,625021,625022,622159,625932,625931,625113,625914,625928,625986,625925,625921,625926,625917,622158,625922,625933,625920,625924,620054,620142,620114,620146,620143,620149,620187,620124,620183,620094,620186,620046,620148,620185,427018,427020,427029,427030,427039,438125,427062,427064,622202,622203,622926,622927,622928,622210,622211,622212,622213,622214,526836,513685,543098,458441,402791,427028,427038,548259,622200,621722,621723,621721,356879,356880,356881,356882,62451804,62451810,62451811,62458071,451804,451810,451811,458071,622231,622232,622233,622234,622929,622930,622931,528856,524374,550213,622237,622239,622238,622223,622229,622224,489734,489735,489736,530970,530990,558360,370249,370246,370248,625330,625331,625332,621558,621559,625916,625915,427010,427019,374738,374739,544210,548943,621225,621226,6245806,6253098,45806,53098,625939,625987,622944,622949,625900,622889,625019,628286,622235,622230,622245,622240,621730,621288,621731,620030,621763,625934,524091,525498,622236,625018,622208,621227,438126,622206,9558,900010,900000,524047,510529,370267,370247,625017,621670,621618,620058,622171,620516,620086,628288,621281,622246,622215,622225,622220" }, { "name": "中国银行", "binCodes": "621294,621293,621342,621343,621394,621364,621648,621248,621249,621638,621334,621395,524865,525745,525746,524864,622759,622761,622762,622763,622752,622753,622755,622757,622758,622756,622754,512315,512316,512411,512412,514957,558868,514958,518378,518379,518474,518475,518476,547766,620026,620025,620531,620019,620035,409672,552742,553131,622771,622770,622772,409668,409669,409667,625141,625143,620211,620210,621661,409666,621787,621785,622751,622750,621756,621757,621330,621331,621758,621759,621332,621333,621663,409665,456351,601382,620202,620203,625908,625907,625909,625906,625910,625905,625040,625042,622789,622788,622480,621212,620514,409670,621662,621297,621741,623040,621788,621786,621790,621789,621215,621725,621666,621668,621667,621669,621660,621672,622346,625055,558869,621231,621620,622347,622479,621256,622274,628388,620061,622760,621041,622273,377677,621665,622765,622764,621568,621569,620513,620040,625140,628313,628312,623208,356833,356835,438088,622348,625333,518377,409671,625145,621283" }, { "name": "中国建设银行", "binCodes": "5453242,5491031,553242,5544033,524094,526410,53243,436738,558895,552801,622675,622676,622677,621082,621083,434062,552245,621466,622966,621499,622988,628316,628317,625363,625362,53242,489592,491031,453242,621488,621598,621487,621081,589970,621084,434061,421349,625966,625965,625964,356899,356896,356895,436742,622700,436718,531693,532458,436748,532450,436745,436728,622708,622168,622166,621700,557080,544887,559051,628366,628266,622725,622728,622382,622381,621467,621621,620060,622280,621080,620107,621284,544033,622707,625956,625955" }, { "name": "上海浦东发展银行", "binCodes": "84301,84336,622500,84373,84385,84390,87000,87010,87030,87040,84380,984301,984303,84361,87050,84342,625957,625958,625970,622522,622523,622521,622516,622518,622176,622177,498451,620530,622519,621791,622517,622520,628222,628221,356852,356851,356850,622276,377187,515672,517650,525998,456418,622228,622277,621795,621793,621352,621792,621390,621796,404739,404738,621351,625971,625993" }, { "name": "招商银行", "binCodes": "356885,356886,356887,356888,356890,439188,479228,479229,356889,552534,552587,622575,622576,622577,622578,622579,622581,622582,545620,545621,545947,545948,545619,545623,410062,468203,512425,524011,622580,622588,95555,439225,439226,625802,625803,690755,690755,518718,518710,439227,620520,622598,622609,621286,402658,370286,370285,370289,370287,521302,621299,621485,621483,628262,628362,621486" }, { "name": "中信银行", "binCodes": "518212,556617,558916,433666,520108,403393,514906,433669,433668,433667,404157,404174,404173,404172,400360,403391,403392,404158,404159,404171,621773,621767,621768,621770,621772,622689,622688,622680,622679,622678,356392,356391,356390,376968,376969,376966,433670,433671,433680,968807,968808,968809,628208,628209,628206,442729,442730,622690,622691,622998,622999,621771,620082,622692,622698,622696" }, { "name": "中国光大银行", "binCodes": "622663,622664,622665,622666,622667,622669,622670,622671,622672,622668,622661,622674,90030,622673,622660,622662,356837,356838,356839,356840,486497,425862,625978,625980,625979,625981,625977,625976,625975,628201,628202,406254,406252,622655,620518,621489,621492,303,481699,524090,543159,620085,622161,622570,622650,622658,622685,622659,622687,622657" }, { "name": "中国民生银行", "binCodes": "407405,421869,421870,421871,512466,528948,552288,517636,556610,545392,545393,545431,545447,622617,622622,622615,622619,472067,421393,472068,622600,622601,628258,464580,356858,356857,356856,356859,464581,427571,427570,421865,415599,553161,545217,523952,622602,622621,622616,622603,377155,377153,377152,377158,622620,622623,625913,625912,625911,622618" }, { "name": "广东发展银行", "binCodes": "428911,436768,436769,436770,491032,491033,491034,491035,491036,491037,491038,436771,518364,541709,541710,548844,493427,520152,520382,552794,528931,685800,558894,406365,487013,406366,6858000,6858001,6858009,625072,625809,625071,625808,9111,622568,622558,622555,622556,622557,622559,622560,621462,625810,628260,628259,625807,625806,625805" }, { "name": "交通银行", "binCodes": "458123,458124,520169,552853,521899,955593,955592,955591,955590,622258,622259,622261,622260,622250,622251,622253,622252,6653783,49104,53783,6649104,622254,622255,622256,622257,625029,625028,434910,522964,601428,66601428,622656,620013,620021,621069,628218,628216,622262,620521,621436,622284,66405512,405512,621335,621002" }, { "name": "平安银行", "binCodes": "526855,622156,622155,528020,622157,531659,412962,412963,998802,998801,415753,415752,622989,622986,435745,435744,356869,356868,483536,998800,622538,620010,622536,622539,622535,622983,623058,625361,625360,622525,622526,622298,602907,621626,627068,627067,627066,627069" }, { "name": "兴业银行", "binCodes": "549633,552398,548738,625087,625086,625085,625082,625083,625084,451290,451289,524070,523036,622902,622901,461982,486494,486493,486861,528057,527414,90592,622909,966666,625962,625961,625960,625963,438589,438588,622908,622922,628212" }, { "name": "上海银行", "binCodes": "356827,486466,402674,402673,356828,622268,622269,622148,520131,519498,622149,356830,622267,625953,621050,356829,628230,622279,622278,438600,625099,622468,622892,622987,622985,620522,524031,548838,622300,940021,622172" }, { "name": "中国农业银行", "binCodes": "95595,95596,95597,95598,95599,622840,622844,622847,622848,622845,622826,622827,622841,103,622824,622825,622823,622846,622843,622849,622821,622822,621671,620501,622828,621619,620059,623018,623206,621282,621336" }, { "name": "中国邮政储蓄银行", "binCodes": "62215049,62215050,62215051,62218850,62218851,62218849,622150,622151,622188,622199,621096,621098,622810,622811,621797,621799,621798,620529,621599,955100,621095,622181,621674,625919,621622,622812,628310,620062,623219,623218,621285" }, { "name": "华夏银行", "binCodes": "621222,623022,622638,625969,625968,625967,622630,999999,539867,539868,528709,528708,628318,623021,622632,623020,523959,622633,622637,622636,622631,623023" }, { "name": "北京银行", "binCodes": "621468,621420,421317,621030,622163,622853,622851,602969,422161,422160,522001,628203,622852" }, { "name": "江苏银行", "binCodes": "622876,622131,621579,621076,622422,625902,504923,940076,622447,622173,622283,628210" }, { "name": "龙江银行", "binCodes": "621037,621588,625588,628333,622475,622644,625090,621097,622977,622270,628368,622860" }, { "name": "宁波银行", "binCodes": "622778,622282,625903,628207,512431,520194,622281,621418,622316,622318,940022,621279" }, { "name": "长沙银行", "binCodes": "622900,622898,621446,694301,940071,622368,628282,628283,628281,620519,625901,622806" }, { "name": "徽商银行", "binCodes": "622651,622877,622879,603601,622137,622327,622340,622366,623203,621775,628251" }, { "name": "浙商银行", "binCodes": "621019,622309,6223091100,6223092900,6223093370,6223097910,6223093310,6223093320,6223093330,6223093380,6223096510" }, { "name": "汉口银行", "binCodes": "625946,622566,622567,623029,623105,628200,622325,990027,622626,622625" }, { "name": "北京农商银行", "binCodes": "625186,621560,625526,628336,621066,621068,622138,620088" }, { "name": "福建省农村信用社联合社", "binCodes": "621251,622290,621589,621701,622127,622184,628232,622802" }, { "name": "哈尔滨银行", "binCodes": "621577,622425,622425,940049,622809,625577,628224,621752" }, { "name": "宁夏银行", "binCodes": "623200,628214,625529,621417,623089,622428,622429,621529" }, { "name": "重庆农村商业银行", "binCodes": "622867,622885,940020,621258,621528,621465,622218,628267" }, { "name": "大连银行", "binCodes": "603708,622993,623069,623070,622383,622385,628299" }, { "name": "江苏省农村信用社联合社", "binCodes": "622452,622324,621578,623066,622815,622816,628226" }, { "name": "南京银行", "binCodes": "622303,628242,622595,622305,621259,622596,621777" }, { "name": "包商银行", "binCodes": "622336,622165,622315,625950,628295,621760" }, { "name": "常熟农商银行", "binCodes": "622462,628272,625101,603694,9400301,622323" }, { "name": "广州银行", "binCodes": "603445,621463,940016,622467,628367,625050" }, { "name": "河北银行", "binCodes": "623000,622921,628321,622498,622499,940046" }, { "name": "吉林银行", "binCodes": "940012,622865,622440,940047,622178,622179" }, { "name": "青海银行", "binCodes": "940068,622310,622817,62536601,625959,628287" }, { "name": "台州银行", "binCodes": "622321,625001,628273,940069,623039,622427" }, { "name": "乌鲁木齐市商业银行", "binCodes": "628278,622476,621751,621754,622143,940001" }, { "name": "重庆银行", "binCodes": "628220,622613,9896,623016,622134,940018" }, { "name": "广州农商银行", "binCodes": "909810,621522,940035,622439,625080" }, { "name": "杭州银行", "binCodes": "622878,603367,603367,622286,628236" }, { "name": "兰州银行", "binCodes": "621538,621242,940040,622139,628263" }, { "name": "柳州银行", "binCodes": "621412,622292,622291,622880,622881" }, { "name": "宁波鄞州农村合作银行", "binCodes": "620500,621024,622289,622389,628300" }, { "name": "青岛银行", "binCodes": "621252,621419,940061,622146,628239" }, { "name": "厦门银行", "binCodes": "622393,6886592,621600,623019,940023" }, { "name": "上海农商银行", "binCodes": "622611,622722,628211,625500,625989" }, { "name": "绍兴银行", "binCodes": "622486,603602,623026,623086,628291" }, { "name": "顺德农商银行", "binCodes": "625088,628322,985262,622322,940038" }, { "name": "天津银行", "binCodes": "6091201,622331,622426,628205,940015" }, { "name": "浙江民泰商业银行", "binCodes": "621726,620517,621088,622740,625036" }, { "name": "沧州银行", "binCodes": "621266,62249804,94004604,621422" }, { "name": "东莞农村商业银行", "binCodes": "625288,940062,622328,623038" }, { "name": "东莞银行", "binCodes": "940050,623010,621439,622888" }, { "name": "福建海峡银行", "binCodes": "622388,623063,620043,621267" }, { "name": "贵阳银行", "binCodes": "622133,621735,888,628213" }, { "name": "湖北省农村信用社联合社", "binCodes": "622412,621013,621523,623055" }, { "name": "南昌银行", "binCodes": "621269,940006,622275,628305" }, { "name": "天津农商银行", "binCodes": "622531,622329,622829,628301" }, { "name": "温州银行", "binCodes": "621977,628255,622899,622868" }, { "name": "浙江泰隆商业银行", "binCodes": "622287,622565,628275,622717" }, { "name": "安徽省农村信用社联合社", "binCodes": "622953,621778,621526" }, { "name": "渤海银行", "binCodes": "621268,622684,622884" }, { "name": "德阳银行", "binCodes": "622561,622563,622562" }, { "name": "赣州银行", "binCodes": "940073,622967,628233" }, { "name": "海南省农村信用社联合社", "binCodes": "621036,621536,621458" }, { "name": "锦州银行", "binCodes": "940003,622990,628261" }, { "name": "晋商银行", "binCodes": "940031,621216,622465" }, { "name": "商丘银行", "binCodes": "621337,621748,628271" }, { "name": "上饶银行", "binCodes": "621014,628223,621416" }, { "name": "深圳农村商业银行", "binCodes": "622129,622128,623035" }, { "name": "苏州银行", "binCodes": "603506,622855,621461" }, { "name": "潍坊银行", "binCodes": "622391,940072,628391" }, { "name": "吴江农村商业银行", "binCodes": "622648,628248,622488" }, { "name": "郑州银行", "binCodes": "622421,96828,940056" }, { "name": "鞍山银行", "binCodes": "940002,622413" }, { "name": "承德银行", "binCodes": "622936,628229" }, { "name": "德州银行", "binCodes": "622937,628397" }, { "name": "东营银行", "binCodes": "621004,628217" }, { "name": "鄂尔多斯银行", "binCodes": "628253,622978" }, { "name": "广西北部湾银行", "binCodes": "628227,623001" }, { "name": "恒丰银行", "binCodes": "622384,940034" }, { "name": "葫芦岛银行", "binCodes": "940054,622398" }, { "name": "湖州银行", "binCodes": "622301,628306" }, { "name": "黄河农村商业银行", "binCodes": "622947,621561" }, { "name": "昆仑银行", "binCodes": "621029,621766" }, { "name": "昆山农村商业银行", "binCodes": "940029,622443" }, { "name": "辽阳银行", "binCodes": "940043,622399" }, { "name": "洛阳银行", "binCodes": "940041,622420" }, { "name": "漯河银行", "binCodes": "621075,623037" }, { "name": "内蒙古银行", "binCodes": "622147,628252" }, { "name": "齐商银行", "binCodes": "940057,622311" }, { "name": "日照银行", "binCodes": "622857,940065" }, { "name": "泰安市商业银行", "binCodes": "622972,623196" }, { "name": "威海市商业银行", "binCodes": "622411,628234" }, { "name": "邢台银行", "binCodes": "621238,620528" }, { "name": "云南省农村信用社联合社", "binCodes": "622469,628307" }, { "name": "张家港农村商业银行", "binCodes": "622332,940063" }, { "name": "张家口市商业银行", "binCodes": "622982,621413" }, { "name": "浙江稠州商业银行", "binCodes": "621028,628250" }, { "name": "阜新银行", "binCodes": "622126" }, { "name": "富滇银行", "binCodes": "628231" }, { "name": "广西农村信用社联合社", "binCodes": "622992" }, { "name": "邯郸银行", "binCodes": "622960" }, { "name": "韩亚银行(中国)", "binCodes": "621201" }, { "name": "济宁银行", "binCodes": "621200" }, { "name": "晋城银行", "binCodes": "622532" }, { "name": "莱商银行", "binCodes": "628279" }, { "name": "临商银行", "binCodes": "628359" }, { "name": "绵阳市商业银行", "binCodes": "622367" }, { "name": "南阳银行", "binCodes": "621392" }, { "name": "攀枝花市商业银行", "binCodes": "622342" }, { "name": "企业银行(中国)", "binCodes": "621651" }, { "name": "新韩银行", "binCodes": "621072" }, { "name": "烟台银行", "binCodes": "622886" }, { "name": "营口银行", "binCodes": "622400" }, { "name": "高要农村信用社", "binCodes": "622510" }, { "name": "高要农村信用社", "binCodes": "622477" }, { "name": "高要农村信用社", "binCodes": "622509" }, { "name": "佛山市禅城区农村信用合作联社", "binCodes": "622302" }, { "name": "珠海农商银行", "binCodes": "622859" }, { "name": "新会农村商业银行", "binCodes": "622470" }, { "name": "中山市农村信用合作联社", "binCodes": "622362" }, { "name": "中山市农村信用合作联社", "binCodes": "621518" }, { "name": "中山市农村信用合作联社", "binCodes": "621018" }]; $(function () { $.ajax({ url: "/Home/PostBank", type: "post", data: JSON.stringify(listCode), contentType: \'application/json; charset=utf-8\', success: function (d) { } }) })
后台代码插入数据库中
[HttpPost] public JsonResult PostBank(List<BankBinCode> listCode) { int bankCode = 507; string connectionStr = "server=192.168.0.116;database=KLB_CarPayment;uid=sa;pwd=abc123!@#"; using (SqlConnection connection=new SqlConnection()) { connection.ConnectionString = connectionStr; using (SqlCommand command = new SqlCommand()) { command.Connection = connection; connection.Open(); foreach (var code in listCode) { command.CommandText = "update PartnerBank set BinCodes=@BinCodes where BankName=@BankName and BinCodes is null"; command.Parameters.Clear(); command.Parameters.Add(new SqlParameter {Value=code.binCodes,ParameterName= "@BinCodes" }); command.Parameters.Add(new SqlParameter { Value = code.name, ParameterName = "@BankName" }); int n=command.ExecuteNonQuery(); if (n == 0) { command.Parameters.Clear(); command.CommandText = @"if (select 1 from PartnerBank where BankName=@BankName)>0 print 1 else insert into PartnerBank (BankCode,BankName,BinCodes,Status) values (@BankCode,@BankName,@BinCodes,1)"; command.Parameters.Add(new SqlParameter { Value = code.binCodes, ParameterName = "@BinCodes" }); command.Parameters.Add(new SqlParameter { Value = code.name, ParameterName = "@BankName" }); command.Parameters.Add(new SqlParameter { Value = bankCode, ParameterName = "@BankCode" }); if (command.ExecuteNonQuery() > 0) { bankCode++; } } } } } return Json(new { }); }