ImportExcel.cs 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Reflection;
  9. using LYFZ.BLL;
  10. using LYFZ.Model;
  11. using LYFZ.DAL;
  12. using System.Text.RegularExpressions;
  13. using LYFZ.ComponentLibrary;
  14. using System.IO;
  15. using LYFZ.Software.MainBusiness.Customers;
  16. using System.Collections;
  17. namespace LYFZ.Software.MainBusiness.HospitalTrackingSystem
  18. {
  19. public partial class ImportExcel : LYFZ.Software.UI.HospitalTrackingSystem.ImportExcel
  20. {
  21. LYFZ.BLL.BLL_ErpOrder orbll = new BLL.BLL_ErpOrder();
  22. BLL.BLL_ErpHospitalClient hcbll = new BLL.BLL_ErpHospitalClient();
  23. DataTable newDt = new DataTable();
  24. public ImportExcel()
  25. {
  26. this.btnOpen.Click += btnOpen_Click;
  27. this.btnSave.Click += btnSave_Click;
  28. this.btnCancel.Click += btnCancel_Click;
  29. }
  30. /// <summary>
  31. /// 是否保存
  32. /// </summary>
  33. public bool IsSaveed = false;
  34. string StrUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  35. /// <summary>
  36. /// 取消按钮
  37. /// </summary>
  38. /// <param name="sender"></param>
  39. /// <param name="e"></param>
  40. void btnCancel_Click(object sender, EventArgs e)
  41. {
  42. this.Close();
  43. }
  44. /// <summary>
  45. /// 保存按钮
  46. /// </summary>
  47. /// <param name="sender"></param>
  48. /// <param name="e"></param>
  49. void btnSave_Click(object sender, EventArgs e)
  50. {
  51. if (this.dgvData.Rows.Count > 0)
  52. {
  53. if (MessageBoxCustom.Show("你确定要导入吗?", "温馨提示", MessageBoxButtons.YesNo) == DialogResult.No)
  54. { return; }
  55. List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  56. try
  57. {
  58. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  59. {
  60. //foreach(DataGridViewColumn dataColumn in this.dgvData.Columns)
  61. //{
  62. // newDt.Columns.Add(dataColumn.Name);
  63. //}
  64. //for (int i = 0; i < this.dgvData.Rows.Count; i++)
  65. //{
  66. // DataRow newDr = newDt.NewRow();
  67. // foreach (DataGridViewColumn dataColumn in this.dgvData.Columns)
  68. // {
  69. // newDr[dataColumn.Name] = this.dgvData.Rows[i].Cells[dataColumn.Name].Value;
  70. // }
  71. // newDt.Rows.Add(newDr);
  72. //}
  73. for (int i = 0; i < newDt.Rows.Count; i++)
  74. {
  75. backgroundWorker.ReportProgress(0, "正在检测第" + (i + 1) + "条,共" + this.dgvData.Rows.Count + "条");
  76. LYFZ.Model.Model_ErpHospitalClient model = new Model_ErpHospitalClient();
  77. model.Hct_DividedShop = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.GetLocalCompanyInfoID();
  78. model.Hct_Oddnumber = this.GenerationNumber(i);
  79. try
  80. {
  81. model.Hct_CustomerName = newDt.Rows[i]["客户姓名"].ToString().Trim();
  82. if (newDt.Rows[i]["宝宝生日/预产期"].ToString().Trim().Length > 0)
  83. { model.Hct_BabyBirthday = Convert.ToDateTime(newDt.Rows[i]["宝宝生日/预产期"]).ToString("yyyy-MM-dd"); }
  84. if (newDt.Rows[i]["生日类型"].ToString().Trim() == "宝宝生日")
  85. {
  86. model.Hct_BirthdayType = 0;
  87. model.Hct_BabyName = newDt.Rows[i]["宝宝姓名"].ToString().Trim();
  88. model.Hct_BabySex = newDt.Rows[i]["宝宝性别"].ToString().Trim();
  89. model.Hct_AreLunar = newDt.Rows[i]["生日是否农历"].ToString().Trim() == "农历" ? true : false;
  90. }
  91. else if (newDt.Rows[i]["生日类型"].ToString().Trim() == "预产期")
  92. {
  93. model.Hct_BirthdayType = 1;
  94. model.Hct_AreLunar = false;
  95. model.Hct_PregnantDay = 0;
  96. if (!string.IsNullOrEmpty(model.Hct_BabyBirthday) && string.IsNullOrEmpty(model.Hct_PregnantDay.ToString().Trim()))
  97. {
  98. int IntDay = Convert.ToInt32("-" + (40 * 7));
  99. model.Hct_PregnantDay = ((SDateTime.Now - Convert.ToDateTime(model.Hct_BabyBirthday).AddDays(IntDay)).Days / 7);
  100. }
  101. }
  102. }
  103. catch (Exception ex)
  104. {
  105. MessageBoxCustom.Show("来单批号为:" + newDt.Rows[i]["来单批号"].ToString().Trim() + ";出错原因:" + ex.Message.Trim());
  106. return;
  107. }
  108. model.Hct_MessageSingle = "否";
  109. model.Hct_CustomerOrders = 0;
  110. model.Hct_LostRemark = "";
  111. model.Hct_OrderNumber = "";
  112. model.Hct_BabyFeeding = newDt.Rows[i]["喂养方式"].ToString_s().Trim();
  113. model.Hct_CustomerRegions = newDt.Rows[i]["客户区域"].ToString_s().Trim();
  114. model.Hct_CustomerGroups = newDt.Rows[i]["客户类别"].ToString_s().Trim();
  115. model.Hct_DealStatus = "未成交";
  116. model.Hct_SingleHospital = newDt.Rows[i]["来单医院"].ToString_s().Trim();
  117. model.Hct_MyselfMobile = newDt.Rows[i]["本人手机"].ToString_s().Trim();
  118. model.Hct_HusbandMobile = newDt.Rows[i]["老公手机"].ToString_s().Trim();
  119. model.Hct_FamilyPhone = newDt.Rows[i]["自家电话"].ToString_s().Trim();
  120. model.Hct_Husbandphone = newDt.Rows[i]["婆家电话"].ToString_s().Trim();
  121. model.Hct_Maidenphone = newDt.Rows[i]["娘家电话"].ToString_s().Trim();
  122. model.Hct_QQ = newDt.Rows[i]["客户QQ"].ToString_s().Trim();
  123. model.Hct_Retail = newDt.Rows[i]["门市"].ToString_s().Trim();
  124. model.Hct_Remarks = newDt.Rows[i]["来单备注"].ToString_s().Trim();
  125. model.Hct_HomeAddress = newDt.Rows[i]["自家地址"].ToString_s().Trim();
  126. model.Hct_HomePostcode = newDt.Rows[i]["自家邮编"].ToString_s().Trim();
  127. model.Hct_HusbandAddress = newDt.Rows[i]["婆家地址"].ToString_s().Trim();
  128. model.Hct_HusbandPostcode = newDt.Rows[i]["婆家邮编"].ToString_s().Trim();
  129. model.Hct_MaidenAddress = newDt.Rows[i]["娘家地址"].ToString_s().Trim();
  130. model.Hct_MaidenPostcode = newDt.Rows[i]["娘家邮编"].ToString_s();
  131. if (!string.IsNullOrEmpty(newDt.Rows[i]["来单日期"].ToString_s().Trim()))
  132. { model.Hct_SingleDatetime = Convert.ToDateTime(newDt.Rows[i]["来单日期"]); }
  133. model.Hcr_BusinessType = newDt.Rows[i]["业务种类"].ToString_s().Trim();
  134. model.Hct_BusinessIntention = newDt.Rows[i]["业务意向"].ToString_s().Trim();
  135. model.Hct_CreateDatetime = SDateTime.Now;
  136. model.Hct_CreateName = this.StrUserID;
  137. model.Hct_ImportedOrderNumber = newDt.Rows[i]["来单批号"].ToString_s().Trim();
  138. clist.Add(hcbll.GetAddCommandInfo(model));
  139. }
  140. });
  141. }
  142. catch (Exception ex)
  143. {
  144. MessageBoxCustom.Show(ex.Message.ToString());
  145. return;
  146. }
  147. if (clist.Count > 0)
  148. {
  149. int IsExecuteSqlTran = 0;
  150. try
  151. {
  152. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  153. {
  154. backgroundWorker.ReportProgress(0, "保存正在提交中,请稍等...");
  155. IsExecuteSqlTran = LYFZ.BLL.BaseBllOperate.ExecuteSqlTran(clist);
  156. });
  157. }
  158. catch (Exception ex) { MessageBoxCustom.Show(ex.Message.ToString()); }
  159. if (IsExecuteSqlTran > 0)
  160. {
  161. this.IsSaveed = true;
  162. MessageBoxCustom.Show("导入成功!");
  163. this.dgvData.Rows.Clear();
  164. this.Close();
  165. }
  166. else
  167. { MessageBoxCustom.Show("导入失败!"); }
  168. }
  169. }
  170. #region
  171. //Customer Cus = new Customer();
  172. //bool ok = true;
  173. //System.Data.DataTable dt = orbll.GetView_Custom("tb_ErpHospitalClient", StrWhere: "Hct_MyselfMobile in (" + StrDianhua("本人手机") + ")", ShowColumnName: "ID,Hct_MyselfMobile,Hct_HusbandMobile").Tables[0];
  174. //LYFZ.BLL.BLL_ErpHospitalClient ambll = new BLL.BLL_ErpHospitalClient();
  175. //DateTime strTime = SDateTime.Now;
  176. //string strUserID = LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.LoginUserModel.User_EmployeeID;
  177. //if (dgvData.Rows.Count > 0)
  178. //{
  179. // List<string> Gmlist = new List<string>();
  180. // Gmlist = new List<string>();
  181. // List<Helper.CommandInfo> clist = new List<Helper.CommandInfo>();
  182. // IntentionsEntered frm = new IntentionsEntered();
  183. // if (dgvData.Columns[0].HeaderText.Trim() == "客户姓名" && dgvData.Columns[1].HeaderText.Trim() == "宝宝姓名" && dgvData.Columns[2].HeaderText.Trim() == "宝宝性别" && dgvData.Columns[3].HeaderText.Trim() == "生日类型"
  184. // && dgvData.Columns[4].HeaderText.Trim() == "宝宝生日/预产期" && dgvData.Columns[5].HeaderText.Trim() == "是否农历" && dgvData.Columns[6].HeaderText.Trim() == "本人手机" && dgvData.Columns[7].HeaderText.Trim() == "老公手机" &&
  185. // dgvData.Columns[8].HeaderText.Trim() == "客户区域" && dgvData.Columns[9].HeaderText.Trim() == "来单医院")
  186. // {
  187. // for (int i = 0; i < dgvData.Rows.Count; i++)
  188. // {
  189. // Model.Model_ErpHospitalClient model = new Model.Model_ErpHospitalClient();
  190. // model.Hct_Oddnumber = frm.GenerationNumber();
  191. // if (dgvData.Rows[i].Cells["客户姓名"].Value.ToString().Trim() != "")
  192. // { model.Hct_CustomerName = dgvData.Rows[i].Cells["客户姓名"].Value.ToString().Trim(); }
  193. // else { ok = false; }
  194. // if (dgvData.Rows[i].Cells["宝宝姓名"].Value.ToString().Trim() != "")
  195. // { model.Hct_BabyName = dgvData.Rows[i].Cells["宝宝姓名"].Value.ToString().Trim(); }
  196. // else { ok = false; }
  197. // if (dgvData.Rows[i].Cells["宝宝性别"].Value.ToString().Trim() != "男")
  198. // {
  199. // if (dgvData.Rows[i].Cells["宝宝性别"].Value.ToString().Trim() != "女")
  200. // { ok = false; }
  201. // else { model.Hct_BabySex = dgvData.Rows[i].Cells["宝宝性别"].Value.ToString().Trim(); }
  202. // }
  203. // else { model.Hct_BabySex = dgvData.Rows[i].Cells["宝宝性别"].Value.ToString().Trim(); }
  204. // if (dgvData.Rows[i].Cells["生日类型"].Value.ToString().Trim() == "宝宝生日")
  205. // {
  206. // model.Hct_BirthdayType = 0;
  207. // }
  208. // else { model.Hct_BirthdayType = 1; }
  209. // string Strqq = dgvData.Rows[i].Cells["宝宝生日/预产期"].Value.ToString().Trim();
  210. // string Straa = dgvData.Rows[i].Cells["是否农历"].Value.ToString().Trim();
  211. // if (Strqq.Length != 10)
  212. // {
  213. // ok = false;
  214. // }
  215. // if (Strqq != "")
  216. // {
  217. // LYFZ.ComponentLibrary.MaskedTextDateEx maskDate = new ComponentLibrary.MaskedTextDateEx();
  218. // LYFZ.ComponentLibrary.CheckBoxEx chk = new ComponentLibrary.CheckBoxEx();
  219. // if (Straa == "农历")
  220. // { chk.Checked = true; }
  221. // maskDate.Text = Strqq;
  222. // if (maskDate.CheckDateValue(maskDate, chk) == 2)
  223. // { ok = false; }
  224. // else { model.Hct_BabyBirthday = Strqq; }
  225. // }
  226. // if (dgvData.Rows[i].Cells["是否农历"].Value.ToString().Trim() == "农历")
  227. // {
  228. // model.Hct_AreLunar = true;
  229. // }
  230. // else { model.Hct_AreLunar = false; }
  231. // string Strzas = dgvData.Rows[i].Cells["本人手机"].Value.ToString().Trim();
  232. // string Strgas = dgvData.Rows[i].Cells["老公手机"].Value.ToString().Trim();
  233. // if (dgvData.Rows[i].Cells["本人手机"].Value.ToString().Trim() != "" && dgvData.Rows[i].Cells["本人手机"].Value.ToString().Length == 11)
  234. // {
  235. // DataRow[] row = dt.Select(" Hct_MyselfMobile='" + dgvData.Rows[i].Cells["本人手机"].Value.ToString().Trim() + "'");
  236. // if (dt.Rows.Count > 0)
  237. // {
  238. // ok = false;
  239. // }
  240. // else { model.Hct_MyselfMobile = dgvData.Rows[i].Cells["本人手机"].Value.ToString().Trim(); }
  241. // }
  242. // else { ok = false; }
  243. // model.Hct_HusbandMobile = dgvData.Rows[i].Cells["老公手机"].Value.ToString().Trim();
  244. // model.Hct_CustomerRegions = dgvData.Rows[i].Cells["客户区域"].Value.ToString().Trim();
  245. // model.Hct_SingleHospital = dgvData.Rows[i].Cells["来单医院"].Value.ToString().Trim();
  246. // model.Hct_CreateDatetime = strTime;
  247. // model.Hct_CreateName = strUserID;
  248. // clist.Add(ambll.GetAddCommandInfo(model));
  249. // }
  250. // if (clist.Count > 0)
  251. // {
  252. // MessageBoxCustom.Show("导入成功!");
  253. // this.DialogResult = DialogResult.OK;
  254. // if (ok == false)
  255. // {
  256. // Cus.DataToExcel(dgvData, "医院跟踪系统", Url);
  257. // MessageBoxCustom.Show(Url);
  258. // return;
  259. // }
  260. // }
  261. // else { MessageBoxCustom.Show("导入失败!"); }
  262. // }
  263. // else { MessageBoxCustom.Show("请导入正确的Excel模板!"); }
  264. //}
  265. //else
  266. //{
  267. // MessageBoxCustom.Show("Excel没有数据,请添加后再导入!");
  268. //}
  269. #endregion
  270. }
  271. string StringPath = "";
  272. char[] StrListChar = ",./;'*-+`~!#$%^&<>?|:".ToCharArray();
  273. string[] StrColumnsName = "来单批号,门市,客户类别,业务意向,来单医院,客户区域,业务种类,客户姓名,客户QQ,本人手机,老公手机,生日类型,宝宝姓名,宝宝性别,喂养方式,生日是否农历,宝宝生日/预产期,怀孕周数,自家地址,自家邮编,自家电话,婆家地址,婆家邮编,婆家电话,娘家地址,娘家邮编,娘家电话,来单日期,来单备注".Split(',');
  274. /// <summary>
  275. /// 打开Excel按钮
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. void btnOpen_Click(object sender, EventArgs e)
  280. {
  281. try
  282. {
  283. openFileDialog1.Filter = "Microsoft Excel files(*.xls)|*.xls;*.xlsx";//过滤一下,只要表格格式的
  284. DialogResult dres = openFileDialog1.ShowDialog();
  285. if (DialogResult.OK.Equals(dres))
  286. {
  287. System.Data.DataTable tblMember = LYFZ.WinAPI.CustomPublicMethod.GetExcelDatatable(openFileDialog1.FileName); //ExcelToDataTable(openFileDialog1.FileName, "Sheet1");
  288. if (tblMember != null)
  289. {
  290. for (int i = 0; i < StrColumnsName.Length; i++)
  291. {
  292. if (tblMember.Columns[StrColumnsName[i].Trim()] == null)
  293. {
  294. MessageBoxCustom.Show("所打开的医院跟踪系统导入模板格式不正确!"); return;
  295. }
  296. }
  297. try
  298. {
  299. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate(object obj, BackgroundWorker backgroundWorker)
  300. {
  301. backgroundWorker.ReportProgress(0, "正在获取数据...");
  302. DataTable tbl = orbll.GetView_Custom("tb_ErpHospitalClient", StrWhere: "", ShowColumnName: "*").Tables[0];
  303. Hashtable htData = new Hashtable();
  304. #region 数据检查
  305. for (int i = 0; i < tblMember.Rows.Count; i++)
  306. {
  307. backgroundWorker.ReportProgress(0, "正在检测第" + (i + 1) + "条,共" + tblMember.Rows.Count + "条");
  308. string StrMages = "";
  309. if (tblMember.Rows[i]["来单批号"] == null || string.IsNullOrEmpty(tblMember.Rows[i]["来单批号"].ToString().Trim()))
  310. { StrMages += "来单批号为空;"; }
  311. else if (tblMember.Rows[i]["来单批号"].ToString().Trim().Length > 20)
  312. { StrMages += "来单批号长度超过20;"; }
  313. if (!string.IsNullOrEmpty(tblMember.Rows[i]["来单批号"].ToString().Trim()))
  314. {
  315. DataRow[] dtHt = tbl.Select("Hct_ImportedOrderNumber = '" + tblMember.Rows[i]["来单批号"].ToString().Trim() + "'");
  316. if (dtHt.Length > 0)
  317. { StrMages += "来单批号数据库已存在;"; }
  318. DataRow[] dtMember = tblMember.Select("来单批号 = '" + tblMember.Rows[i]["来单批号"].ToString().Trim() + "'");
  319. if (dtMember.Length > 1)
  320. { StrMages += "导入数据源中来单批号有重复;"; }
  321. }
  322. if (tblMember.Rows[i]["门市"].ToString().Trim().Length > 15)
  323. { StrMages += "门市长度超过15;"; }
  324. if (tblMember.Rows[i]["客户类别"].ToString().Trim().Length > 20)
  325. { StrMages += "客户类别长度超过20;"; }
  326. if (tblMember.Rows[i]["业务意向"].ToString().Trim().Length > 8)
  327. { StrMages += "业务意向长度超过8;"; }
  328. if (tblMember.Rows[i]["来单医院"].ToString().Trim().Length > 200)
  329. { StrMages += "来单医院长度超过200;"; }
  330. if (tblMember.Rows[i]["客户区域"].ToString().Trim().Length > 20)
  331. { StrMages += "客户区域长度超过20;"; }
  332. if (tblMember.Rows[i]["业务种类"].ToString().Trim().Length > 8)
  333. { StrMages += "业务种类长度超过8;"; }
  334. if (string.IsNullOrEmpty(tblMember.Rows[i]["客户姓名"].ToString().Trim()))
  335. { StrMages += "客户姓名为空;"; }
  336. else if (tblMember.Rows[i]["客户姓名"].ToString().Trim().Length > 20)
  337. { StrMages += "客户姓名长度超过20;"; }
  338. if (tblMember.Rows[i]["客户QQ"].ToString().Trim().Length > 15)
  339. { StrMages += "客户QQ长度超过15;"; }
  340. if (!string.IsNullOrEmpty(tblMember.Rows[i]["本人手机"].ToString().Trim()))
  341. {
  342. if (tblMember.Rows[i]["本人手机"].ToString().Trim().Length != 11)
  343. { StrMages += "本人手机长度错误;"; }
  344. }
  345. if (!string.IsNullOrEmpty(tblMember.Rows[i]["老公手机"].ToString().Trim()))
  346. {
  347. if (tblMember.Rows[i]["老公手机"].ToString().Trim().Length != 11)
  348. { StrMages += "老公手机长度错误;"; }
  349. }
  350. if (string.IsNullOrEmpty(tblMember.Rows[i]["生日类型"].ToString().Trim()))
  351. { StrMages += "生日类型为空;"; }
  352. else if (tblMember.Rows[i]["生日类型"].ToString().Trim().Length > 10)
  353. { StrMages += "生日类型长度超过10;"; }
  354. if (!string.IsNullOrEmpty(tblMember.Rows[i]["生日类型"].ToString().Trim()))
  355. {
  356. if (tblMember.Rows[i]["生日类型"].ToString().Trim() == "宝宝生日")
  357. {
  358. if (!string.IsNullOrEmpty(tblMember.Rows[i]["宝宝姓名"].ToString().Trim()))
  359. {
  360. if (tblMember.Rows[i]["宝宝姓名"].ToString().Trim().Length > 20)
  361. { StrMages += "宝宝姓名长度超过20;"; }
  362. if (string.IsNullOrEmpty(tblMember.Rows[i]["宝宝性别"].ToString().Trim()))
  363. { StrMages += "宝宝性别为空;"; }
  364. else if (tblMember.Rows[i]["宝宝性别"].ToString().Trim().Length > 2)
  365. { StrMages += "宝宝性别长度超过2;"; }
  366. if (tblMember.Rows[i]["宝宝性别"].ToString().Trim() != "男" && tblMember.Rows[i]["宝宝性别"].ToString().Trim() != "女")
  367. { StrMages += "宝宝性别输入错误;"; }
  368. }
  369. if (tblMember.Rows[i]["喂养方式"].ToString().Trim().Length > 20)
  370. { StrMages += "喂养方式长度超过20;"; }
  371. if (!string.IsNullOrEmpty(tblMember.Rows[i]["宝宝生日/预产期"].ToString().Trim()))
  372. {
  373. if (!string.IsNullOrEmpty(LYFZ.Command.Command_Validate.DateTimeToString(tblMember.Rows[i]["宝宝生日/预产期"])))
  374. {
  375. if (tblMember.Rows[i]["生日是否农历"].ToString().Trim().Length > 2)
  376. { StrMages += "生日是否农历长度超过2;"; }
  377. if (!string.IsNullOrEmpty(tblMember.Rows[i]["生日是否农历"].ToString().Trim()))
  378. {
  379. if (tblMember.Rows[i]["生日是否农历"].ToString().Trim() != "公历" && tblMember.Rows[i]["生日是否农历"].ToString().Trim() != "公历")
  380. { StrMages += "生日是否农历输入错误;"; }
  381. }
  382. }
  383. else
  384. { StrMages += "宝宝生日格式错误;"; }
  385. }
  386. }
  387. else if (tblMember.Rows[i]["生日类型"].ToString().Trim() == "预产期")
  388. {
  389. if (!string.IsNullOrEmpty(tblMember.Rows[i]["宝宝生日/预产期"].ToString().Trim()))
  390. {
  391. if (!string.IsNullOrEmpty(LYFZ.Command.Command_Validate.DateTimeToString(tblMember.Rows[i]["宝宝生日/预产期"])))
  392. { }
  393. else
  394. { StrMages += "预产期格式错误;"; }
  395. }
  396. if (!string.IsNullOrEmpty(tblMember.Rows[i]["怀孕周数"].ToString().Trim()))
  397. {
  398. try { Convert.ToInt32(tblMember.Rows[i]["怀孕周数"].ToString().Trim()); }
  399. catch
  400. { StrMages += "怀孕周数格式错误;"; }
  401. }
  402. }
  403. else
  404. { StrMages += "生日类型输入错误;"; }
  405. }
  406. if (tblMember.Rows[i]["自家地址"].ToString().Trim().Length > 250)
  407. { StrMages += "自家地址长度超过250;"; }
  408. if (!string.IsNullOrEmpty(tblMember.Rows[i]["自家邮编"].ToString().Trim()))
  409. {
  410. if (tblMember.Rows[i]["自家邮编"].ToString().Trim().Length != 6)
  411. { StrMages += "自家邮编长度超过不正确;"; }
  412. }
  413. if (tblMember.Rows[i]["自家电话"].ToString().Trim().Length > 13)
  414. { StrMages += "自家电话长度超过13;"; }
  415. if (tblMember.Rows[i]["婆家地址"].ToString().Trim().Length > 250)
  416. { StrMages += "婆家地址长度超过250;"; }
  417. if (!string.IsNullOrEmpty(tblMember.Rows[i]["婆家邮编"].ToString().Trim()))
  418. {
  419. if (tblMember.Rows[i]["婆家邮编"].ToString().Trim().Length != 6)
  420. { StrMages += "婆家邮编长度超过不正确;"; }
  421. }
  422. if (tblMember.Rows[i]["婆家电话"].ToString().Trim().Length > 13)
  423. { StrMages += "婆家电话长度超过13;"; }
  424. if (tblMember.Rows[i]["娘家地址"].ToString().Trim().Length > 250)
  425. { StrMages += "娘家地址长度超过250;"; }
  426. if (!string.IsNullOrEmpty(tblMember.Rows[i]["娘家邮编"].ToString().Trim()))
  427. {
  428. if (tblMember.Rows[i]["娘家邮编"].ToString().Trim().Length != 6)
  429. { StrMages += "娘家邮编长度超过不正确;"; }
  430. }
  431. if (tblMember.Rows[i]["娘家电话"].ToString().Trim().Length > 13)
  432. { StrMages += "娘家电话长度超过13;"; }
  433. if (!string.IsNullOrEmpty(tblMember.Rows[i]["来单日期"].ToString().Trim()))
  434. {
  435. if (string.IsNullOrEmpty(LYFZ.Command.Command_Validate.DateTimeToString(tblMember.Rows[i]["来单日期"])))
  436. { StrMages += "来单日期格式错误;"; }
  437. }
  438. if (tblMember.Rows[i]["来单备注"].ToString().Trim().Length > 700)
  439. { StrMages += "来单备注长度超过700;"; }
  440. if (!string.IsNullOrEmpty(StrMages))
  441. { htData[tblMember.Rows[i]] = StrMages; }
  442. }
  443. #endregion
  444. backgroundWorker.ReportProgress(0, "正在处理数据...");
  445. DataTable NewTable = new DataTable();
  446. for (int i = 0; i <= tblMember.Columns.Count; i++)
  447. {
  448. if (i == tblMember.Columns.Count)
  449. { NewTable.Columns.Add("错误说明", typeof(string)); }
  450. else
  451. { NewTable.Columns.Add(tblMember.Columns[i].ColumnName.Trim(), typeof(string)); }
  452. }
  453. foreach (DictionaryEntry item in htData)
  454. {
  455. try
  456. {
  457. DataRow dtRow = (DataRow)item.Key;
  458. DataRow newRow = NewTable.NewRow();
  459. for (int j = 0; j < dtRow.Table.Columns.Count; j++)
  460. {
  461. switch (dtRow.Table.Columns[j].ColumnName.Trim())
  462. {
  463. //case "宝宝生日/预产期":
  464. //case "来单日期":
  465. // if (!string.IsNullOrEmpty(dtRow[dtRow.Table.Columns[j].ColumnName.Trim()].ToString().Trim()))
  466. // { newRow[dtRow.Table.Columns[j].ColumnName.Trim()] = Convert.ToDateTime(dtRow[dtRow.Table.Columns[j].ColumnName.Trim()]).ToString("yyyy-MM-dd"); }
  467. // else
  468. // { newRow[dtRow.Table.Columns[j].ColumnName.Trim()] = ""; }
  469. // break;
  470. default:
  471. newRow[dtRow.Table.Columns[j].ColumnName.Trim()] = dtRow[dtRow.Table.Columns[j].ColumnName.Trim()].ToString().Trim();
  472. break;
  473. }
  474. }
  475. newRow["错误说明"] = item.Value.ToString().Trim();
  476. NewTable.Rows.Add(newRow);
  477. tblMember.Rows.Remove(dtRow);
  478. }
  479. catch
  480. { }
  481. }
  482. try
  483. {
  484. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  485. {
  486. this.dgvData.DataSource(tblMember, DataSourceTopCount: 950);
  487. newDt = tblMember;
  488. }));
  489. }
  490. catch
  491. { }
  492. if (NewTable.Rows.Count > 0)
  493. {
  494. StringPath = System.IO.Path.GetDirectoryName(openFileDialog1.FileName) + "\\" + System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
  495. string StrFilePath = StringPath + "_有问题数据.xls"; //+ System.IO.Path.GetExtension(openFileDialog1.FileName);
  496. backgroundWorker.ReportProgress(0, "正在导出有问题数据...");
  497. //bool IsTrue = LYFZ.Command.Command_ExportExcel.DataTable2Sheet(StrFilePath, NewTable, "Sheet1", IsCoveredExistingFile: true);
  498. bool IsTrue = LYFZ.WinAPI.CustomPublicMethod.DataGridViewToExcel(StrFilePath, NewTable, null, backgroundWorker);
  499. if (IsTrue)
  500. {
  501. try
  502. {
  503. this.Invoke(new LYFZ.Software.MainBusiness.DoorCityProcess.PublicCodeClasses.UpdateControl(delegate()
  504. { MessageBoxCustom.Show("检查数据完毕!\r\n要导入的Excel中有问题数据已挑出另存于:\r\n" + StrFilePath); }));
  505. }
  506. catch
  507. { }
  508. }
  509. }
  510. });
  511. }
  512. catch
  513. { }
  514. //dgvExcel.DataSource(dt);
  515. //for (int i = 0; i < this.dgvExcel.Columns.Count; i++)
  516. //{ this.dgvExcel.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable; }
  517. }
  518. }
  519. }
  520. catch (Exception ex)
  521. { MessageBoxCustom.Show(ex.Message); }
  522. }
  523. /// <summary>
  524. /// 生成来单编号
  525. /// </summary>
  526. public string GenerationNumber(int IndexCount = 0)
  527. {
  528. string StrNumber = "";
  529. DataTable dt = orbll.GetView_Custom("tb_ErpHospitalClient", filedOrder: "Hct_Oddnumber desc", ShowColumnName: "Hct_Oddnumber", TopCount: 1).Tables[0];
  530. if (dt.Rows.Count > 0)
  531. {
  532. string[] Strshu = dt.Rows[0]["Hct_Oddnumber"].ToString().Split('-');
  533. if (Convert.ToInt32(Strshu[0].ToString()) >= Convert.ToInt32(SDateTime.Now.ToString("yyyyMMdd")))
  534. { StrNumber = Strshu[0].ToString() + "-" + (Convert.ToInt32(Strshu[1]) + 1 + IndexCount).ToString("d4"); }
  535. else
  536. { StrNumber = SDateTime.Now.ToString("yyyyMMdd") + "-" + (1 + IndexCount).ToString("d4"); }
  537. }
  538. else
  539. { StrNumber = SDateTime.Now.ToString("yyyyMMdd") + "-" + (1 + IndexCount).ToString("d4"); ; }
  540. return StrNumber;
  541. }
  542. /// <summary>
  543. /// /
  544. /// </summary>
  545. /// <param name="lie"></param>
  546. /// <returns></returns>
  547. public string StrDianhua(string lie)
  548. {
  549. string str = "";
  550. for (int i = 0; i < dgvData.Rows.Count; i++)
  551. {
  552. str += "'" + dgvData.Rows[i].Cells[lie].Value.ToString().Trim() + "',";
  553. }
  554. str = str.Substring(0, str.Length - 1);
  555. return str;
  556. }
  557. }
  558. }