public static void WriteClosingPrices(List <ClosingPriceInfo> input) { FileService.CheckAppFolder(); if (input.Count == 0) { return; } string insCode = input[0].InsCode.ToString(); //List<ClosingPriceInfo> closingPriceInfoList1 = new List<ClosingPriceInfo>(); // unused List <ClosingPriceInfo> closingPriceInfoList2 = new List <ClosingPriceInfo>(); List <ClosingPriceInfo> closingPriceInfoList3 = FileService.ClosingPrices(Convert.ToInt64(insCode)); foreach (ClosingPriceInfo closingPriceInfo in input) { closingPriceInfoList2.Add(closingPriceInfo); } using (List <ClosingPriceInfo> .Enumerator enumerator = closingPriceInfoList3.GetEnumerator()) { while (enumerator.MoveNext()) { ClosingPriceInfo item = enumerator.Current; if (closingPriceInfoList2.Find((Predicate <ClosingPriceInfo>)(p => p.DEven == item.DEven)) == null) { closingPriceInfoList2.Add(item); } } } closingPriceInfoList2.Sort((Comparison <ClosingPriceInfo>)((s1, s2) => s1.DEven.CompareTo(s2.DEven))); using (TextWriter text = File.CreateText(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\TseClient 2.0\\Files\\Instruments\\" + insCode + ".csv")) { foreach (ClosingPriceInfo closingPriceInfo in closingPriceInfoList2) { text.Write(closingPriceInfo.InsCode); text.Write(','); text.Write(closingPriceInfo.DEven); text.Write(','); text.Write(closingPriceInfo.PClosing); text.Write(','); text.Write(closingPriceInfo.PDrCotVal); text.Write(','); text.Write(closingPriceInfo.ZTotTran); text.Write(','); text.Write(closingPriceInfo.QTotTran5J); text.Write(','); text.Write(closingPriceInfo.QTotCap); text.Write(','); text.Write(closingPriceInfo.PriceMin); text.Write(','); text.Write(closingPriceInfo.PriceMax); text.Write(','); text.Write(closingPriceInfo.PriceYesterday); text.Write(','); text.Write(closingPriceInfo.PriceFirst); text.Write('\n'); } text.Flush(); } }
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); } }