MemberImportExcel.cs 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. namespace LYFZ.Software.MainBusiness.MembershipManage.SetSmallForm
  11. {
  12. public partial class MemberImportExcel : LYFZ.Software.UI.MembershipManage.SetSmallForm.MemberImportExcel
  13. {
  14. LYFZ.BLL.BLL_ErpCustomer ctbll = new BLL.BLL_ErpCustomer();
  15. LYFZ.BLL.BLL_ErpMemberCard mcbll = new BLL.BLL_ErpMemberCard();
  16. LYFZ.BLL.BLL_ErpCustomerGroup ctgpbll = new BLL.BLL_ErpCustomerGroup();
  17. LYFZ.BLL.BLL_ErpSystemConfigure sgbll = new BLL.BLL_ErpSystemConfigure();
  18. LYFZ.BLL.BLL_ErpMemberCardPoints mcpsbll = new BLL.BLL_ErpMemberCardPoints();
  19. LYFZ.BLL.BLL_ErpMemberCardDiscount mcdtbll = new BLL.BLL_ErpMemberCardDiscount();
  20. LYFZ.BLL.BLL_ErpMemberCardViceCard mcvcbll = new BLL.BLL_ErpMemberCardViceCard();
  21. LYFZ.BLL.BLL_ErpCustomerGroupMembers ctgmbll = new BLL.BLL_ErpCustomerGroupMembers();
  22. public MemberImportExcel()
  23. {
  24. this.Load += MemberImportExcel_Load;
  25. this.btnOpenExcel.Click += btnOpenExcel_Click;
  26. this.btnOpenPointsViceCard.Click += btnOpenPointsViceCard_Click;
  27. this.btnOpenBackCashViceCard.Click += btnOpenBackCashViceCard_Click;
  28. this.btnSaveed.Click += btnSaveed_Click;
  29. this.btnDelete.Click += btnDelete_Click;
  30. this.btnCancel.Click += btnCancel_Click;
  31. this.dgvData.RowsAdded += dgvData_RowsAdded;
  32. this.btnExport.Click += btnExport_Click;
  33. }
  34. void btnExport_Click(object sender, EventArgs e)
  35. {
  36. string[] strArray = "'*','0','0.00','00','00.','000002','000003','000005','000006','000008','000009','000011','000012','000013','000015','000016','000018','000020','000021','000026','000029','000030','000033','000035','000036','000038','000039','00005','000050','000052','000055','000058','000059','000061','000062','000065','000066','000068','000069','000080','000082','000083','000085','000090','000092','000093','000098','00010','000101','000102','0001026','000103','000105','000106','000108','000109','000110','000111','000112','000113','000115','000116','000119','00012','000120','000123','0001238','000126','0001266','000128','000130','000131','000132','000133','000135','000136','000138','000150','000151','000152','000153','000156','000158','000159','000160','000161','000162','000165','000166','000169','000180','000181','0001813','000182','000183','000185','000186','0001888','000190','000191','000192','000193','0002','000202','000203','000208','000209','000211','000212','000213','000215','000216','000219','000220','000222','000225','000226','000228','000229','000231','000232','000235','000238','000239','00025','000250','000251','000253','000258','000259','000260','000261','000263','000265','000268','000269','000280','000281','000282','000283','000286','000288','000289','000292','000293','000296','000298','000299','000300','000301','000305','000306','000309','000310','000311','000312','000313','000315','000316','000318','000322','000323','000325','000326','000329','000330','000332','000333','000335','000336','000338','000339','000351','000360','000362','000365','000381','000385','000390','000393','000395','000396','000501','000502','000508','000509','000510','000511','000513','000515','000516','000518','000539','000552','000553','000556','000562','000563','000565','000566','000568','000581','000583','000588','000592','000593','000608','00061','000612','000615','000616','000619','000623','000626','000628','000630','000631','000632','000633','000638','000650','000652','000656','000658','000659','000661','000665','000668','000669','000681','000682','000683','000685','000686','000688','000689','000690','000691','000692','000693','000695','000696','000698','000802','000803','000806','000808','000809','000810','000815','000816','000818','000819','000821','000822','000823','000826','000829','000831','000835','000836','000839','000853','000855','000858','000860','000861','000862','000863','000865','000866','000868','000886','000890','000891','000893','000895','000896','000898','000900','000901','000902','000903','000905','000908','000909','000910','000911','000912','000915','000916','000920','000923','000938','00095','000950','000951','000953','000958','00096','000960','000965','000968','000980','000981','000982','000983','000985','000986','000988','000989','000990','000991','000993','000995','000996','000999','001','0010','001000','0010003','001001','001003','001005','001008','001009','001010','001012','001016','001018','001020','001021','001023','001025','001026','001029','001030','001032','001033','001035','001036','001039','001050','001061','001062','001063','001068','001069','001080','001085','001086','001088','001089','001090','001091','001092','001095','001098','001099','0011','001100','001101','001103','001105','001106','0011060','001108','001109','001110','001111','001113','001118','001120','001121','001122','001123','001125','001126','001131','001133','001135','001139','001152','001156','001160','001162','001163','001165','001168','001180','001181','001182','001183','001185','001186','001188','001189','001192','0011933','001195','001196','001198','001200','001201','001203','001205','001206','001208','001209','001213','001215','001216','001220','001221','001222','001229','001232','001233','001235','001238','001239','00125','001253','001255','001256','001260','001261','001262','001263','001269','001280','001282','001285','001286','001291','001292','001293','001295','001298','001301','001305','001306','001308','001312','001318','001321','001322','001323','001325','001338','001352','001353','001355','001356','001359','001360','001361','001362','001363','001366','001380','001381','001382','001383','001385','001386','001390','001391','001395','001396','001398','001399','001501','001502','001506','001508','001509','001511','001515','001518','001519','001520','001523','001525','001526','001529','001530','001531','001532','001533','001536','001539','001552','001553','001555','001556','001559','001561','001562','001563','001566','001568','001569','001580','001581','001582','001585','001586','001589','00159','001590','001591','001595','001596','001598','001599','001600','001602','001603','001605','001606','001608','001609','001611','001612','001615','001618','001621','001622','001626','001628','001629','001630','001635','001636','001650','001651','001652','001653','001655','001656','001658','001659','001661','0016610','001662','001665','001666','001668','001681','001682','001683','001686','001689','001690','001691','001692','001695','001698','001800','001806','001810','001812','001815','001816','001818','001819','001820','001821','001823','001825','001829','001831','001832','001833','001836','001839','001850','001851','001852','001855','001888','001889','001890','001891','001893','001895','001896','001899','001900','001901','001902','001903','001905','001906','001908','001909','001912','001920','001921','001930','001935','001936','001939','001950','001951','001953','001955','002','0020','00213','0023','00241','00350','0036','00391','004','00560','006','008','009','00910','0112','013','014','015','016','017','0170','018','019','02','020','021','022','023','024','026','027','028','029','03','030','031','032','0320','0328','034','035','036','0368','050','0569','0633','0820','0832','0833','0838','0851','0856','0858','0880','0888','0892','1','1019','10305','1109','111328','112455','1166','1169','1193','12','1202','1211','1221','1223','1230','1231','123456','1281','1288','13','13028577008','13098049309','13098051661','13098051666','13098075556','13098090777','13119201123','13119203966','13119230111','13119242555','13119252333','13119290321','13220010077','13220065613','13239188366','13239188888','13239227999','13244115333','13244198885','13259323130','13279112211','13309111418','13325313322','13359115777','13359116264','13369269875','13369280321','13369281933','13369285665','13369294010','13379114933','13379532009','13379539911','13379559821','13389117427','13391163631','13402900110','13402903965','13402904847','13402905187','13402905680','13409110316','13409110963','13409111942','13409112216','13409112412','13409114652','13409114662','13409117467','13409117543','13409118467','13429713154','13468543515','13468548121','13468580150','13468590140','13468592723','13468596355','13468596533','13468861341','13468863746','13468870635','13468871299','13468872240','13468873122','13468873689','13468877793','13468879775','13468961271','13468969626','13474340200','13474342844','13474345729','13474380899','13474384448','13474385070','13474404237','13474410790','13474411691','13474412223','13474412301','13474416140','13474419640','13474419662','13474419777','13474424222','13474425583','13474427796','13474427844','13474433611','13474435522','13474435533','13474437076','13474565658','13474568785','13474568885','13474570840','13474572264','13474573457','13474573493','13474574433','13484411136','13484411377','13484411456','13484411557','13484412345','13484416109','13484418387','13484643493','13484647093','13484658178','13484659442','13484659521','13484659722','13484685067','13484688265','13484965265','13484967899','13484969329','13484971265','13484973036','13484976971','13484977868','13488240225','13488245428','13488247265','13488249559','13488249735','13488254099','13488257520.','13488257854','13488258940','13488259936','13488280435','13488281602','13488288484','13488289574','13488373979','13488414221','13488416589','13488419026','13494569902','13509110342','13509111173','13509112378','13509114802','13509116574','13509117197','13571103141','13571103354','13571110766','13571112522','13571113177','13571113329','13571114377','13571117593','13571118634','13571121727','13571125398','13571126774','13571127565','13571131141','13571136171','13571137833','13571138066','13571138488','13571139937','13571142769','13571143995','13571144695','13571145020','13571145649','13571147877','13571149402','13571149444','13571151141','13571151823','13571157799','13571159060','13571159351','13572633343','13619111677','13619112191','13619114450','13619115070','13619116264','13619116591','13619117416','13619117647','13619119694','13629116560','13629211166','13629218041','13630240657','13630240790','13630242724','13630245032','13630245166','13630247875','13630249465','13636721034','13636722938','13636722939','13636723248','13636863494','13636868388','13636868412','13636872057','13636875774','13636877480','13636878367','13636878642','13639210548','13649113535','13649115986','13649116967','13649119764','13669115014','13669116338','13679112507','13689211618','13689217792','13698641569','13729344440','13772250512','13772258193','13772268994','13772275334','13772277174','13772278246','13772283335','13772288731','13772290267','13772292994','13772858144','13772862785','13772871807','13772878105','13772878756','13772880515','13772882375','13772886726','13772887557','13772888675','13772889089','13772891273','13772893633','13772895196','13772897110','13809110724','13809111047','13809115263','13809115306','13809116100','13891100424','13891100737','13891102001','13891102059','13891104737','13891111834','13891113447','13891113642','13891116006','13891120395','13891120815','13891124240','13891125435','13891129292','13891130824','13891130945','13891132540','13891134913','13891138453','13891141829','13891154757','13891156700','13891158755','13891159787','13891159859','13891164516','13891166461','13891169001','13891171822','13891173728','13891175454','13891176692','13891180530','13891182300','13891184474','13891187445','13891188867','13891189045','13891196521','13892106464','13892109542','13892112608','13892118021','13892120807','13892125610','13892126601','13892129566','13892131543','13892136744','13892137504','13892141450','13892141779','13892142237','13892144319','13892147263','13892147361','13892147862','13892148377','13892149711','13892160154','13892164437','13892166285','13892166404','13892167375','13892171966','13892181160','13892189141','13892195321','13892196314','13892197727','13931104472','13991771872','13991774435','13991787308','13991787481','13991792705','13991795545','13991796179','13991796741','13992101094','13992103494','13992111160','13992111734','13992113390','13992113391','13992118367','13992134855','13992137620','13992140456','13992144366','13992147594','13992149677','13992150500','13992150858','13992154041','13992154633','13992156642','13992157155','13992163034','13992166555','13992175833','13992181664','13992183386','13992187258','13992192564','13992194566','13992198485','14','15','15009211772','15009219379','15029311716','15029314030','15029315482','15091010789','15091111929','15091117332','15091118234','15091118467','15091212075','15091218114','15091314044','15091417999','15091742792','15091812992','15091814443','1510','15114913377','15129340516','15129343199','15129388400','15129417177','15129512241','15129519940','15129593939','15129594007','15129597543','15129598786','15149118229','1516','15191107762','15191131332','15191133663','15191142814','15191146467','15191154424','15191157175','15191176093','15191180797','15229119033','15229440903','15229517651','15229690474','15249115113','15249119114','15291112443','15291114948','15291115945','15291115947','15291121522','15291132000','15291142611','15291144947','15291146916','15291148330','15291163600','15291164211','15291169952','15291179093','15291949396','15293714450','15319556434','15319556771','15319582655','15591102118','15591102222','15594336555','15594389198','15594709333','15594713945','15596688213','15596968383','15609116543','15619118880','15619860309','15667666788','15669111856','15691111124','15829111122','15829112787','15829113121','15829114110','15829414771','15829810994','15829815388','15829992871','15829993422','15829993789','15829999002','15829999839','15877311142','15877312346','15877312984','15877317733','15877411192','15877411351','15877413739','15877414222','15877416880','15877417230','15877418644','15877419793','15877525558','15877663291','15877665044','15877666584','15877675808','15891010143','15891012319','15891014353','15891014406','15891050909','15891059555','15891112920','15891115347','15891116626','15891143833','15891143949','15891144769','15891144925','15891313010','15891419647','15891570540','15891611789','15891641140','15891649985','15891684801','15891686778','15891688808','15909110749','15909112406','15909112577','15909114117','15909114233','15909114322','15909117818','15909141230','15909143156','15909146600','15909183215','15909188625','15909212572','15909214798','15909216611','15909223346','15909227544','15929071678','15929114299','15929114854','15929118333','15929410564','15929413456','15929414818','15929572713','15929573004','15929579765','15929610903','15929818003','15929850962','15929857691','15991101192','15991111124','15991113062','15991113799','15991118085','15991119761','15991120124','15991120507','15991410419','15991413221','15991416424','15991425632','15991540359','15991541481','15991547118','15991549359','15991550666','15991552301','15991555414','15991560937','15991570797','15991572109','15991581380','15991582243','15991588567','15991596967','15991599994','15991642678','15991928283','15991928535','18029215976','18091105528','18220114333','18220132388','18220136552','18220149924','18220155120','18240812936','18247773905','18291104557','18291126336','18291130507','18291155662','18291175677','18291192200','18292105673','18292120500','18292144860','18329817135','18391114145','18391163340','18391178397','18609115058','18609116185','18609119211','18609292882','18609297319','18627486005','18691119300','18691140287','18691466997','18691467090','18700108190','18700117703','18700134431','18700137046','18700137055','18700148857','18700177224','18700793212','18709119778','18717324181','18717410666','18717410888','18717513477','18729812900','18740315855','18740513111','18740518851','18740616237','18791111236','18791111348','18791114229','18791115430.','18791116117','18791199050','18809110476','18809113241','18829118088','18835608857','18891107110','18909111103','18992100588','18992107640','18992120743','18992132611','18992170099','18992189933','19469354855','195','19809118490','2','20','22','2337','2434','258','265','2678','3','3044','3336','4250','4475','4488','4513','4534','4546','4572','4721','495','5955','636','699','7099','7755','7980','80931','83538','90002','90009','90010','90026','90030','90031','90051','90052','90053','90059','90060','90061','90062','90063','90065','90066','90068','90069','90080','90088','90090','90091','90100','90101','90102','90103','90105','90106','90109','90111','90115','90116','90118','90119','90121','90122','90126','90128','90129','90130','90131','90132','90133','90135','90136','90138','90139','90151','90152','90153','90158','9016','90160','90161','90162','90163','90165','90168','90169','90182','90185','90188','90189','90193','90195','90196','90198','90199','90201','90202','90203','90205','90208','90209','90210','902111','90212','90215','90216','90218','90219','90220','90225','90228','90229','90230','90231','90232','90235','90236','90239','90251','90262','90265','90266','90268','90281','90282','90283','90286','90291','90293','90296','90299','90302','90303','90306','90309','90558','9449','952'".Split(',');
  37. Hashtable htdata = new Hashtable();
  38. for (int i = 0; i < strArray.Length; i++)
  39. {
  40. if (htdata.ContainsKey(strArray[i].Trim()))
  41. { htdata[strArray[i].Trim()] = Convert.ToInt32(htdata[strArray[i].Trim()]) + 1; }
  42. else
  43. { htdata[strArray[i].Trim()] = 1; }
  44. }
  45. string StrString = "";
  46. foreach (DictionaryEntry item in htdata)
  47. {
  48. if (Convert.ToInt32(item.Value) > 1)
  49. { StrString += "'" + item.Key + "',"; }
  50. }
  51. string SJ = htdata.Count + " " + StrString;
  52. //this.dgvData.ExportDataTable();
  53. DataTable NewTable = new DataTable();
  54. for (int i = 0; i < this.dgvData.Columns.Count; i++)
  55. {
  56. NewTable.Columns.Add(this.dgvData.Columns[i].Name.Trim(), typeof(string));
  57. }
  58. for (int i = 0; i < this.dgvData.Rows.Count; i++)
  59. {
  60. DataRow newRow = NewTable.NewRow();
  61. for (int j = 0; j < this.dgvData.Columns.Count; j++)
  62. {
  63. newRow[this.dgvData.Columns[j].Name.Trim()] = this.dgvData.Rows[i].Cells[this.dgvData.Columns[j].Name.Trim()].Value.ToString().Trim();
  64. }
  65. NewTable.Rows.Add(newRow);
  66. }
  67. string StrFilePath = StringPath + "_检测过数据.xls";
  68. //bool IsTrue = LYFZ.Command.Command_ExportExcel.DataTable2Sheet(StrFilePath, NewTable, "Sheet1", IsCoveredExistingFile: true);
  69. bool IsTrue = false;
  70. LYFZ.ComponentLibrary.FrmLoadHandling.ExecutionDoWorkMethod(delegate (object obj, System.ComponentModel.BackgroundWorker backgroundWorker)
  71. {
  72. try
  73. {
  74. IsTrue = LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(StrFilePath, NewTable, null, backgroundWorker);
  75. if (IsTrue)
  76. {
  77. MessageBoxCustom.Show("数据导出成功!");
  78. }
  79. else
  80. {
  81. MessageBoxCustom.Show("数据导出失败!");
  82. }
  83. }
  84. catch (Exception ex)
  85. {
  86. MessageBoxCustom.Show(String.Format("导出数据出错:{0}", ex.Message));
  87. }
  88. });
  89. MessageBoxCustom.Show("导出完毕");
  90. }
  91. private EnumOpenType CurrentOpenType;
  92. string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  93. public bool IsSaveed = false;
  94. string StringPath = "";
  95. char[] StrListChar = ",./;'*-+`~!#$%^&<>?|:".ToCharArray();
  96. /// <summary>
  97. /// 窗体加载事件
  98. /// </summary>
  99. /// <param name="sender"></param>
  100. /// <param name="e"></param>
  101. void MemberImportExcel_Load(object sender, EventArgs e)
  102. {
  103. this.flowLayoutPanel1.Location = new Point((this.panelEx2.Width - this.flowLayoutPanel1.Width) / 2, this.flowLayoutPanel1.Location.Y);
  104. string strColumns = "客户姓名,客户性别,手机号码,会员卡号";
  105. this.dgvData.DataColumns(strColumns);
  106. }
  107. /// <summary>
  108. /// 打开(Excel)
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. void btnOpenExcel_Click(object sender, EventArgs e)
  113. {
  114. this.CurrentOpenType = EnumOpenType.主会员;
  115. string strColumns = "客户姓名,客户性别,手机号码,QQ,出生日期,客户婚期,会员卡号,可用金额,可用积分,会员折扣";
  116. this.dgvData.DataColumns(strColumns);
  117. try
  118. {
  119. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  120. DialogResult dres = openFileDialog1.ShowDialog();
  121. if (DialogResult.OK.Equals(dres))
  122. {
  123. this.dgvData.Rows.Clear();
  124. DataTable tblMember = LYFZ.WinAPI.CustomPublicMethod.GetExcelDatatable(openFileDialog1.FileName);
  125. if (tblMember != null)
  126. {
  127. try
  128. {
  129. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  130. {
  131. backgroundWorker.ReportProgress(0, "正在获取数据...");
  132. DataTable tbl2 = mcbll.GetView_Custom("tb_ErpCustomer", StrWhere: "Cus_Telephone != ''", ShowColumnName: "Cus_Telephone,Cus_CustomerNumber").Tables[0];
  133. DataTable tbl = mcbll.GetView_Custom("tb_ErpMemberCard Left Join tb_ErpCustomer on Cus_CustomerNumber = Mc_CustomerNumber", StrWhere: "Mc_CradNumber != '' and Mc_Status = '1'", filedOrder: "tb_ErpMemberCard.ID ASC", ShowColumnName: "Mc_CustomerNumber,Mc_CradNumber,Cus_Name,Cus_Telephone").Tables[0];
  134. Hashtable htData = new Hashtable();
  135. #region 数据检查
  136. for (int i = 0; i < tblMember.Rows.Count; i++)
  137. {
  138. backgroundWorker.ReportProgress(0, "正在检测第" + (i + 1) + "条,共" + tblMember.Rows.Count + "条");
  139. string StrMages = "";
  140. if (tblMember.Rows[i]["手机号码"] == null)
  141. { StrMages += "手机号码为空;"; }
  142. else if (string.IsNullOrEmpty(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  143. { StrMages += "手机号码为空;"; }
  144. else if (tblMember.Rows[i]["手机号码"].ToString().Trim().Length != 11 || !LYFZ.Command.Command_Validate.IsPhone(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  145. { StrMages += "手机号码格式不正确;"; }
  146. if (tblMember.Rows[i]["客户性别"] == null)
  147. { StrMages += "客户性别为空;"; }
  148. else if (string.IsNullOrEmpty(tblMember.Rows[i]["客户性别"].ToString().Trim()))
  149. { StrMages += "客户性别为空;"; }
  150. else if (tblMember.Rows[i]["客户性别"].ToString().Trim() != "男" && tblMember.Rows[i]["客户性别"].ToString().Trim() != "女")
  151. { StrMages += "客户性别不是'男'或'女';"; }
  152. if (tblMember.Rows[i]["手机号码"] != null && !string.IsNullOrEmpty(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  153. {
  154. DataRow[] dtRow2 = tbl2.Select("Cus_Telephone = '" + tblMember.Rows[i]["手机号码"].ToString().Trim() + "'");
  155. if (dtRow2.Length > 0)
  156. {
  157. DataRow[] dtRow3 = tbl.Select("Mc_CustomerNumber = '" + dtRow2[0]["Cus_CustomerNumber"].ToString().Trim() + "'");
  158. if (dtRow3.Length > 0)
  159. { StrMages += "手机号码找到客户在系统中存在会员卡;"; }
  160. }
  161. else if (tblMember.Rows[i]["客户姓名"] == null && string.IsNullOrEmpty(tblMember.Rows[i]["客户姓名"].ToString().Trim()))
  162. { StrMages += "客户姓名为空;"; }
  163. DataRow[] dtRow = tblMember.Select("手机号码 = '" + tblMember.Rows[i]["手机号码"].ToString().Trim() + "'");
  164. if (dtRow.Length > 1)
  165. { StrMages += "手机号码有重复(" + dtRow.Length + ");"; }
  166. if (LYFZ.Command.Command_Validate.IsContainChinese(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  167. { StrMages += "手机号码有中文;"; }
  168. if (!LYFZ.Command.Command_Validate.IsPhone(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  169. { StrMages += "手机号码格式不正确;"; }
  170. for (int j = 0; j < this.StrListChar.Length; j++)
  171. {
  172. if (tblMember.Rows[i]["手机号码"].ToString().Trim().Contains(this.StrListChar[j].ToString().Trim()))
  173. { StrMages += "手机号码含有非法字符;"; break; }
  174. }
  175. }
  176. else
  177. { StrMages += "手机号码为空;"; }
  178. if (tblMember.Rows[i]["会员卡号"] != null)
  179. {
  180. if (!string.IsNullOrEmpty(tblMember.Rows[i]["会员卡号"].ToString().Trim()))
  181. {
  182. DataRow[] dtRow2 = tbl.Select("Mc_CradNumber = '" + tblMember.Rows[i]["会员卡号"].ToString().Trim() + "'");
  183. if (dtRow2.Length > 0)
  184. { StrMages += "会员卡号在系统中存在;"; }
  185. DataRow[] dtRow1 = tblMember.Select("会员卡号 = '" + tblMember.Rows[i]["会员卡号"].ToString().Trim() + "'");
  186. if (dtRow1.Length > 1)
  187. { StrMages += "会员卡号有重复(" + dtRow1.Length + ");"; }
  188. if (LYFZ.Command.Command_Validate.IsContainChinese(tblMember.Rows[i]["会员卡号"].ToString().Trim()))
  189. { StrMages += "会员卡号有中文;"; }
  190. try
  191. {
  192. if (LYFZ.Command.Command_Validate.IsNumeric(tblMember.Rows[i]["会员卡号"].ToString().Trim()))
  193. {
  194. if (Convert.ToInt32(tblMember.Rows[i]["会员卡号"]) == 0)
  195. { StrMages += "会员卡号不全部为0;"; }
  196. }
  197. }
  198. catch
  199. { }
  200. for (int j = 0; j < this.StrListChar.Length; j++)
  201. {
  202. if (tblMember.Rows[i]["会员卡号"].ToString().Trim().Contains(this.StrListChar[j].ToString().Trim()))
  203. { StrMages += "会员卡号含有非法字符;"; break; }
  204. }
  205. }
  206. }
  207. else
  208. {
  209. if (tblMember.Rows[i]["手机号码"] != null)
  210. {
  211. if (!string.IsNullOrEmpty(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  212. {
  213. DataRow[] dtRow2 = tbl.Select("会员卡号 = '" + tblMember.Rows[i]["手机号码"].ToString().Trim() + "'");
  214. if (dtRow2.Length > 0)
  215. { StrMages += "手机号码在系统中做会员存在;"; }
  216. }
  217. }
  218. }
  219. if (tblMember.Rows[i]["可用金额"] != null)
  220. {
  221. if (!string.IsNullOrEmpty(tblMember.Rows[i]["可用金额"].ToString().Trim()))
  222. {
  223. if (!LYFZ.Command.Command_Validate.IsNumeric(tblMember.Rows[i]["可用金额"].ToString().Trim()))
  224. { StrMages += "可用金额格式错误;"; }
  225. }
  226. }
  227. if (tblMember.Rows[i]["可用积分"] != null)
  228. {
  229. if (!string.IsNullOrEmpty(tblMember.Rows[i]["可用积分"].ToString().Trim()))
  230. {
  231. if (!LYFZ.Command.Command_Validate.IsNumeric(tblMember.Rows[i]["可用积分"].ToString().Trim()))
  232. { StrMages += "可用积分格式错误;"; }
  233. }
  234. }
  235. if (!string.IsNullOrEmpty(StrMages))
  236. { htData[tblMember.Rows[i]] = StrMages; }
  237. }
  238. #endregion
  239. backgroundWorker.ReportProgress(0, "正在处理数据...");
  240. DataTable NewTable = new DataTable();
  241. for (int i = 0; i <= tblMember.Columns.Count; i++)
  242. {
  243. if (i == tblMember.Columns.Count)
  244. { NewTable.Columns.Add("错误说明", typeof(string)); }
  245. else
  246. { NewTable.Columns.Add(tblMember.Columns[i].ColumnName.Trim(), typeof(string)); }
  247. }
  248. foreach (DictionaryEntry item in htData)
  249. {
  250. try
  251. {
  252. DataRow dtRow = (DataRow)item.Key;
  253. DataRow newRow = NewTable.NewRow();
  254. for (int j = 0; j < dtRow.Table.Columns.Count; j++)
  255. {
  256. switch (dtRow.Table.Columns[j].ColumnName.Trim())
  257. {
  258. case "出生日期":
  259. case "客户婚期":
  260. if (!string.IsNullOrEmpty(dtRow[dtRow.Table.Columns[j].ColumnName.Trim()].ToString().Trim()))
  261. { newRow[dtRow.Table.Columns[j].ColumnName.Trim()] = Convert.ToDateTime(dtRow[dtRow.Table.Columns[j].ColumnName.Trim()]).ToString("yyyy-MM-dd"); }
  262. else
  263. { newRow[dtRow.Table.Columns[j].ColumnName.Trim()] = ""; }
  264. break;
  265. default:
  266. newRow[dtRow.Table.Columns[j].ColumnName.Trim()] = dtRow[dtRow.Table.Columns[j].ColumnName.Trim()].ToString().Trim();
  267. break;
  268. }
  269. }
  270. newRow["错误说明"] = item.Value.ToString().Trim();
  271. NewTable.Rows.Add(newRow);
  272. tblMember.Rows.Remove(dtRow);
  273. }
  274. catch
  275. { }
  276. }
  277. try
  278. {
  279. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  280. { this.dgvData.DataSource(tblMember, strHideField: ""); }));
  281. }
  282. catch
  283. { }
  284. if (NewTable.Rows.Count > 0)
  285. {
  286. StringPath = System.IO.Path.GetDirectoryName(openFileDialog1.FileName) + "\\" + System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
  287. string StrFilePath = StringPath + "_有问题数据.xls"; //+ System.IO.Path.GetExtension(openFileDialog1.FileName);
  288. backgroundWorker.ReportProgress(0, "正在导出有问题数据...");
  289. bool IsTrue = LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(StrFilePath, NewTable, null, backgroundWorker);
  290. //LYFZ.ComponentLibrary.DataGridViewExport.DataTableToExcel(NewTable, IsShowSave: false, StrFileName: StrFilePath, ExportOKPrompt: "检查数据完毕!\r\n要导入的Excel中有问题数据已挑出另存于:\r\n" + StrFilePath); }));
  291. if (IsTrue)
  292. {
  293. try
  294. {
  295. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  296. { MessageBoxCustom.Show("检查数据完毕!\r\n要导入的Excel中有问题数据已挑出另存于:\r\n" + StrFilePath); }));
  297. }
  298. catch
  299. { }
  300. }
  301. }
  302. });
  303. }
  304. catch (Exception ex)
  305. { MessageBoxCustom.Show(ex.Message.ToString()); }
  306. }
  307. }
  308. }
  309. catch (Exception ex)
  310. { MessageBoxCustom.Show(new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(true)).ToString() + "\r\n错误消息:" + ex.Message); }
  311. }
  312. /// <summary>
  313. /// 打开积分副卡
  314. /// </summary>
  315. /// <param name="sender"></param>
  316. /// <param name="e"></param>
  317. void btnOpenPointsViceCard_Click(object sender, EventArgs e)
  318. {
  319. this.CurrentOpenType = EnumOpenType.积分副卡;
  320. string strColumns = "客户姓名,手机号码,积分副卡号";
  321. this.dgvData.DataColumns(strColumns);
  322. try
  323. {
  324. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  325. DialogResult dres = openFileDialog1.ShowDialog();
  326. if (DialogResult.OK.Equals(dres))
  327. {
  328. this.dgvData.Rows.Clear();
  329. DataTable tblMember = LYFZ.WinAPI.CustomPublicMethod.GetExcelDatatable(openFileDialog1.FileName);
  330. if (tblMember != null)
  331. {
  332. if (tblMember.Columns["积分副卡号"] == null || tblMember.Columns["手机号码"] == null)
  333. { MessageBoxCustom.Show("积分副卡模板格式不正确定!"); return; }
  334. DataTable tbl2 = mcbll.GetView_Custom("tb_ErpCustomer", StrWhere: "Cus_Telephone != ''", ShowColumnName: "Cus_Telephone,Cus_CustomerNumber").Tables[0];
  335. DataTable tbl = mcbll.GetView_Custom("tb_ErpMemberCard Left Join tb_ErpCustomer on Cus_CustomerNumber = Mc_CustomerNumber", StrWhere: "Mc_CradNumber != '' and Mc_Status = '1'", filedOrder: "tb_ErpMemberCard.ID ASC", ShowColumnName: "Mc_CustomerNumber,Mc_CradNumber,Cus_Name,Cus_Telephone").Tables[0];
  336. DataTable tbl3 = mcbll.GetView_Custom("tb_ErpMemberCardViceCard", StrWhere: "Mvc_Status = '1'", ShowColumnName: "Mvc_ViceCardNumber").Tables[0];
  337. Hashtable htData = new Hashtable();
  338. #region 数据检查
  339. for (int i = 0; i < tblMember.Rows.Count; i++)
  340. {
  341. string StrMages = "";
  342. if (tblMember.Rows[i]["手机号码"] == null)
  343. { StrMages += "手机号码为空;"; }
  344. else if (string.IsNullOrEmpty(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  345. { StrMages += "手机号码为空;"; }
  346. else if (tblMember.Rows[i]["手机号码"].ToString().Trim().Length != 11 || !LYFZ.Command.Command_Validate.IsPhone(tblMember.Rows[i]["手机号码"].ToString().Trim()))
  347. { StrMages += "手机号码格式不正确;"; }
  348. else
  349. {
  350. DataRow[] dtRow2 = tbl2.Select("Cus_Telephone = '" + tblMember.Rows[i]["手机号码"].ToString().Trim() + "'");
  351. if (dtRow2.Length > 0)
  352. {
  353. DataRow[] dtRow3 = tbl.Select("Mc_CustomerNumber = '" + dtRow2[0]["Cus_CustomerNumber"].ToString().Trim() + "'");
  354. if (dtRow3.Length <= 0)
  355. { StrMages += "客户在系统中未办理会员;"; }
  356. }
  357. else
  358. { StrMages += "手机号码未找到此客户;"; }
  359. //DataRow[] dtRow = tblMember.Select("手机号码 = '" + tblMember.Rows[i]["手机号码"].ToString().Trim() + "'");
  360. //if (dtRow.Length > 1)
  361. //{ StrMages += "手机号码有重复(" + dtRow.Length + ");"; }
  362. }
  363. if (tblMember.Rows[i]["积分副卡号"] != null)
  364. {
  365. if (!string.IsNullOrEmpty(tblMember.Rows[i]["积分副卡号"].ToString().Trim()))
  366. {
  367. DataRow[] dtRow2 = tbl.Select("Mc_CradNumber = '" + tblMember.Rows[i]["积分副卡号"].ToString().Trim() + "'");
  368. if (dtRow2.Length > 0)
  369. { StrMages += "副卡号在系统中做主卡号存在;"; }
  370. DataRow[] dtRow1 = tblMember.Select("积分副卡号 = '" + tblMember.Rows[i]["积分副卡号"].ToString().Trim() + "'");
  371. if (dtRow1.Length > 1)
  372. { StrMages += "副卡号有重复(" + dtRow1.Length + ");"; }
  373. DataRow[] dtRow3 = tbl3.Select("Mvc_ViceCardNumber = '" + tblMember.Rows[i]["积分副卡号"].ToString().Trim() + "'");
  374. if (dtRow3.Length > 0)
  375. { StrMages += "副卡号在系统中做副卡号存在;"; }
  376. }
  377. else
  378. { StrMages += "副卡号为空;"; }
  379. }
  380. else
  381. { StrMages += "副卡号为空;"; }
  382. if (!string.IsNullOrEmpty(StrMages))
  383. { htData[tblMember.Rows[i]] = StrMages; }
  384. }
  385. #endregion
  386. DataTable NewTable = new DataTable();
  387. for (int i = 0; i <= tblMember.Columns.Count; i++)
  388. {
  389. if (i == tblMember.Columns.Count)
  390. { NewTable.Columns.Add("错误说明", typeof(string)); }
  391. else
  392. { NewTable.Columns.Add(tblMember.Columns[i].ColumnName.Trim(), typeof(string)); }
  393. }
  394. foreach (DictionaryEntry item in htData)
  395. {
  396. try
  397. {
  398. DataRow dtRow = (DataRow)item.Key;
  399. DataRow newRow = NewTable.NewRow();
  400. for (int j = 0; j < dtRow.Table.Columns.Count; j++)
  401. {
  402. newRow[dtRow.Table.Columns[j].ColumnName.Trim()] = dtRow[dtRow.Table.Columns[j].ColumnName.Trim()].ToString().Trim();
  403. }
  404. newRow["错误说明"] = item.Value.ToString().Trim();
  405. NewTable.Rows.Add(newRow);
  406. tblMember.Rows.Remove(dtRow);
  407. }
  408. catch
  409. { }
  410. }
  411. if (NewTable.Rows.Count > 0)
  412. {
  413. string StrFilePath = System.IO.Path.GetDirectoryName(openFileDialog1.FileName) + "\\" + System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
  414. StrFilePath += "_有问题数据.xls";// +System.IO.Path.GetExtension(openFileDialog1.FileName);
  415. try
  416. {
  417. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  418. {
  419. bool IsTrue = LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(StrFilePath, NewTable,null ,backgroundWorker);
  420. //LYFZ.Command.Command_ExportExcel.DataTable2Sheet(StrFilePath, NewTable, "Sheet1", IsCoveredExistingFile: true);
  421. //LYFZ.ComponentLibrary.DataGridViewExport.DataTableToExcel(NewTable, IsShowSave: false, StrFileName: StrFilePath, ExportOKPrompt: "检查数据完毕!\r\n要导入的Excel中有问题数据已挑出另存于:\r\n" + StrFilePath); }));
  422. if (IsTrue)
  423. {
  424. try
  425. {
  426. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  427. { MessageBoxCustom.Show("检查数据完毕!\r\n要导入的Excel中有问题数据已挑出另存于:\r\n" + StrFilePath); }));
  428. }
  429. catch
  430. { }
  431. }
  432. });
  433. }
  434. catch (Exception ex) { MessageBoxCustom.Show(ex.Message.ToString()); }
  435. }
  436. this.dgvData.DataSource(tblMember, strHideField: "");
  437. }
  438. }
  439. }
  440. catch (Exception ex)
  441. { MessageBoxCustom.Show("错误消息:" + ex.Message + "\r\n" + new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(true)).ToString()); }
  442. }
  443. /// <summary>
  444. /// 打开返现副卡
  445. /// </summary>
  446. /// <param name="sender"></param>
  447. /// <param name="e"></param>
  448. void btnOpenBackCashViceCard_Click(object sender, EventArgs e)
  449. {
  450. }
  451. /// <summary>
  452. /// 保存
  453. /// </summary>
  454. /// <param name="sender"></param>
  455. /// <param name="e"></param>
  456. void btnSaveed_Click(object sender, EventArgs e)
  457. {
  458. DateTime StrTime = SDateTime.Now;
  459. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  460. DataTable tbl = mcbll.GetView_Custom("tb_ErpMemberCard Left Join tb_ErpCustomer on Cus_CustomerNumber = Mc_CustomerNumber", StrWhere: "Mc_Status = '1'", filedOrder: "tb_ErpMemberCard.ID ASC", ShowColumnName: "Mc_CustomerNumber,Mc_Number,Mc_CradNumber,Cus_Name,Cus_Telephone").Tables[0];
  461. if (this.CurrentOpenType == EnumOpenType.主会员)
  462. {
  463. #region 主会员
  464. DataTable tbl2 = mcbll.GetView_Custom("tb_ErpCustomer", StrWhere: "Cus_Telephone != ''", ShowColumnName: "Cus_Telephone,Cus_CustomerNumber").Tables[0];
  465. string StrMagess = "";
  466. string StrMagess2 = "";
  467. try
  468. {
  469. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  470. {
  471. for (int i = 0; i < this.dgvData.Rows.Count; i++)
  472. {
  473. backgroundWorker.ReportProgress(0, "正在检测第" + (i + 1) + "条,共" + this.dgvData.Rows.Count + "条");
  474. string StrClientPhone = "";
  475. string StrClientName = "";
  476. string StrClientSex = "";
  477. string StrClientBirthday = "";
  478. string StrClientQQ = "";
  479. string StrClientDayForMarriage = "";
  480. string StrMebmerCardNumber = "";
  481. string StrMemberAvailableAmount = "0";
  482. string StrMemberAvailablePoints = "0";
  483. string StrMemberDiscount = "0";
  484. #region 获取数据
  485. try
  486. {
  487. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  488. {
  489. StrClientPhone = this.dgvData.Rows[i].Cells["手机号码"].Value.ToString().Trim();
  490. StrClientName = this.dgvData.Rows[i].Cells["客户姓名"].Value.ToString().Trim();
  491. StrClientSex = this.dgvData.Rows[i].Cells["客户性别"].Value.ToString().Trim();
  492. if (string.IsNullOrEmpty(StrClientSex))
  493. { StrClientSex = "女"; }
  494. if (!string.IsNullOrEmpty(this.dgvData.Rows[i].Cells["出生日期"].Value.ToString().Trim()))
  495. { StrClientBirthday = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[i].Cells["出生日期"].Value); }
  496. if (!string.IsNullOrEmpty(this.dgvData.Rows[i].Cells["QQ"].Value.ToString().Trim()))
  497. {
  498. if (LYFZ.Command.Command_Validate.IsNumeric(this.dgvData.Rows[i].Cells["QQ"].Value.ToString().Trim()))
  499. { StrClientQQ = this.dgvData.Rows[i].Cells["QQ"].Value.ToString().Trim(); }
  500. }
  501. if (!string.IsNullOrEmpty(this.dgvData.Rows[i].Cells["客户婚期"].Value.ToString().Trim()))
  502. { StrClientDayForMarriage = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[i].Cells["客户婚期"].Value); }
  503. StrMebmerCardNumber = this.dgvData.Rows[i].Cells["会员卡号"].Value.ToString().Trim();
  504. if (!string.IsNullOrEmpty(this.dgvData.Rows[i].Cells["可用金额"].Value.ToString().Trim()))
  505. {
  506. if (LYFZ.Command.Command_Validate.IsNumeric(this.dgvData.Rows[i].Cells["可用金额"].Value.ToString().Trim()))
  507. { StrMemberAvailableAmount = this.dgvData.Rows[i].Cells["可用金额"].Value.ToString().Trim(); }
  508. }
  509. if (!string.IsNullOrEmpty(this.dgvData.Rows[i].Cells["可用积分"].Value.ToString().Trim()))
  510. {
  511. if (LYFZ.Command.Command_Validate.IsNumeric(this.dgvData.Rows[i].Cells["可用积分"].Value.ToString().Trim()))
  512. { StrMemberAvailablePoints = this.dgvData.Rows[i].Cells["可用积分"].Value.ToString().Trim(); }
  513. }
  514. if (!string.IsNullOrEmpty(this.dgvData.Rows[i].Cells["会员折扣"].Value.ToString().Trim()))
  515. {
  516. if (LYFZ.Command.Command_Validate.IsNumeric(this.dgvData.Rows[i].Cells["会员折扣"].Value.ToString().Trim()))
  517. { StrMemberDiscount = this.dgvData.Rows[i].Cells["会员折扣"].Value.ToString().Trim(); }
  518. }
  519. }));
  520. }
  521. catch
  522. { }
  523. #endregion
  524. #region 客户资料
  525. string StrClientNumber = "";
  526. bool isMember = false;
  527. LYFZ.Model.Model_ErpCustomer model_Client = null;
  528. DataRow[] dtRow2 = tbl2.Select("Cus_Telephone = '" + StrClientPhone + "'");
  529. if (dtRow2.Length > 0)
  530. {
  531. StrClientNumber = dtRow2[0]["Cus_CustomerNumber"].ToString().Trim();
  532. DataRow[] dtRow = tbl.Select("Mc_CustomerNumber = '" + dtRow2[0]["Cus_CustomerNumber"].ToString().Trim() + "'");
  533. if (dtRow.Length > 0)
  534. { isMember = true; StrMagess2 += "[客户已有会员:" + StrClientPhone + "]"; }
  535. StrMagess += "[客户电话:" + StrClientPhone + "]";
  536. }
  537. else
  538. {
  539. model_Client = new Model.Model_ErpCustomer();
  540. model_Client.Cus_CustomerNumber = LYFZ.BLL.BLL_ErpCustomer.GetClientNumber();
  541. model_Client.Cus_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  542. model_Client.Cus_Type = "";
  543. model_Client.Cus_MicroSignal = "";
  544. model_Client.Cus_Zodiac = "";
  545. model_Client.Cus_Address = "";
  546. model_Client.Cus_WorkUnit = "";
  547. model_Client.Cus_CreateDateTime = StrTime;
  548. model_Client.Cus_CreateName = StrUserID;
  549. model_Client.Cus_Name = LYFZ.BLL.OtherCommonModel.ClearSpecialCharacter(StrClientName);
  550. model_Client.Cus_NamePinyin = LYFZ.Command.Command_ChineseToPinyin.GetChineseSpellPinyin(StrClientName).ToLower();
  551. model_Client.Cus_Sex = false;
  552. if (StrClientSex == "女")
  553. { model_Client.Cus_Sex = true; }
  554. model_Client.Cus_Telephone = StrClientPhone;
  555. model_Client.Cus_QQ = StrClientQQ;
  556. model_Client.Cus_Birthday = StrClientBirthday;
  557. if (string.IsNullOrEmpty(StrClientBirthday))
  558. { model_Client.Cus_BirthdayLunar = ""; }
  559. else
  560. {
  561. model_Client.Cus_Zodiac = LYFZ.Command.Command_CalendarTurnLunar.GetZodiac(StrClientBirthday, false);
  562. model_Client.Cus_BirthdayLunar = "0";
  563. }
  564. model_Client.Cus_DayForMarriage = StrClientDayForMarriage;
  565. if (string.IsNullOrEmpty(StrClientDayForMarriage))
  566. { model_Client.Cus_DayForMarriageLunar = ""; }
  567. else
  568. { model_Client.Cus_DayForMarriageLunar = "0"; }
  569. clist.Add(ctbll.GetAddCommandInfo(model_Client));
  570. //客户组表
  571. LYFZ.Model.Model_ErpCustomerGroup modelClientGroup = new Model.Model_ErpCustomerGroup();
  572. modelClientGroup.GP_OrderNumber = "";
  573. modelClientGroup.GP_CustomerGroupID = LYFZ.BLL.BLL_ErpCustomer.GetNewClientGroupNumber();
  574. modelClientGroup.GP_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  575. modelClientGroup.GP_GroupType = 1;
  576. modelClientGroup.GP_CustomerType = -1;
  577. modelClientGroup.GP_CustomerStatus = "正常";
  578. modelClientGroup.GP_LossReason = "";
  579. modelClientGroup.GP_DegreeOfIntent = "";
  580. modelClientGroup.GP_CustomerSource = "";
  581. modelClientGroup.GP_IntroducerCustomerID = "";
  582. modelClientGroup.GP_Remark = "";
  583. modelClientGroup.GP_BelongsPersonID = "";
  584. modelClientGroup.GP_CreateDatetime = StrTime;
  585. modelClientGroup.GP_CreateName = StrUserID;
  586. modelClientGroup.GP_ISIntentionCustomer = 0;
  587. modelClientGroup.GP_RemindEvent = "";
  588. clist.Add(ctgpbll.GetAddCommandInfo(modelClientGroup));
  589. //客户成员表
  590. LYFZ.Model.Model_ErpCustomerGroupMembers modelClientMember = new Model.Model_ErpCustomerGroupMembers();
  591. modelClientMember.GM_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  592. modelClientMember.GM_CustomerGroupID = modelClientGroup.GP_CustomerGroupID;
  593. modelClientMember.GM_CustomerID = model_Client.Cus_CustomerNumber;
  594. modelClientMember.GM_Master = 1;
  595. modelClientMember.GM_ProtagonistCustomer = 1;
  596. modelClientMember.GM_RelatedPersonID = modelClientMember.GM_CustomerID;
  597. modelClientMember.GM_Relation = "本人";
  598. modelClientMember.GM_IsOrder = 0;
  599. modelClientMember.GM_IsOrderNumber = "";
  600. clist.Add(ctgmbll.GetAddCommandInfo(modelClientMember));
  601. }
  602. #endregion
  603. #region 会员资料
  604. if (!isMember)
  605. {
  606. bool IsFind = false;
  607. if (!string.IsNullOrEmpty(StrMebmerCardNumber))
  608. {
  609. DataRow[] dtRow = tbl.Select("Mc_CradNumber = '" + StrMebmerCardNumber + "'");
  610. if (dtRow.Length > 0)
  611. {
  612. StrMagess += "[会员卡号:" + StrClientPhone + "]";
  613. IsFind = true;
  614. }
  615. }
  616. else
  617. {
  618. DataRow[] dtRow = tbl.Select("Mc_CradNumber = '" + StrClientPhone + "'");
  619. if (dtRow.Length > 0)
  620. {
  621. StrMagess += "[会员卡号:" + StrClientPhone + "]";
  622. IsFind = true;
  623. }
  624. }
  625. if (!IsFind)
  626. {
  627. LYFZ.Model.Model_ErpSystemConfigure sgModel = LYFZ.BLL.OrderPayment_Member.GetNewMenberNumber(i);
  628. clist.Add(sgbll.GetUpdateCommandInfo(sgModel));
  629. LYFZ.Model.Model_ErpMemberCard model_MCard = new Model.Model_ErpMemberCard();
  630. model_MCard.Mc_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  631. if (model_Client == null)
  632. { model_MCard.Mc_CustomerNumber = StrClientNumber; }
  633. else
  634. { model_MCard.Mc_CustomerNumber = model_Client.Cus_CustomerNumber; }
  635. model_MCard.Mc_Money = Convert.ToDecimal(StrMemberAvailableAmount);
  636. model_MCard.Mc_Number = sgModel.Sconfig_Value;
  637. if (!string.IsNullOrEmpty(StrMebmerCardNumber))
  638. { model_MCard.Mc_CradNumber = StrMebmerCardNumber; }
  639. else
  640. { model_MCard.Mc_CradNumber = StrClientPhone; }
  641. model_MCard.Mc_CardType = "无";
  642. model_MCard.Mc_TraderPassword = "";
  643. model_MCard.Mc_UsedNumber = "";
  644. model_MCard.Mc_Status = "1";
  645. model_MCard.Mc_Remark = "";
  646. model_MCard.Mc_OpenCardSource = "会员导入," + new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(true)).ToString();
  647. model_MCard.Mc_CreateDatetime = StrTime;
  648. model_MCard.Mc_CreateName = StrUserID;
  649. clist.Add(mcbll.GetAddCommandInfo(model_MCard));
  650. #region 会员积分
  651. int intPoints = Convert.ToInt32(Convert.ToDecimal(StrMemberAvailablePoints));
  652. LYFZ.Model.Model_ErpMemberCardPoints model_Points = mcpsbll.GetModel("Mcps_Number", model_MCard.Mc_Number);
  653. if (model_Points.ID <= 0)
  654. {
  655. model_Points = new Model.Model_ErpMemberCardPoints();
  656. model_Points.Mcps_Number = model_MCard.Mc_Number;
  657. model_Points.Mcps_TotalPoints = intPoints;
  658. model_Points.Mcps_AvailablePoints = intPoints;
  659. model_Points.Mcps_OpenCardSource = "会员导入," + new System.Diagnostics.StackTrace(new System.Diagnostics.StackFrame(true)).ToString();
  660. model_Points.Mcps_UpdateDateTime = StrTime;
  661. model_Points.Mcps_UpdateName = StrUserID;
  662. clist.Add(mcpsbll.GetAddCommandInfo(model_Points));
  663. }
  664. #endregion
  665. #region 会员折扣
  666. decimal decDiscount = Convert.ToDecimal(StrMemberDiscount);
  667. if (decDiscount > 0)
  668. {
  669. LYFZ.Model.Model_ErpMemberCardDiscount model_Discount = mcdtbll.GetModel("Mcdt_Number", model_MCard.Mc_Number);
  670. if (model_Discount.ID <= 0)
  671. {
  672. model_Discount = new Model.Model_ErpMemberCardDiscount();
  673. model_Discount.Mcdt_Number = model_MCard.Mc_Number;
  674. model_Discount.Mcdt_Discount = decDiscount;
  675. model_Discount.Mcdt_UpdateDateTime = StrTime;
  676. model_Discount.Mcdt_UpdateName = StrUserID;
  677. clist.Add(mcdtbll.GetAddCommandInfo(model_Discount));
  678. }
  679. }
  680. #endregion
  681. }
  682. }
  683. #endregion
  684. }
  685. });
  686. }
  687. catch (Exception ex)
  688. {
  689. MessageBoxCustom.Show(ex.Message.ToString());
  690. return;
  691. }
  692. if (clist.Count > 0)
  693. {
  694. if (!string.IsNullOrEmpty(StrMagess2))
  695. { StrMagess += "\r\n" + StrMagess2; }
  696. if (!string.IsNullOrEmpty(StrMagess))
  697. {
  698. LYFZ.Software.MainBusiness.MembershipManage.SetSmallForm.MemberImportRepeat frm = new MemberImportRepeat();
  699. frm.StrText = "在系统中已经存在,选择'是'为继续保存但不对客户数据做修改,选择'否'为取消保存操作?";
  700. frm.StrMagess = StrMagess;
  701. frm.ShowDialog();
  702. if (!frm.IsSaveed)
  703. { return; }
  704. //if (MessageBoxCustom.Show(StrMagess + "\r\n在系统中已经存在,选择'是'为继续保存但不对客户数据做修改,选择'否'为取消保存操作?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  705. //{ return; }
  706. }
  707. else
  708. {
  709. if (MessageBoxCustom.Show("是否确定要导入?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  710. { return; }
  711. }
  712. int IsExecuteSqlTran = 0;
  713. try
  714. {
  715. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  716. {
  717. backgroundWorker.ReportProgress(0, "保存正在提交中,请稍等...");
  718. IsExecuteSqlTran = LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  719. if (IsExecuteSqlTran > 0)
  720. { LYFZ.DAL.DAL_ErpCustomer.UpdateAggregationCustomerAll(); }
  721. });
  722. }
  723. catch (Exception ex) { MessageBoxCustom.Show(ex.Message.ToString()); }
  724. if (IsExecuteSqlTran > 0)
  725. {
  726. this.IsSaveed = true;
  727. MessageBoxCustom.Show("导入成功!");
  728. this.Close();
  729. }
  730. else
  731. { MessageBoxCustom.Show("导入失败!"); }
  732. }
  733. #endregion
  734. }
  735. else if (this.CurrentOpenType == EnumOpenType.积分副卡)
  736. {
  737. #region 积分副卡
  738. DataTable tbl2 = mcbll.GetView_Custom("tb_ErpMemberCardViceCard", StrWhere: "Mvc_Status = '1'", filedOrder: "ID ASC", ShowColumnName: "*").Tables[0];
  739. string StrMagess = "";
  740. string StrMagess2 = "";
  741. try
  742. {
  743. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  744. {
  745. int NumberCount = 1;
  746. string StrMcNumber = LYFZ.BLL.BLL_ErpMemberCard.GetViceCardLastViceNumber();
  747. LYFZ.Model.Model_ErpMemberCardViceCard model = null;
  748. for (int i = 0; i < this.dgvData.Rows.Count; i++)
  749. {
  750. backgroundWorker.ReportProgress(0, "正在检测第" + (i + 1) + "条");
  751. string StrClientPhone = "";
  752. string StrClientName = "";
  753. string StrMebmerViceCardNumber = "";
  754. #region 获取数据
  755. try
  756. {
  757. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  758. {
  759. StrClientPhone = this.dgvData.Rows[i].Cells["手机号码"].Value.ToString().Trim();
  760. StrClientName = this.dgvData.Rows[i].Cells["客户姓名"].Value.ToString().Trim();
  761. StrMebmerViceCardNumber = this.dgvData.Rows[i].Cells["积分副卡号"].Value.ToString().Trim();
  762. }));
  763. }
  764. catch
  765. { }
  766. #endregion
  767. #region 获取主会员卡卡编号
  768. DataRow[] dtRow = tbl.Select("Cus_Telephone = '" + StrClientPhone + "'");
  769. if (dtRow.Length > 0)
  770. {
  771. DataRow[] dtRow2 = tbl2.Select("Mvc_ViceCardNumber = '" + StrMebmerViceCardNumber + "'");
  772. if (dtRow2.Length <= 0)
  773. {
  774. model = new Model.Model_ErpMemberCardViceCard();
  775. model.Mvc_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  776. model.Mvc_ViceNumber = LYFZ.BLL.BLL_ErpMemberCard.GetNewViceCardNumber(StrMcNumber, ref NumberCount);
  777. model.Mvc_Number = dtRow[0]["Mc_Number"].ToString().Trim();
  778. model.Mvc_ViceCardNumber = StrMebmerViceCardNumber;
  779. model.Mvc_ViceCardType = "积分副卡";
  780. model.Mvc_ViceMoney = 0;
  781. model.Mvc_ViceTraderPassword = "";
  782. model.Mvc_Status = "1";
  783. model.Mvc_UsedNumber = "";
  784. model.Mvc_Remark = "";
  785. model.Mvc_CashBackGroup = -1;
  786. model.Mvc_OpenCardSource = "副卡导入";
  787. model.Mvc_CreateDatetime = StrTime;
  788. model.Mvc_CreateName = this.StrUserID;
  789. clist.Add(mcvcbll.GetAddCommandInfo(model));
  790. }
  791. else
  792. { StrMagess2 += "[积分副卡号:" + StrClientPhone + "]"; }
  793. }
  794. else
  795. { StrMagess += "[客户电话:" + StrClientPhone + "]"; }
  796. #endregion
  797. }
  798. });
  799. }
  800. catch (Exception ex) { MessageBoxCustom.Show(ex.Message.ToString()); }
  801. if (clist.Count > 0)
  802. {
  803. string StrMagessT = "";
  804. if (!string.IsNullOrEmpty(StrMagess))
  805. { StrMagessT = "在系统中未找到客户:(" + StrMagess + ")"; }
  806. if (!string.IsNullOrEmpty(StrMagess2))
  807. { StrMagessT += "在系统已存在的副卡:(" + StrMagess2 + ")"; }
  808. if (!string.IsNullOrEmpty(StrMagess))
  809. { MessageBoxCustom.Show(StrMagess, "温馨提示", MessageBoxButtons.YesNo); return; }
  810. else
  811. {
  812. if (MessageBoxCustom.Show("是否确定要导入?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  813. { return; }
  814. }
  815. int IsExecuteSqlTran = 0;
  816. try
  817. {
  818. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  819. {
  820. backgroundWorker.ReportProgress(0, "保存正在提交中,请稍等...");
  821. IsExecuteSqlTran = LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  822. });
  823. }
  824. catch (Exception ex) { MessageBoxCustom.Show(ex.Message.ToString()); }
  825. if (IsExecuteSqlTran > 0)
  826. {
  827. this.IsSaveed = true;
  828. MessageBoxCustom.Show("导入成功!");
  829. this.Close();
  830. }
  831. else
  832. { MessageBoxCustom.Show("导入失败!"); }
  833. }
  834. #endregion
  835. }
  836. }
  837. /// <summary>
  838. /// 移除
  839. /// </summary>
  840. /// <param name="sender"></param>
  841. /// <param name="e"></param>
  842. void btnDelete_Click(object sender, EventArgs e)
  843. {
  844. if (this.dgvData.Rows.Count > 0)
  845. {
  846. if (this.dgvData.CurrentRow != null)
  847. {
  848. if (this.dgvData.CurrentRow.Index >= 0)
  849. { this.dgvData.Rows.Remove(this.dgvData.CurrentRow); }
  850. }
  851. }
  852. }
  853. /// <summary>
  854. /// 取消
  855. /// </summary>
  856. /// <param name="sender"></param>
  857. /// <param name="e"></param>
  858. void btnCancel_Click(object sender, EventArgs e)
  859. { this.Close(); }
  860. /// <summary>
  861. /// 添加行是发生事件
  862. /// </summary>
  863. /// <param name="sender"></param>
  864. /// <param name="e"></param>
  865. void dgvData_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
  866. {
  867. if (this.CurrentOpenType == EnumOpenType.主会员)
  868. {
  869. if (this.dgvData.Rows[e.RowIndex].Cells["出生日期"].Value != null)
  870. {
  871. if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["出生日期"].Value.ToString().Trim()))
  872. { this.dgvData.Rows[e.RowIndex].Cells["出生日期"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["出生日期"].Value); }
  873. }
  874. if (this.dgvData.Rows[e.RowIndex].Cells["客户婚期"].Value != null)
  875. {
  876. if (!string.IsNullOrEmpty(this.dgvData.Rows[e.RowIndex].Cells["客户婚期"].Value.ToString().Trim()))
  877. { this.dgvData.Rows[e.RowIndex].Cells["客户婚期"].Value = LYFZ.Command.Command_Validate.DateTimeToString(this.dgvData.Rows[e.RowIndex].Cells["客户婚期"].Value); }
  878. }
  879. }
  880. }
  881. /// <summary>
  882. /// 打开要导入的类型
  883. /// </summary>
  884. enum EnumOpenType
  885. {
  886. 主会员,
  887. 积分副卡,
  888. 返现副卡
  889. }
  890. }
  891. }