Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public string GetName(string path, string fileType)
- {
- string[] sourcePath = Directory.GetFiles(path);
- Int64 yearMonth = (DateTime.Now.Year * 10000) + (DateTime.Now.Month * 100) + DateTime.Now.Day;
- string name = yearMonth + "-001";
- int pathNo2 = 0;
- string objt = db.FileCopyFromServers.Where(x => x.YearMonth == yearMonth && x.FileType == fileType).OrderByDescending(x => x.YearMonth).Select(x => x.FileName).FirstOrDefault();
- if (objt != null)
- {
- objt = objt.Substring(objt.Length - 7).Substring(0, 3);
- pathNo2 = Convert.ToInt32(objt) + 1;
- name = CovertName(pathNo2, yearMonth);
- }
- if (sourcePath.Length != 0)
- {
- string[] sptPath = sourcePath[sourcePath.Length - 1].Split('\\');
- int count = sptPath.Length;
- string temp = sptPath[count - 1].Substring(sptPath[count - 1].Length - 16).Substring(0, 12);
- sptPath = temp.Split('-');
- int pathNo1 = 0;
- int extnNumber = 0;
- int pathYearMonth;
- bool success = Int32.TryParse(sptPath[0], out pathYearMonth);
- if (success)
- {
- if (pathYearMonth == yearMonth || pathNo2 != 0)
- {
- if (pathNo2 != 0 && Convert.ToInt32(sptPath[0]) == yearMonth)
- {
- pathNo1 = Convert.ToInt32(sptPath[1]) + 1;
- extnNumber = pathNo1 < pathNo2 ? pathNo2 : pathNo1;
- }
- else if (Convert.ToInt32(sptPath[0]) == yearMonth)
- {
- extnNumber = Convert.ToInt32(sptPath[1]) + 1;
- }
- else if (pathNo2 != 0)
- {
- extnNumber = pathNo2;
- }
- name = CovertName(extnNumber, yearMonth);
- }
- }
- }
- return name;
- }
- public string CovertName(int extnNumber, Int64 yearMonth)
- {
- if (extnNumber < 10)
- {
- return yearMonth + "-00" + extnNumber;
- }
- else if (extnNumber < 100)
- {
- return yearMonth + "-0" + extnNumber;
- }
- else
- {
- return yearMonth + "-" + extnNumber;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement