//등록 public int insert(ChartVo chartVo) { int result = 0; using (SQLiteConnection conn = new SQLiteConnection(connStr)) { conn.Open(); StringBuilder sb = new StringBuilder(); sb.Append("insert into chart ( date "); //날자 sb.Append(" ,d2Dps "); //예수금(D2) sb.Append(" ,dpsastTotamt "); //예탁자산총액 sb.Append(" ,mamt "); //매입금액 sb.Append(" ,balEvalAmt "); //매입평가금액 sb.Append(" ,pnlRat "); //손익율 sb.Append(" ,tdtsunik "); //평가손익 sb.Append(" ,dtsunik "); //실현손익 sb.Append(" ,battingAtm "); //배팅금액 sb.Append(" ,toDaysunik "); //당일매도 실현손익 sb.Append(" ,dtsunik2 "); //실현손익2 sb.Append(" ,investmentRatio "); //투자율 sb.Append(" ,itemTotalCnt "); //계좌잔고(매수종목수) sb.Append(" ,buyFilterCnt "); //매수금지종목수 sb.Append(" ,buyCnt "); //매수횟수 sb.Append(" ,sellCnt "); //매도횟수 sb.Append(" )VALUES( "); sb.Append(" '" + chartVo.date + "' "); //날자 sb.Append(" ,'" + chartVo.d2Dps + "' "); //예수금(D2) sb.Append(" ,'" + chartVo.dpsastTotamt + "' "); //예탁자산총액 sb.Append(" ,'" + chartVo.mamt + "' "); //매입금액 sb.Append(" ,'" + chartVo.balEvalAmt + "' "); //매입평가금액 sb.Append(" ,'" + chartVo.pnlRat + "' "); //손익율 sb.Append(" ,'" + chartVo.tdtsunik + "' "); //평가손익 sb.Append(" ,'" + chartVo.dtsunik + "' "); //실현손익 sb.Append(" ,'" + chartVo.battingAtm + "' "); //배팅금액 sb.Append(" ,'" + chartVo.toDaysunik + "' "); //당일매도 실현손익 sb.Append(" ,'" + chartVo.dtsunik2 + "' "); //실현손익2 sb.Append(" ,'" + chartVo.investmentRatio + "' "); //투자율 sb.Append(" ,'" + chartVo.itemTotalCnt + "' "); //계좌잔고(매수종목수) sb.Append(" ,'" + chartVo.buyFilterCnt + "' "); //매수금지종목수 sb.Append(" ,'" + chartVo.buyCnt + "' "); //매수횟수 sb.Append(" ,'" + chartVo.sellCnt + "' ) "); //매도횟수 SQLiteCommand sqlCmd = new SQLiteCommand(sb.ToString(), conn); result = sqlCmd.ExecuteNonQuery(); sqlCmd.Dispose(); conn.Close(); conn.Dispose(); } return(result); }
////수정 public int update(ChartVo chartVo) { int result = 0; using (var conn = new SQLiteConnection(connStr)) { conn.Open(); StringBuilder sb = new StringBuilder(); sb.Append("UPDATE chart SET "); sb.Append(" date = '" + chartVo.date + "' "); //날자 sb.Append(" ,d2Dps = '" + chartVo.d2Dps + "' "); //예수금(D2) sb.Append(" ,dpsastTotamt = '" + chartVo.dpsastTotamt + "' "); //예탁자산총액 sb.Append(" ,mamt = '" + chartVo.mamt + "' "); //매입금액 sb.Append(" ,balEvalAmt = '" + chartVo.balEvalAmt + "' "); //매입평가금액 sb.Append(" ,pnlRat = '" + chartVo.pnlRat + "' "); //손익율 sb.Append(" ,tdtsunik = '" + chartVo.tdtsunik + "' "); //평가손익 sb.Append(" ,dtsunik = '" + chartVo.dtsunik + "' "); //실현손익 sb.Append(" ,battingAtm = '" + chartVo.battingAtm + "' "); //배팅금액 sb.Append(" ,toDaysunik = '" + chartVo.toDaysunik + "' "); //당일매도 실현손익 sb.Append(" ,dtsunik2 = '" + chartVo.dtsunik2 + "' "); //실현손익2 sb.Append(" ,investmentRatio = '" + chartVo.investmentRatio + "' "); //투자율 sb.Append(" ,itemTotalCnt = '" + chartVo.itemTotalCnt + "' "); //계좌잔고(매수종목수) sb.Append(" ,buyFilterCnt = '" + chartVo.buyFilterCnt + "' "); //매수금지종목수 sb.Append(" ,buyCnt = '" + chartVo.buyCnt + "' "); //매수횟수 sb.Append(" ,sellCnt = '" + chartVo.sellCnt + "' "); //매도횟수 sb.Append("WHERE date = '" + chartVo.date + "' "); //날자 SQLiteCommand sqlCmd = new SQLiteCommand(sb.ToString(), conn); //Log.WriteLine(sb.ToString()); result = sqlCmd.ExecuteNonQuery(); sqlCmd.Dispose(); conn.Close(); conn.Dispose(); } return(result); }
//일일 성과및 상태 저장 public void dayCapture() { DataRow tmpRow = tradingInfoDt.Rows[0]; ChartVo chartVo = new ChartVo(); chartVo.date = DateTime.Now.ToString("yyyy-MM-dd"); //날자 chartVo.d2Dps = Double.Parse(tmpRow["예수금(D2)"].ToString()); //예수금(D2) chartVo.dpsastTotamt = Double.Parse(tmpRow["예탁자산총액"].ToString()); //예탁자산총액 chartVo.mamt = Double.Parse(tmpRow["매입금액"].ToString()); //매입금액 chartVo.balEvalAmt = Double.Parse(tmpRow["평가금액"].ToString()); //매입평가금액 chartVo.pnlRat = Double.Parse(tmpRow["수익률"].ToString()); //손익율 chartVo.tdtsunik = Double.Parse(tmpRow["평가손익"].ToString()); //평가손익 chartVo.dtsunik = Double.Parse(tmpRow["실현손익"].ToString()); //실현손익 chartVo.battingAtm = double.Parse(Properties.Settings.Default.BUY_BATTING_AMT) * 10000; //배팅금액 //chartVo.toDaysunik = Double.Parse(this.label_toDaysunik.Text.Replace(",", "")); //당일매도 실현손익 //chartVo.dtsunik2 = Double.Parse(this.label_dtsunik2.Text.Replace(",", "")); //실현손익2 chartVo.investmentRatio = Double.Parse(tmpRow["투자율"].ToString()); //투자율 chartVo.itemTotalCnt = Double.Parse(this.h_totalCount.Text); //총 보유종목 수 //chartVo.buyFilterCnt = Double.Parse(this.exCnt.Text); //매수금지종목수 chartVo.buyCnt = Double.Parse(this.label_buyCnt.Text); //매수횟수 chartVo.sellCnt = Double.Parse(this.label_sellCnt.Text.Replace(",", "")); //매도횟수 int findIndex = this.chartData.getChartVoList().Find("date", chartVo.date); if (findIndex >= 0) { this.chartData.update(chartVo); } else { this.chartData.insert(chartVo); } this.chartData.dbSync(); //누적수익율 출력 //this.tradingInfoDt.Rows[0]["누적수익금"] = Util.GetNumberFormat(this.chartData.getSumDtsunik()); }
public void dbSync() { //this.historyDataTable = list(); if (chartVoList == null) { this.chartVoList = new EBindingList <ChartVo>(); } this.dataTable = list(); this.chartVoList.Clear(); foreach (DataRow dr in dataTable.Rows) { ChartVo chartVo = new ChartVo(); chartVo.date = dr["date"].ToString(); //날자 chartVo.d2Dps = Double.Parse(dr["d2Dps"].ToString()); //예수금(D2) chartVo.dpsastTotamt = Double.Parse(dr["dpsastTotamt"].ToString()); //예탁자산총액 chartVo.mamt = Double.Parse(dr["mamt"].ToString()); //매입금액 chartVo.balEvalAmt = Double.Parse(dr["balEvalAmt"].ToString()); //매입평가금액 chartVo.pnlRat = Double.Parse(dr["pnlRat"].ToString()); //손익율 chartVo.tdtsunik = Double.Parse(dr["tdtsunik"].ToString()); //평가손익 chartVo.dtsunik = Double.Parse(dr["dtsunik"].ToString()); //실현손익 chartVo.battingAtm = Double.Parse(dr["battingAtm"].ToString()); //배팅금액 chartVo.toDaysunik = Double.Parse(dr["toDaysunik"].ToString()); //당일매도 실현손익 chartVo.dtsunik2 = Double.Parse(dr["dtsunik2"].ToString()); //실현손익2 chartVo.investmentRatio = Double.Parse(dr["investmentRatio"].ToString()); //투자율 chartVo.itemTotalCnt = Double.Parse(dr["itemTotalCnt"].ToString()); //계좌잔고(매수종목수) chartVo.buyFilterCnt = Double.Parse(dr["buyFilterCnt"].ToString()); //매수금지종목수 chartVo.buyCnt = Double.Parse(dr["buyCnt"].ToString()); //매수횟수 chartVo.sellCnt = Double.Parse(dr["sellCnt"].ToString()); //매도횟수 this.chartVoList.Add(chartVo); } //누적 실현손익 구한다. this.sumDtsunik = dataTable.AsEnumerable().Select(row => double.Parse(row["dtsunik"].ToString())).Sum(); }