public static int OutputFileLastDeven(InstrumentInfo instrument, int indexOfDate, bool isShamsiDate) { FileService.CheckAppFolder(); int num = 0; try { Settings settings = new Settings(); string storageLocation = settings.StorageLocation; if (settings.AdjustPricesCondition == 1 || settings.AdjustPricesCondition == 2) { storageLocation = settings.AdjustedStorageLocation; } string ext = settings.FileExtension; string filename = GetFilename(instrument, settings.FileName, settings.AdjustPricesCondition); filename = SafeWinFilename(filename); string filepath = storageLocation + "\\" + filename + "." + ext; if (!File.Exists(filepath)) { return(0); } using (StreamReader streamReader = new StreamReader(File.OpenRead(filepath))) { string str = ""; while (!streamReader.EndOfStream) { str = streamReader.ReadLine(); } string[] strArray = str.Split(','); num = isShamsiDate ? Utility.ConvertJalaliStringToGregorianInt(strArray[indexOfDate].ToString()) : Convert.ToInt32(strArray[indexOfDate].ToString()); } } catch (Exception ex) { } return(num); }
public static string GetFilename(InstrumentInfo instrument, string filenameType, int AdjustPricesCondition) { string YMarNSC = instrument.YMarNSC; string filename = ""; switch (Convert.ToInt32(filenameType)) { case 0: filename = instrument.CIsin + GetSuffix(YMarNSC, AdjustPricesCondition); break; case 1: filename = instrument.LatinName + GetSuffix(YMarNSC, AdjustPricesCondition); break; case 2: filename = instrument.LatinSymbol + GetSuffix(YMarNSC, AdjustPricesCondition); break; case 3: filename = instrument.Name + GetSuffix(YMarNSC, AdjustPricesCondition, true); break; case 4: filename = instrument.Symbol + GetSuffix(YMarNSC, AdjustPricesCondition, true); break; default: filename = instrument.CIsin + GetSuffix(YMarNSC, AdjustPricesCondition); break; } return(filename); }
private bool GnerateFiles() { try { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type Settings settings = new Settings(); if (string.IsNullOrEmpty(settings.StorageLocation) || !Directory.Exists(settings.StorageLocation)) { return(false); } int startDeven = 0; settings.StartDate.Replace("/", "").ToString(); DateTime dateTime = Utility.ConvertJalaliStringToDateTime(settings.StartDate); startDeven = dateTime.Year * 10000 + dateTime.Month * 100 + dateTime.Day; int num1 = 0; using (List <string> .Enumerator enumerator = StaticData.SelectedInstruments.GetEnumerator()) { while (enumerator.MoveNext()) { string item = enumerator.Current; List <ClosingPriceInfo> cp = FileService.ClosingPrices(Convert.ToInt64(item)); cp = cp.FindAll((Predicate <ClosingPriceInfo>)(p => p.DEven >= startDeven)); if ((settings.AdjustPricesCondition == 1 || settings.AdjustPricesCondition == 2) && cp.Count > 1) { List <ClosingPriceInfo> closingPriceInfoList = new List <ClosingPriceInfo>(); Decimal num2 = new Decimal(1); closingPriceInfoList.Add(cp[cp.Count - 1]); double num3 = 0.0; if (settings.AdjustPricesCondition == 1) { for (int index = cp.Count - 2; index >= 0; --index) { if (cp[index].PClosing != cp[index + 1].PriceYesterday) { ++num3; } } } if (settings.AdjustPricesCondition == 1 && num3 / (double)cp.Count < 0.08 || settings.AdjustPricesCondition == 2) { for (int i = cp.Count - 2; i >= 0; --i) { if (settings.AdjustPricesCondition == 1 && cp[i].PClosing != cp[i + 1].PriceYesterday || settings.AdjustPricesCondition == 2 && cp[i].PClosing != cp[i + 1].PriceYesterday && StaticData.TseShares.Exists((Predicate <TseShareInfo>)(p => { if (p.InsCode.ToString().Equals(item)) { return(p.DEven == cp[i].DEven); } return(false); }))) { num2 = num2 * cp[i + 1].PriceYesterday / cp[i].PClosing; } closingPriceInfoList.Add(new ClosingPriceInfo() { InsCode = cp[i].InsCode, DEven = cp[i].DEven, PClosing = Math.Round(num2 * cp[i].PClosing, 2), PDrCotVal = Math.Round(num2 * cp[i].PDrCotVal, 2), ZTotTran = cp[i].ZTotTran, QTotTran5J = cp[i].QTotTran5J, QTotCap = cp[i].QTotCap, PriceMin = Math.Round(num2 * cp[i].PriceMin), PriceMax = Math.Round(num2 * cp[i].PriceMax), PriceYesterday = Math.Round(num2 * cp[i].PriceYesterday), PriceFirst = Math.Round(num2 * cp[i].PriceFirst, 2) }); } cp.Clear(); for (int index = closingPriceInfoList.Count - 1; index >= 0; --index) { cp.Add(closingPriceInfoList[index]); } } } InstrumentInfo instrument = StaticData.Instruments.Find((Predicate <InstrumentInfo>)(p => p.InsCode.ToString().Equals(item))); if (!settings.ExcelOutput) { FileService.WriteOutputFile(instrument, cp, !settings.RemoveOldFiles); } else { FileService.WriteOutputExcel(instrument, cp); } ++num1; } } return(true); } catch (Exception ex) { ServerMethods.LogError("UpdateClosingPrices", ex); try { if (FileService.LogErrorFile("[ Generating Output Files (" + StaticData.Version + ") ] " + ex.Message + "(" + (ex.InnerException != null ? ex.InnerException.Message ?? "" : "") + ")") == -1) { int num = (int)MessageBox.Show("مقدار فیلد محل ذخیره فایل ها صحیح نمی باشد "); } } catch { } return(false); } }
private bool UpdateClosingPrices() { // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type Settings settings = new Settings(); try { string str1 = ""; try { str1 = ServerMethods.LastPossibleDeven(); } catch (Exception ex) { ServerMethods.LogError("lastPossibleDEvens", ex); } string[] strArray1 = str1.Split(';'); int int32_1 = Convert.ToInt32(strArray1[0]); int int32_2 = Convert.ToInt32(strArray1[1]); long[][] numArray1 = new long[StaticData.SelectedInstruments.Count][]; int index1 = 0; using (List <string> .Enumerator enumerator = StaticData.SelectedInstruments.GetEnumerator()) { while (enumerator.MoveNext()) { string item = enumerator.Current; int num = FileService.LastDeven(item); InstrumentInfo instrumentInfo = StaticData.Instruments.Find((Predicate <InstrumentInfo>)(p => p.InsCode == Convert.ToInt64(item))); if ((!(instrumentInfo.YMarNSC == "NO") || num != int32_1) && (!(instrumentInfo.YMarNSC == "ID") || num != int32_2)) { numArray1[index1] = new long[3]; numArray1[index1][0] = Convert.ToInt64(item); numArray1[index1][1] = Convert.ToInt64(num); numArray1[index1][2] = instrumentInfo.YMarNSC == "NO" ? 0L : 1L; ++index1; } } } int num1 = index1 % 20 != 0 ? index1 / 20 + 1 : index1 / 20; for (int index2 = 0; index2 < num1; ++index2) { int length = index2 < num1 - 1 ? 20 : index1 % 20; long[][] numArray2 = new long[length][]; for (int index3 = 0; index3 < length; ++index3) { numArray2[index3] = new long[3]; numArray2[index3][0] = numArray1[index2 * 20 + index3][0]; numArray2[index3][1] = numArray1[index2 * 20 + index3][1]; numArray2[index3][2] = numArray1[index2 * 20 + index3][2]; } string str2 = ""; foreach (long[] numArray3 in numArray2) { str2 = str2 + (object)numArray3[0] + "," + (object)numArray3[1] + "," + (object)numArray3[2] + ";"; } string insturmentClosingPrice = ServerMethods.GetInsturmentClosingPrice(str2.Substring(0, str2.Length - 1)); char[] chArray = new char[1] { '@' }; foreach (string str3 in insturmentClosingPrice.Split(chArray)) { if (!string.IsNullOrEmpty(str3)) { List <ClosingPriceInfo> input = new List <ClosingPriceInfo>(); string[] strArray2 = str3.Split(';'); for (int index3 = 0; index3 < strArray2.Length; ++index3) { ClosingPriceInfo closingPriceInfo = new ClosingPriceInfo(); try { string[] strArray3 = strArray2[index3].Split(','); closingPriceInfo.InsCode = Convert.ToInt64(strArray3[0].ToString()); closingPriceInfo.DEven = Convert.ToInt32(strArray3[1].ToString()); closingPriceInfo.PClosing = Convert.ToDecimal(strArray3[2].ToString()); closingPriceInfo.PDrCotVal = Convert.ToDecimal(strArray3[3].ToString()); closingPriceInfo.ZTotTran = Convert.ToDecimal(strArray3[4].ToString()); closingPriceInfo.QTotTran5J = Convert.ToDecimal(strArray3[5].ToString()); closingPriceInfo.QTotCap = Convert.ToDecimal(strArray3[6].ToString()); closingPriceInfo.PriceMin = Convert.ToDecimal(strArray3[7].ToString()); closingPriceInfo.PriceMax = Convert.ToDecimal(strArray3[8].ToString()); closingPriceInfo.PriceYesterday = Convert.ToDecimal(strArray3[9].ToString()); closingPriceInfo.PriceFirst = Convert.ToDecimal(strArray3[10].ToString()); input.Add(closingPriceInfo); } catch (Exception ex) { ServerMethods.LogError("UpdateClosingPrices[Row:" + strArray2[index3] + "]", ex); throw ex; } } FileService.WriteClosingPrices(input); } } } return(true); } catch (Exception ex) { if (ex.Message.Contains("The magic number in GZip header is not correct")) { if (settings.EnableDecompression) { settings.EnableDecompression = false; settings.Save(); return(false); } } try { if (FileService.LogErrorFile("[ UpdateClosingPrices (" + StaticData.Version + ") ] " + ex.Message + "(" + (ex.InnerException != null ? ex.InnerException.Message ?? "" : "") + ")") == -1) { int num = (int)MessageBox.Show("مقدار فیلد محل ذخیره فایل ها صحیح نمی باشد "); } } catch { } return(false); } }
public bool GnerateFiles() { try { if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tایجاد فایلهای خروجی ... "); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); this.progressBar.Value = 0; this.lblProgress.Text = "0%"; Application.DoEvents(); } Settings settings = new Settings(); int cond = settings.AdjustPricesCondition; string path = cond != 0 ? settings.AdjustedStorageLocation : settings.StorageLocation; if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) { if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tمقدار فیلد محل ذخیره فایل ها صحیح نمی باشد "); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); } return(false); } int startDeven = 0; //settings.StartDate.Replace("/", "").ToString(); // unnecessary DateTime dateTime = Utility.ConvertJalaliStringToDateTime(settings.StartDate); startDeven = dateTime.Year * 10000 + dateTime.Month * 100 + dateTime.Day; int num1 = 0; using (List <string> .Enumerator enumerator = StaticData.SelectedInstruments.GetEnumerator()) { while (enumerator.MoveNext()) { string currentItemInscode = enumerator.Current; List <ClosingPriceInfo> cp = FileService.ClosingPrices(Convert.ToInt64(currentItemInscode)); cp = cp.FindAll((Predicate <ClosingPriceInfo>)(p => p.DEven >= startDeven)); if ((cond == 1 || cond == 2) && cp.Count > 1) { List <ClosingPriceInfo> closingPriceInfoList = new List <ClosingPriceInfo>(); Decimal num2 = new Decimal(1); closingPriceInfoList.Add(cp[cp.Count - 1]); double gaps = 0.0; if (cond == 1) { for (int index = cp.Count - 2; index >= 0; --index) { if (cp[index].PClosing != cp[index + 1].PriceYesterday) { ++gaps; } } } if (cond == 1 && gaps / cp.Count < 0.08 || cond == 2) { for (int i = cp.Count - 2; i >= 0; --i) { ClosingPriceInfo curr = cp[i]; ClosingPriceInfo next = cp[i + 1]; Predicate <TseShareInfo> aShareThatsDifferent = p => { if (p.InsCode.ToString().Equals(currentItemInscode)) { return(p.DEven == next.DEven); } return(false); }; bool pricesDontMatch = curr.PClosing != next.PriceYesterday; if (cond == 1 && pricesDontMatch) { num2 = num2 * next.PriceYesterday / curr.PClosing; } else if (cond == 2 && pricesDontMatch && StaticData.TseShares.Exists(aShareThatsDifferent)) { var something = StaticData.TseShares.Find(aShareThatsDifferent); decimal oldShares = something.NumberOfShareOld; decimal newShares = something.NumberOfShareNew; num2 = (num2 * oldShares) / newShares; } decimal close = Math.Round(num2 * curr.PClosing, 2), last = Math.Round(num2 * curr.PDrCotVal, 2), low = Math.Round(num2 * curr.PriceMin), high = Math.Round(num2 * curr.PriceMax), yday = Math.Round(num2 * curr.PriceYesterday), first = Math.Round(num2 * curr.PriceFirst, 2); closingPriceInfoList.Add(new ClosingPriceInfo() { InsCode = curr.InsCode, DEven = curr.DEven, PClosing = close, PDrCotVal = last, ZTotTran = curr.ZTotTran, QTotTran5J = curr.QTotTran5J, QTotCap = curr.QTotCap, PriceMin = low, PriceMax = high, PriceYesterday = yday, PriceFirst = first }); } cp.Clear(); for (int i = closingPriceInfoList.Count - 1; i >= 0; --i) { cp.Add(closingPriceInfoList[i]); } } } InstrumentInfo instrument = StaticData.Instruments.Find((Predicate <InstrumentInfo>)(p => p.InsCode.ToString().Equals(currentItemInscode))); if (!settings.ExcelOutput) { FileService.WriteOutputFile(instrument, cp, !this.chkRemoveOldFiles.Checked); } else { FileService.WriteOutputExcel(instrument, cp); } ++num1; if (this.isVisual) { this.progressBar.Value = Convert.ToInt32((double)num1 / (double)StaticData.SelectedInstruments.Count * 100.0); this.lblProgress.Text = Convert.ToInt32((double)num1 / (double)StaticData.SelectedInstruments.Count * 100.0).ToString() + "%"; this.rtbOperationLog.AppendText("\n\t\t " + instrument.Symbol + " (" + instrument.Name + ")"); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); Application.DoEvents(); } } } if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tعملیات ایجاد فایلهای خروجی با موفقیت انجام گردید."); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); } return(true); } catch (Exception ex) { if (this.isVisual) { this.rtbOperationLog.AppendText("\n\t"); this.rtbOperationLog.AppendText("\n\tعملیات ایجاد فایلهای خروجی ناموفق بود. "); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); } if (this.isVisual) { this.rtbOperationLog.AppendText(ServerMethods.LogError("UpdateClosingPrices", ex)); } else { ServerMethods.LogError("UpdateClosingPrices", ex); } try { if (FileService.LogErrorFile("[ Generating Output Files (" + StaticData.Version + ") ] " + ex.Message + "(" + (ex.InnerException != null ? ex.InnerException.Message ?? "" : "") + ")") == -1) { if (this.isVisual) { int num = (int)MessageBox.Show("مقدار فیلد محل ذخیره فایل ها صحیح نمی باشد "); } } } catch { if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tثبت خطا در فایل ناموفق بود"); } } return(false); } }
public bool UpdateClosingPrices() { Settings settings = new Settings(); try { if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tدریافت اطلاعات ... "); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); this.progressBar.Value = 0; this.lblProgress.Text = "0%"; Application.DoEvents(); } string lastPossibleDeven = ""; try { lastPossibleDeven = ServerMethods.LastPossibleDeven(); } catch (Exception ex) { ServerMethods.LogError("lastPossibleDEvens", ex); } if (lastPossibleDeven.Equals("*")) { if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات در حد فاصل ساعت هشت صبح تا یک بعد از ظهر روزهای شنبه تا چهارشنبه امکان پذیر نمی باشد."); this.rtbOperationLog.AppendText("\n\tجهت ساخت فایلها با اطلاعات فعلی از دکمه تعبیه شده در پایین صفحه استفاده کنید."); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); } return(false); } string[] strArray1 = lastPossibleDeven.Split(';'); int int32_1 = Convert.ToInt32(strArray1[0]); int int32_2 = Convert.ToInt32(strArray1[1]); long[][] numArray1 = new long[StaticData.SelectedInstruments.Count][]; int index1 = 0; using (List <string> .Enumerator enumerator = StaticData.SelectedInstruments.GetEnumerator()) { while (enumerator.MoveNext()) { string item = enumerator.Current; int num = FileService.LastDeven(item); InstrumentInfo instrumentInfo = StaticData.Instruments.Find((Predicate <InstrumentInfo>)(p => p.InsCode == Convert.ToInt64(item))); if ((!(instrumentInfo.YMarNSC == "NO") || num != int32_1) && (!(instrumentInfo.YMarNSC == "ID") || num != int32_2)) { numArray1[index1] = new long[3]; numArray1[index1][0] = Convert.ToInt64(item); numArray1[index1][1] = Convert.ToInt64(num); numArray1[index1][2] = instrumentInfo.YMarNSC == "NO" ? 0L : 1L; ++index1; } } } int num1 = index1 % 20 != 0 ? index1 / 20 + 1 : index1 / 20; for (int index2 = 0; index2 < num1; ++index2) { int length = index2 < num1 - 1 ? 20 : index1 % 20; if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tدریافت بخش " + (index2 + 1).ToString() + " از " + num1 + " اطلاعات ... "); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); Application.DoEvents(); if (length == 0) { this.progressBar.Value = 100; this.lblProgress.Text = "100%"; Application.DoEvents(); continue; } } long[][] numArray2 = new long[length][]; for (int index3 = 0; index3 < length; ++index3) { numArray2[index3] = new long[3]; numArray2[index3][0] = numArray1[index2 * 20 + index3][0]; numArray2[index3][1] = numArray1[index2 * 20 + index3][1]; numArray2[index3][2] = numArray1[index2 * 20 + index3][2]; } string insCodes = ""; foreach (long[] numArray3 in numArray2) { insCodes += numArray3[0] + "," + numArray3[1] + "," + numArray3[2] + ";"; } insCodes = insCodes.Substring(0, insCodes.Length - 1); string insturmentClosingPrice = ServerMethods.GetInsturmentClosingPrice(insCodes); if (insturmentClosingPrice.Equals("*")) { if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات در حد فاصل ساعت هشت صبح تا یک بعد از ظهر روزهای شنبه تا چهارشنبه امکان پذیر نمی باشد."); this.rtbOperationLog.AppendText("\n\tجهت ساخت فایلها با اطلاعات فعلی از دکمه تعبیه شده در پایین صفحه استفاده کنید."); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); } return(false); } string str3 = insturmentClosingPrice; char[] chArray = new char[1] { '@' }; foreach (string str4 in str3.Split(chArray)) { if (!string.IsNullOrEmpty(str4)) { List <ClosingPriceInfo> cpList = new List <ClosingPriceInfo>(); string[] strArray2 = str4.Split(';'); for (int index3 = 0; index3 < strArray2.Length; ++index3) { ClosingPriceInfo closingPriceInfo = new ClosingPriceInfo(); try { string[] strArray3 = strArray2[index3].Split(','); closingPriceInfo.InsCode = Convert.ToInt64(strArray3[0].ToString()); closingPriceInfo.DEven = Convert.ToInt32(strArray3[1].ToString()); closingPriceInfo.PClosing = Convert.ToDecimal(strArray3[2].ToString()); closingPriceInfo.PDrCotVal = Convert.ToDecimal(strArray3[3].ToString()); closingPriceInfo.ZTotTran = Convert.ToDecimal(strArray3[4].ToString()); closingPriceInfo.QTotTran5J = Convert.ToDecimal(strArray3[5].ToString()); closingPriceInfo.QTotCap = Convert.ToDecimal(strArray3[6].ToString()); closingPriceInfo.PriceMin = Convert.ToDecimal(strArray3[7].ToString()); closingPriceInfo.PriceMax = Convert.ToDecimal(strArray3[8].ToString()); closingPriceInfo.PriceYesterday = Convert.ToDecimal(strArray3[9].ToString()); closingPriceInfo.PriceFirst = Convert.ToDecimal(strArray3[10].ToString()); cpList.Add(closingPriceInfo); } catch (Exception ex) { ServerMethods.LogError("UpdateClosingPrices[Row:" + strArray2[index3] + "]", ex); throw ex; } } FileService.WriteClosingPrices(cpList); if (this.isVisual && cpList.Count > 0) { InstrumentInfo instrumentInfo = StaticData.Instruments.Find((Predicate <InstrumentInfo>)(p => p.InsCode == cpList[0].InsCode)); this.rtbOperationLog.AppendText("\n\t\tبروز رسانی اطلاعات " + instrumentInfo.Symbol + " (" + instrumentInfo.Name + ")"); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); } } } if (this.isVisual) { this.progressBar.Value = Convert.ToInt32((double)(index2 + 1) / (double)num1 * 100.0); this.lblProgress.Text = Convert.ToInt32((double)(index2 + 1) / (double)num1 * 100.0).ToString() + "%"; Application.DoEvents(); } } if (this.isVisual) { if (num1 == 0) { this.progressBar.Value = 100; this.lblProgress.Text = "100%"; Application.DoEvents(); } this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات نمادها با موفقیت انجام گردید\t "); this.rtbOperationLog.AppendText("\n\tجهت ایجاد خروجی جدید بر اساس اطلاعات بروز شده از دکمه تولید خروجی استفاده کنید "); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); } return(true); } catch (Exception ex) { if (ex.Message.Contains("The magic number in GZip header is not correct") && settings.EnableDecompression) { settings.EnableDecompression = false; settings.Save(); this.owner.TabSwitcher(Tabs.Update); return(false); } if (this.isVisual) { this.rtbOperationLog.AppendText("\n\tبروز رسانی اطلاعات نمادها ناموفق بود. "); this.rtbOperationLog.SelectionStart = this.rtbOperationLog.Text.Length; this.rtbOperationLog.ScrollToCaret(); this.rtbOperationLog.AppendText(ServerMethods.LogError(nameof(UpdateClosingPrices), ex)); } try { if (FileService.LogErrorFile("[ UpdateClosingPrices (" + StaticData.Version + ") ] " + ex.Message + "(" + (ex.InnerException != null ? ex.InnerException.Message ?? "" : "") + ")") == -1) { if (this.isVisual) { int num = (int)MessageBox.Show("مقدار فیلد محل ذخیره فایل ها صحیح نمی باشد "); } } } catch { this.rtbOperationLog.AppendText("\n\tثبت خطا در فایل ناموفق بود"); } return(false); } }
public static void WriteOutputExcel(InstrumentInfo instrument, List <ClosingPriceInfo> cp) { FileService.CheckAppFolder(); // ISSUE: object of a compiler-generated type is created // ISSUE: variable of a compiler-generated type Settings settings = new Settings(); string str1 = settings.StorageLocation; if (settings.AdjustPricesCondition == 1 || settings.AdjustPricesCondition == 2) { str1 = settings.AdjustedStorageLocation; } string str2; switch (Convert.ToInt32(settings.FileName)) { case 0: str2 = instrument.CIsin; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str2 += "-a"; break; } if (settings.AdjustPricesCondition == 2) { str2 += "-i"; break; } break; } break; case 1: str2 = instrument.LatinName; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str2 += "-a"; break; } if (settings.AdjustPricesCondition == 2) { str2 += "-i"; break; } break; } break; case 2: str2 = instrument.LatinSymbol; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str2 += "-a"; break; } if (settings.AdjustPricesCondition == 2) { str2 += "-i"; break; } break; } break; case 3: str2 = instrument.Name; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str2 += "-ت"; break; } if (settings.AdjustPricesCondition == 2) { str2 += "-ا"; break; } break; } break; case 4: str2 = instrument.Symbol; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str2 += "-ت"; break; } if (settings.AdjustPricesCondition == 2) { str2 += "-ا"; break; } break; } break; default: str2 = instrument.CIsin; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str2 += "-a"; break; } if (settings.AdjustPricesCondition == 2) { str2 += "-i"; break; } break; } break; } string str3 = str2.Replace('\\', ' ').Replace('/', ' ').Replace('*', ' ').Replace(':', ' ').Replace('>', ' ').Replace('<', ' ').Replace('?', ' ').Replace('|', ' ').Replace('^', ' ').Replace('"', ' '); List <ColumnInfo> columnInfoList = FileService.ColumnsInfo(); string file = str1 + "\\" + str3 + ".xls"; Workbook workbook = new Workbook(); Worksheet worksheet = new Worksheet(instrument.InstrumentID); columnInfoList.Sort((Comparison <ColumnInfo>)((s1, s2) => s1.Index.CompareTo(s2.Index))); int index1 = 0; int index2 = 0; if (settings.ShowHeaders) { foreach (ColumnInfo columnInfo in columnInfoList) { if (columnInfo.Visible) { worksheet.Cells[index1, index2] = new Cell((object)columnInfo.Header); ++index2; } } ++index1; } foreach (ClosingPriceInfo closingPriceInfo in cp) { if (settings.ExportDaysWithoutTrade || !(closingPriceInfo.ZTotTran == new Decimal(0))) { int index3 = 0; foreach (ColumnInfo columnInfo in columnInfoList) { if (columnInfo.Visible) { switch (columnInfo.Type) { case ColumnType.CompanyCode: worksheet.Cells[index1, index3] = new Cell((object)instrument.CompanyCode.ToString()); ++index3; continue; case ColumnType.LatinName: string str4 = ""; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str4 = "-a"; } else if (settings.AdjustPricesCondition == 2) { str4 = "-i"; } } worksheet.Cells[index1, index3] = new Cell((object)(instrument.LatinName.ToString() + str4)); ++index3; continue; case ColumnType.Symbol: string str5 = ""; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str5 = "-ت"; } else if (settings.AdjustPricesCondition == 2) { str5 = "-ا"; } } worksheet.Cells[index1, index3] = new Cell((object)(instrument.Symbol.ToString() + str5)); ++index3; continue; case ColumnType.Name: string str6 = ""; if (instrument.YMarNSC != "ID") { if (settings.AdjustPricesCondition == 1) { str6 = "-ت"; } else if (settings.AdjustPricesCondition == 2) { str6 = "-ا"; } } worksheet.Cells[index1, index3] = new Cell((object)(instrument.Name.ToString() + str6)); ++index3; continue; case ColumnType.Date: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.DEven.ToString()); ++index3; continue; case ColumnType.ShamsiDate: worksheet.Cells[index1, index3] = new Cell((object)Utility.ConvertGregorianIntToJalaliInt(closingPriceInfo.DEven).ToString()); ++index3; continue; case ColumnType.PriceFirst: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.PriceFirst.ToString()); ++index3; continue; case ColumnType.PriceMax: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.PriceMax.ToString()); ++index3; continue; case ColumnType.PriceMin: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.PriceMin.ToString()); ++index3; continue; case ColumnType.LastPrice: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.PDrCotVal.ToString()); ++index3; continue; case ColumnType.ClosingPrice: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.PClosing.ToString()); ++index3; continue; case ColumnType.Price: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.QTotCap.ToString()); ++index3; continue; case ColumnType.Volume: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.QTotTran5J.ToString()); ++index3; continue; case ColumnType.Count: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.ZTotTran.ToString()); ++index3; continue; case ColumnType.PriceYesterday: worksheet.Cells[index1, index3] = new Cell((object)closingPriceInfo.PriceYesterday.ToString()); ++index3; continue; default: continue; } } } ++index1; } } workbook.Worksheets.Add(worksheet); workbook.Save(file); }
public static void WriteOutputFile(InstrumentInfo instrument, List <ClosingPriceInfo> cp, bool appendExistingFile) { FileService.CheckAppFolder(); Settings settings = new Settings(); string storageLocation = settings.StorageLocation; if (settings.AdjustPricesCondition == 1 || settings.AdjustPricesCondition == 2) { storageLocation = settings.AdjustedStorageLocation; } string delimiter = settings.Delimeter.ToString(); string filename = GetFilename(instrument, settings.FileName, settings.AdjustPricesCondition); filename = SafeWinFilename(filename); string filepath = storageLocation + "\\" + filename + "." + settings.FileExtension; int outputFileLastDeven = 0; if (appendExistingFile) { if (!File.Exists(filepath)) { appendExistingFile = false; } else { int indexOfDate = 0; bool isShamsiDate = false; foreach (ColumnInfo columnInfo in StaticData.ColumnsInfo) { if (columnInfo.Type == ColumnType.Date && columnInfo.Visible) { indexOfDate = columnInfo.Index - 1; isShamsiDate = false; break; } if (columnInfo.Type == ColumnType.ShamsiDate && columnInfo.Visible) { indexOfDate = columnInfo.Index; isShamsiDate = true; } } outputFileLastDeven = FileService.OutputFileLastDeven(instrument, indexOfDate, isShamsiDate); } } List <ColumnInfo> columnInfoList = FileService.ColumnsInfo(); //Encoding utF8 = Encoding.UTF8; // unused Encoding encoding; switch (Convert.ToInt32(settings.Encoding)) { case 0: encoding = Encoding.Unicode; break; case 1: encoding = Encoding.UTF8; break; case 2: encoding = Encoding.GetEncoding(1256); break; default: encoding = Encoding.UTF8; break; } TextWriter textWriter = new StreamWriter(filepath, appendExistingFile, encoding); columnInfoList.Sort((Comparison <ColumnInfo>)((s1, s2) => s1.Index.CompareTo(s2.Index))); string headerRow = ""; if (settings.ShowHeaders && outputFileLastDeven == 0) { foreach (ColumnInfo columnInfo in columnInfoList) { if (columnInfo.Visible) { headerRow += columnInfo.Header; headerRow += delimiter; } } headerRow = headerRow.Substring(0, headerRow.Length - 1); textWriter.WriteLine(headerRow); } string YMarNSC = instrument.YMarNSC; int AdjustPricesCondition = settings.AdjustPricesCondition; foreach (ClosingPriceInfo closingPriceInfo in cp) { if ((!appendExistingFile || closingPriceInfo.DEven > outputFileLastDeven) && (settings.ExportDaysWithoutTrade || !(closingPriceInfo.ZTotTran == new Decimal(0)))) { string str = ""; foreach (ColumnInfo columnInfo in columnInfoList) { if (columnInfo.Visible) { switch (columnInfo.Type) { case ColumnType.CompanyCode: str += instrument.CompanyCode.ToString(); break; case ColumnType.LatinName: str += instrument.LatinName.ToString() + GetSuffix(YMarNSC, AdjustPricesCondition); break; case ColumnType.Symbol: str += instrument.Symbol.Replace(" ", "_").ToString() + GetSuffix(YMarNSC, AdjustPricesCondition, true); break; case ColumnType.Name: str += instrument.Name.Replace(" ", "_").ToString() + GetSuffix(YMarNSC, AdjustPricesCondition, true); break; case ColumnType.Date: str += closingPriceInfo.DEven.ToString(); break; case ColumnType.ShamsiDate: str += Utility.ConvertGregorianIntToJalaliInt(closingPriceInfo.DEven).ToString(); break; case ColumnType.PriceFirst: str += closingPriceInfo.PriceFirst.ToString(); break; case ColumnType.PriceMax: str += closingPriceInfo.PriceMax.ToString(); break; case ColumnType.PriceMin: str += closingPriceInfo.PriceMin.ToString(); break; case ColumnType.LastPrice: str += closingPriceInfo.PDrCotVal.ToString(); break; case ColumnType.ClosingPrice: str += closingPriceInfo.PClosing.ToString(); break; case ColumnType.Price: str += closingPriceInfo.QTotCap.ToString(); break; case ColumnType.Volume: str += closingPriceInfo.QTotTran5J.ToString(); break; case ColumnType.Count: str += closingPriceInfo.ZTotTran.ToString(); break; case ColumnType.PriceYesterday: str += closingPriceInfo.PriceYesterday.ToString(); break; } str += delimiter; } } str = str.Substring(0, str.Length - 1); textWriter.WriteLine(str); } } textWriter.Flush(); textWriter.Dispose(); }