# Region converts a date to the specified format // <summary> // converts the date to the yyyy-mm-dd format. /// </summary> /// <param name = "NDate"> date </param> /// <returns> returns the String object </returns> public string Date_Format (string NDate) {string sm, sd; int y, m, d; try {y = Convert. toDateTime (NDate ). year; m = Convert. toDateTime (NDate ). month; d = Convert. toDateTime (NDate ). day;} catch {return "";} if (y = 1900) return ""; if (m <10) sm = "0" + Con Vert. toString (m); else sm = Convert. toString (m); if (d <10) sd = "0" + Convert. toString (d); else sd = Convert. toString (d); return Convert. toString (y) + sm + sd ;} # endregion # region converts a date to a specified format // <summary> // converts a date to a yyyy-mm-dd format. /// </summary> /// <param name = "NDate"> date </param> /// <returns> returns the String object </returns> public string Date_Format _ (string NDate) {string sm, sd; int y, m, d; try {y = Co Nvert. toDateTime (NDate ). year; m = Convert. toDateTime (NDate ). month; d = Convert. toDateTime (NDate ). day;} catch {return "";} if (y = 1900) return ""; if (m <10) sm = "0" + Convert. toString (m); else sm = Convert. toString (m); if (d <10) sd = "0" + Convert. toString (d); else sd = Convert. toString (d); return Convert. toString (y) + "-" + sm + "-" + sd;} # endregion # region converts the time to a specified format. // <summary> // /Convert the time To hhmmss format. /// </summary> /// <param name = "NDate"> date </param> /// <returns> returns the String object </returns> public string Time_Format (string NDate) {string sh, sm, se; int hh, mm, ss; try {hh = Convert. toDateTime (NDate ). hour; mm = Convert. toDateTime (NDate ). minute; ss = Convert. toDateTime (NDate ). second;} catch {return "";} sh = Convert. toString (hh); if (sh. length <2) sh = "0" + sh; sm = Convert. toS Tring (mm); if (sm. length <2) sm = "0" + sm; se = Convert. toString (ss); if (se. length <2) se = "0" + se; return sh + sm + se;} # endregion # region returns the excel pathname internal string getExcelFileName () // open the excel file {string name = ""; try {OpenFileDialog openCsv = new OpenFileDialog (); openCsv. filter = "Excel file | *. xls ;*. csv ;*. et "; if (openCsv. showDialog () = DialogResult. OK) {name = openCsv. fileName; ret Urn name ;}} catch (OleDbException ode) {MessageBox. show (ode. toString (); return null;} catch (Exception exc) {MessageBox. show ("file not opened! "," Prompt ", MessageBoxButtons. OK, MessageBoxIcon. information); Console. writeLine (exc. toString ();} return null;} // open the file # endregion # region returns the time format to yyyymmddhhmmss 20130930074600 internal string changeDateTimeFormat (string cardTime) {string dateFormat = Date_Format (cardTime ); string timeFormat = Time_Format (cardTime); string dateAndTime = dateFormat + timeFormat; return dateAndTime;} # endregion