/* Complete details of all your trading with latest stock value Used in work sheet form */ public DataView WorkSheet() { DataTable dtWorkSheet = null; _lblMsgDoubleM.Text = "Reading database please wait.."; OleDbCommand cmdWorkSheet = new OleDbCommand(); try { cmdWorkSheet.Connection = _oConnDM; cmdWorkSheet.CommandType = CommandType.StoredProcedure; cmdWorkSheet.CommandText = "QryAllDetails"; OleDbDataAdapter daWorkSheet = new OleDbDataAdapter(cmdWorkSheet); dtWorkSheet = new DataTable("WorkSheet"); daWorkSheet.Fill(dtWorkSheet); return(new DataView(dtWorkSheet)); } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); return(null); } finally { _lblMsgDoubleM.Text = "Done"; if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } }
public DataTable TradingValue(string sSQL) { DataTable dtLatestValue = null; OleDbCommand cmdLatestView = new OleDbCommand(); try { cmdLatestView.Connection = _oConnDM; cmdLatestView.CommandType = CommandType.Text; cmdLatestView.CommandText = sSQL; OleDbDataAdapter daLatestView = new OleDbDataAdapter(cmdLatestView); dtLatestValue = new DataTable("TradingView"); //daLatestView.FillSchema(dtLatestValue, SchemaType.Source); daLatestView.Fill(dtLatestValue); // daLatestView.Fill(dtLatestValue); return(dtLatestValue); } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); return(null); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } //dtLatestValue.Dispose(); } }
public DataTable GraphSingle(int iStockID) { DataTable dtSingleGraph = null; OleDbCommand cmdSingleGraph = new OleDbCommand(); try { cmdSingleGraph.Connection = _oConnDM; cmdSingleGraph.CommandType = CommandType.StoredProcedure; cmdSingleGraph.CommandText = "QryGraph"; cmdSingleGraph.Parameters.Clear(); cmdSingleGraph.Parameters.Add("@StockID", OleDbType.Numeric).Value = iStockID; OleDbDataAdapter daSingleGraph = new OleDbDataAdapter(cmdSingleGraph); dtSingleGraph = new DataTable("strGraphSingle"); daSingleGraph.Fill(dtSingleGraph); //Console.WriteLine(dvShare.Table.Columns[1].DataType.ToString()); return(dtSingleGraph); } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); return(null); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } //dtLatestValue.Dispose(); } }
private void frmMain_Load(object sender, EventArgs e) { //scrtxtStock.BackgroundBrush = // new LinearGradientBrush(this.scrtxtStock.ClientRectangle, // Color.Red, Color.Blue, // LinearGradientMode.Horizontal); this.Icon = new Icon(this.GetType().Assembly.GetManifestResourceStream("DoubleM.Pics.der.ico")); CommonDoubleM.LoadAppConfig(); pBarDM.Visible = false; dtPKStart.Value = DateTime.Now.Date; scrtxtStock.BackgroundBrush = new LinearGradientBrush(this.scrtxtStock.ClientRectangle, Color.Black, Color.DarkSlateGray, LinearGradientMode.Horizontal); scrtxtStock.ScrollText = CommonDoubleM.MarqueeString; chkAfterBefore.Checked = true; /*Loading proxy Settings*/ chkProxy.Checked = CommonDoubleM._blnFirewll; txtProxySrvName.Text = CommonDoubleM._sProxy; txtUID.Text = CommonDoubleM._sUID; txtPWD.Text = CommonDoubleM._sPWD; ProxySettingInit(); ////////////////////////////////////// }
public static void RemoveSetting(string key) { // load config document for current assembly XmlDocument doc = loadConfigDocument(); // retrieve appSettings node XmlNode node = doc.SelectSingleNode("//appSettings"); try { if (node == null) { throw new InvalidOperationException("appSettings section not found in config file."); } else { // remove 'add' element with coresponding key node.RemoveChild(node.SelectSingleNode(string.Format("//add[@key='{0}']", key))); doc.Save(getConfigFilePath()); } } catch (NullReferenceException e) { //throw new Exception(string.Format("The key {0} does not exist.", key), e); CommonDoubleM.LogDM(string.Format("The key {0} does not exist.", key) + e.Message); } }
public DataTable StockAvgAfterSale() { DataTable dtAvgAfterSale = null; OleDbCommand cmdAvgAfterSale = new OleDbCommand(); try { cmdAvgAfterSale.Connection = _oConnDM; cmdAvgAfterSale.CommandType = CommandType.StoredProcedure; cmdAvgAfterSale.CommandText = "QryAvgAfterSale"; cmdAvgAfterSale.Parameters.Clear(); //Avg on Current data at 23h cmdAvgAfterSale.Parameters.Add("@Date", OleDbType.Date).Value = DateTime.Today.AddHours(23); OleDbDataAdapter daAvgAfterSale = new OleDbDataAdapter(cmdAvgAfterSale); dtAvgAfterSale = new DataTable("AvgAfterSale"); daAvgAfterSale.Fill(dtAvgAfterSale); return(dtAvgAfterSale); } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); return(null); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } }
public DataTable LatestValue() { DataTable dtLatestValue = null; OleDbCommand cmdLatestView = new OleDbCommand(); try { cmdLatestView.Connection = _oConnDM; cmdLatestView.CommandType = CommandType.StoredProcedure; cmdLatestView.CommandText = "QryCurrentStatus"; OleDbDataAdapter daLatestView = new OleDbDataAdapter(cmdLatestView); dtLatestValue = new DataTable("strSheetName"); //daLatestView.FillSchema(dtLatestValue, SchemaType.Source); daLatestView.Fill(dtLatestValue); // daLatestView.Fill(dtLatestValue); return(dtLatestValue); } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); return(null); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } //dtLatestValue.Dispose(); } }
internal int NewStock(int StockCatID, string StockName, string ShortName, string YFCode, string RCode, string BSECode, string HDFCCode, bool Active) { int iResult = -1; int iLatestStockId; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdStocks = _oConnDM.CreateCommand(); cmdStocks.Connection = _oConnDM; try { /* Update to TRates Table */ cmdStocks.CommandType = CommandType.StoredProcedure; cmdStocks.CommandText = "QryInsStocks"; cmdStocks.Parameters.Clear(); //Assign parameters should be in order cmdStocks.Parameters.Add("@StockCatID", OleDbType.Integer).Value = StockCatID; cmdStocks.Parameters.Add("@StockName", OleDbType.VarChar).Value = StockName; cmdStocks.Parameters.Add("@ShortName", OleDbType.VarChar).Value = ShortName; cmdStocks.Parameters.Add("@YFCode", OleDbType.VarChar).Value = YFCode; cmdStocks.Parameters.Add("@RCode", OleDbType.VarChar).Value = RCode; cmdStocks.Parameters.Add("@BSECode", OleDbType.VarChar).Value = BSECode; cmdStocks.Parameters.Add("@HDFCCode", OleDbType.VarChar).Value = HDFCCode; cmdStocks.Parameters.Add("@Active", OleDbType.Boolean).Value = Active; iResult = cmdStocks.ExecuteNonQuery(); /*Getting the latest PK from TRates Table */ //Another way to get the auto generated id cmdStocks.CommandType = CommandType.StoredProcedure; cmdStocks.CommandText = "QryGetAutoID"; cmdStocks.Parameters.Clear(); iLatestStockId = (int)cmdStocks.ExecuteScalar(); iResult = iLatestStockId; } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.Message + " was encountered while inserting the data."; CommonDoubleM.LogDM("New stock [" + StockName + "] has not been added."); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }
private void dgViewQ_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1 && e.RowIndex < dgViewQ.RowCount - 1) { CommonDoubleM.LogDM("Downloading rates for " + dgViewQ[0, e.RowIndex].Value.ToString()); blnSelectedUpdate = true; DowloadAllRates(); } else { _theParent.lblDMMsg.Text = "Please double click on valid rows.."; } }
private void WatchList_Design() { try { dgViewQ.Columns.Add("Stock Name", "Stock Name"); dgViewQ.Columns.Add("Shrs", "Shrs"); dgViewQ.Columns.Add("Current", "Current"); dgViewQ.Columns.Add("Avg", "Avg"); dgViewQ.Columns.Add("%", "%"); dgViewQ.Columns.Add("C%", "% Chg"); dgViewQ.Columns.Add("T Gain", "T Gain"); dgViewQ.Columns.Add("Paid", "Paid"); dgViewQ.Columns.Add("Last update", "Last update"); dgViewQ.Columns.Add("Active", "Active"); dgViewQ.Columns.Add("SID", "SID"); dgViewQ.Columns.Add("BSEID", "BSEID"); /* Data grid format display*/ dgViewQ.Columns[0].Width = 180; //Name dgViewQ.Columns[1].Width = 50; //Shrs - Total Qualtity dgViewQ.Columns[2].Width = 50; //Current Rate - Should be coming from BSE dgViewQ.Columns[3].Width = 60; //Avg Cost Price dgViewQ.Columns[4].Width = 50; // % Gain dgViewQ.Columns[5].Width = 60; // % Change dgViewQ.Columns[6].Width = 60; //T Gain need to be calculated dgViewQ.Columns[7].Width = 60; //Ammount Paid for the currect quantity dgViewQ.Columns[8].Width = 125; // Time on BSE dgViewQ.Columns[9].Width = 30; // Active dgViewQ.RowHeadersWidth = 60; dgViewQ.Columns[9].Visible = false; // Active dgViewQ.Columns[10].Visible = false; // SID dgViewQ.Columns[11].Visible = false; // BSE dgViewQ.Columns[8].DefaultCellStyle.Format = CommonDoubleM.lngDate; dgViewQ.Columns[2].DefaultCellStyle.Format = "0.00"; dgViewQ.Columns[3].DefaultCellStyle.Format = "0.00"; dgViewQ.Columns[4].DefaultCellStyle.Format = "0.00"; dgViewQ.Columns[5].DefaultCellStyle.Format = "0.00"; dgViewQ.Columns[6].DefaultCellStyle.Format = "0.00"; dgViewQ.Columns[7].DefaultCellStyle.Format = "0.00"; } catch (Exception ex) { _theParent.lblDMMsg.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); } }
internal int NewRate(int iStock, double dblRate, DateTime dtTradOn) { int iResult = -1; int iLatestRateId; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdRates = _oConnDM.CreateCommand(); cmdRates.Connection = _oConnDM; try { /* Insert to TRates Table */ cmdRates.CommandType = CommandType.StoredProcedure; cmdRates.CommandText = "QryInsRates"; cmdRates.Parameters.Clear(); cmdRates.Parameters.Add("@StockID", OleDbType.Numeric).Value = iStock; cmdRates.Parameters.Add("@Price", OleDbType.Currency).Value = dblRate; cmdRates.Parameters.Add("@Ondate", OleDbType.Date).Value = dtTradOn; iResult = cmdRates.ExecuteNonQuery(); /*Getting the latest PK from TRates Table */ //Another way to get the auto generated id cmdRates.CommandType = CommandType.StoredProcedure; cmdRates.CommandText = "QryGetAutoID"; cmdRates.Parameters.Clear(); iLatestRateId = (int)cmdRates.ExecuteScalar(); iResult = iLatestRateId; } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.GetType() + " was encountered while inserting the data."; CommonDoubleM.LogDM("NewRate for StockID " + iStock.ToString() + " Not inserted"); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }
/* Calculate average of price for the particular stocks*/ public void MarqueeUpdate() { //2,5 OleDbCommand cmdStockName = new OleDbCommand(); OleDbDataReader drStock = null; cmdStockName.Connection = _oConnDM; cmdStockName.CommandType = CommandType.StoredProcedure; cmdStockName.CommandText = "QryStockLatestValue"; _pBarDoubleM.Visible = true; try { if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } drStock = cmdStockName.ExecuteReader(); if (drStock.HasRows) { //_pBarDoubleM.Value = 0; while (drStock.Read()) //Reading Stock Names { CommonDoubleM.MarqueeString = CommonDoubleM.MarqueeString + " [" + drStock.GetString(2) + ": " + drStock.GetDecimal(5).ToString() + "] "; } } else { CommonDoubleM.MarqueeString = "Welcome to Market Manager - Double'M'"; } } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); } finally { cmdStockName.Dispose(); _pBarDoubleM.Visible = false; if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } }
private void fillGrid() { int iPBValue = 0; _theParent.pBarDM.Visible = true; Application.DoEvents(); Cursor = Cursors.WaitCursor; try { _theParent.pBarDM.Maximum = _dtWatchList.Table.Rows.Count; blnBbaseRow = false; dgViewQ.Rows.Clear(); //for (int ii = 0; ii < dtWatchList.Table.Rows.Count; ii++) foreach (DataRow dtRow in _dtWatchList.Table.Rows) { dgViewQ.Rows.Add(); dgViewQ[10, iPBValue].Value = dtRow[0].ToString(); //SID if (_Source == "Yahoo") { dgViewQ[11, iPBValue].Value = dtRow[1].ToString(); //Yahoo Code } else if (_Source == "Rediff") { dgViewQ[11, iPBValue].Value = dtRow[2].ToString(); //Rediff Code } dgViewQ[0, iPBValue].Value = dtRow[3].ToString(); // Stock Name dgViewQ[1, iPBValue].Value = Convert.ToInt32(dtRow[4].ToString()); // Quantity dgViewQ[7, iPBValue].Value = Convert.ToDouble(dtRow[5].ToString()); //T Paid dgViewQ[3, iPBValue].Value = Convert.ToDouble(dtRow[6].ToString()); //Avg dgViewQ[9, iPBValue].Value = (dtRow[7].ToString() == "True") ? "Y" : "N"; // Acitive or Inactive _theParent.pBarDM.Value = iPBValue; iPBValue++; //if (iPBValue == 5) break; //Just for testing only 2 rows } _theParent.lblDMMsg.Text = iPBValue.ToString() + " Script loaded."; } catch (Exception ex) { _theParent.lblDMMsg.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); } finally { _theParent.pBarDM.Visible = false; Cursor = Cursors.Default; } }
private void btnOk_Click(object sender, EventArgs e) { string sURL = string.Empty; string sSName = string.Empty; long DownloadBytes = 0; try { sSName = _dvStocks[(int)ddlStock.SelectedIndex]["YFCode"].ToString(); sURL = string.Format(URLYahoo, sSName, dtpStart.Value.ToString("MM"), dtpStart.Value.ToString("dd"), dtpStart.Value.ToString("yyyy"), dtpEnd.Value.ToString("MM"), dtpEnd.Value.ToString("dd"), dtpEnd.Value.ToString("yyyy"), _mode); //Console.WriteLine(sURL); SaveFileDialog saveFileDlgExport = new SaveFileDialog(); saveFileDlgExport.Title = "Save file [Historical Data from Yahoo]"; saveFileDlgExport.FileName = sSName = _dvStocks[(int)ddlStock.SelectedIndex]["ShortName"].ToString(); saveFileDlgExport.Filter = "CSV (*.csv)|*.csv"; saveFileDlgExport.InitialDirectory = CommonDoubleM._DoubleMPath; if (saveFileDlgExport.ShowDialog() == DialogResult.OK) { Cursor = Cursors.WaitCursor; DownloadBytes = CommonDoubleM.DownloadFile(sURL, saveFileDlgExport.FileName, _pBar); if (DownloadBytes > -1) { _lblMsgDoubleM.Text = "Download " + CommonDoubleM.FormatBytes(DownloadBytes); } else { _lblMsgDoubleM.Text = "No data available for selected date, please change the date & try again.."; } Cursor = Cursors.Default; } } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); } }
internal int UpdateStock(int SID, int StockCatID, string StockName, string ShortName, string YFCode, string RCode, string BSECode, string HDFCCode, bool Active) { int iResult = -1; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdStocks = _oConnDM.CreateCommand(); cmdStocks.Connection = _oConnDM; try { /* Update to TRates Table */ cmdStocks.CommandType = CommandType.StoredProcedure; cmdStocks.CommandText = "QryUpdateStocks"; cmdStocks.Parameters.Clear(); //Assign parameters should be in order cmdStocks.Parameters.Add("@StockCatID", OleDbType.Integer).Value = StockCatID; cmdStocks.Parameters.Add("@StockName", OleDbType.VarChar).Value = StockName; cmdStocks.Parameters.Add("@ShortName", OleDbType.VarChar).Value = ShortName; cmdStocks.Parameters.Add("@YFCode", OleDbType.VarChar).Value = YFCode; cmdStocks.Parameters.Add("@RCode", OleDbType.VarChar).Value = RCode; cmdStocks.Parameters.Add("@BSECode", OleDbType.VarChar).Value = BSECode; cmdStocks.Parameters.Add("@HDFCCode", OleDbType.VarChar).Value = HDFCCode; cmdStocks.Parameters.Add("@Active", OleDbType.Boolean).Value = Active; cmdStocks.Parameters.Add("@SID", OleDbType.Integer).Value = SID; iResult = cmdStocks.ExecuteNonQuery(); } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.Message + " was encountered while updating the data."; CommonDoubleM.LogDM("Stock has been not update for StockID " + SID.ToString()); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }
private void dgViewQ_CellValueChanged(object sender, DataGridViewCellEventArgs e) { try { if (e.RowIndex == dgViewQ.RowCount - 1) { return; } if (e.ColumnIndex == 2) { //Only got cleaning if (dgViewQ[2, e.RowIndex].Value.ToString() == string.Empty) { dgViewQ[4, e.RowIndex].Value = ""; dgViewQ[6, e.RowIndex].Value = ""; dgViewQ[4, e.RowIndex].Style.BackColor = dgViewQ[3, e.RowIndex].Style.BackColor; return; } double SP = 0.0, CP = 0.0, dicPerct = 0.0, Profit = 0.0; //System.Diagnostics.Debug.WriteLine(e.RowIndex); //Total Gain SP = Convert.ToDouble(dgViewQ[1, e.RowIndex].Value) * Convert.ToDouble(dgViewQ[2, e.RowIndex].Value); CP = Convert.ToDouble(dgViewQ[7, e.RowIndex].Value); Profit = SP - CP; dgViewQ[6, e.RowIndex].Value = Profit; if (CP > 0) { //Calc % dicPerct = (Profit / CP) * 100; dgViewQ[4, e.RowIndex].Value = dicPerct; dgViewQ[4, e.RowIndex].Style.BackColor = Color.FromArgb(CommonDoubleM.GetColorcode((double)dicPerct)); } else { dgViewQ[4, e.RowIndex].Value = 0.0; } } } catch (Exception ex) { _theParent.lblDMMsg.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); } }
private void dgvSPrice_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1 && e.RowIndex < dgvSPrice.RowCount - 1) { CommonDoubleM.LogDM("Editing Rates with ID " + dgvSPrice[0, e.RowIndex].Value.ToString()); _RateID = Convert.ToInt64(dgvSPrice[0, e.RowIndex].Value); txtRate.Text = dgvSPrice[2, e.RowIndex].Value.ToString(); dtpOndate.Value = (DateTime)dgvSPrice[3, e.RowIndex].Value; _theParent.lblDMMsg.Text = "After modification - Press Edit to button to update or New Button to Insert new rate"; _drRate = _dsRates.Tables[0].Rows[e.RowIndex]; txtRate.Focus(); } else { _theParent.lblDMMsg.Text = "Please double click on valid rows.."; } }
private void dgvAc_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { try { if (dgvAc.DataSource != null && dgvAc[0, e.RowIndex].Value != null) { if (dgvAc[13, e.RowIndex].Value != DBNull.Value && dgvAc[13, e.RowIndex].Value.ToString() != "") { dgvAc[13, e.RowIndex].Style.BackColor = Color.FromArgb( CommonDoubleM.GetColorcode(Convert.ToDouble(dgvAc[13, e.RowIndex].Value))); } } } catch (Exception ex) { _theParent.lblDMMsg.Text = ex.Message; } }
private void dgvLayout() { try { dgvScripts.Columns.Add("Stock Name", "Stock Name"); dgvScripts.Columns.Add("Called", "Called"); dgvScripts.Columns.Add("Y! Code", "Y! Code"); dgvScripts.Columns.Add("Rediff Code", "Rediff Code"); dgvScripts.Columns.Add("BSE Code", "BSE Code"); dgvScripts.Columns.Add("Tr. Code", "Tr. Code"); dgvScripts.Columns.Add("Hist. Date", "Hist. Date"); dgvScripts.Columns.Add("SID", "SID"); dgvScripts.Columns.Add("CATID", "CATID"); dgvScripts.Columns.Add("IsActive", "IsActive"); /* Data grid format display*/ dgvScripts.Columns[0].Width = 180; //Name of Script dgvScripts.Columns[1].Width = 90; //Short Name of Script dgvScripts.Columns[2].Width = 80; //Yahoo Code dgvScripts.Columns[3].Width = 80; //Rediff Code dgvScripts.Columns[4].Width = 80; // BSE Code dgvScripts.Columns[5].Width = 80; // Trading Code dgvScripts.Columns[6].Width = 125; // Stock in Date dgvScripts.Columns[7].Width = 0; //Stock ID dgvScripts.Columns[8].Width = 0; //Sector ID dgvScripts.Columns[9].Width = 30; //Active or inAtive dgvScripts.RowHeadersWidth = 60; dgvScripts.Columns[7].Visible = false; // Stock ID dgvScripts.Columns[8].Visible = false; // Sector ID dgvScripts.Columns[9].Visible = false; // Active / Inactive dgvScripts.Columns[6].DefaultCellStyle.Format = CommonDoubleM.srtDate; } catch (Exception ex) { _theParent.lblDMMsg.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); } }
public static bool WriteSetting(string key, string value) { // load config document for current assembly XmlDocument doc = loadConfigDocument(); // retrieve appSettings node XmlNode node = doc.SelectSingleNode("//appSettings"); if (node == null) { throw new InvalidOperationException("appSettings section not found in config file."); } try { // select the 'add' element that contains the key XmlElement elem = (XmlElement)node.SelectSingleNode(string.Format("//add[@key='{0}']", key)); if (elem != null) { // add value for key elem.SetAttribute("value", value); } else { // key was not found so create the 'add' element // and set it's key/value attributes elem = doc.CreateElement("add"); elem.SetAttribute("key", key); elem.SetAttribute("value", value); node.AppendChild(elem); } doc.Save(getConfigFilePath()); return(true); } catch (Exception ex) { CommonDoubleM.LogDM(ex.Message); return(false); } }
public static DataTable ReadCSV(string file) { string path = System.IO.Path.GetDirectoryName(file).ToString(); string filename = System.IO.Path.GetFileName(file).ToString(); string strConn = @"Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" + path + @"\;Extensions=asc,csv,tab,txt"; try { System.Data.Odbc.OdbcConnection conn = new System.Data.Odbc.OdbcConnection(strConn); System.Data.Odbc.OdbcDataAdapter da = new System.Data.Odbc.OdbcDataAdapter("Select * from [" + filename + "]", conn); DataTable dt = new DataTable(); da.Fill(dt); Console.WriteLine(dt.Rows.Count.ToString()); return(dt); } catch (Exception ex) { CommonDoubleM.LogDM("Import CSV failed: " + ex.Message); return(null); } }
private void btnSave_Click(object sender, EventArgs e) { CommonDoubleM._blnFirewll = chkProxy.Checked; AppWRDoubleM.WriteSetting("Firewall", CommonDoubleM._blnFirewll.ToString()); try { if (chkProxy.Checked) { CommonDoubleM._sProxy = txtProxySrvName.Text.Trim(); AppWRDoubleM.WriteSetting("Proxy", CommonDoubleM._sProxy); CommonDoubleM._sUID = txtUID.Text.Trim(); AppWRDoubleM.WriteSetting("UID", txtUID.Text.Trim()); CommonDoubleM._sPWD = txtPWD.Text.Trim(); AppWRDoubleM.WriteSetting("PWD", CryptorEngine.Encrypt(CommonDoubleM._sPWD, true)); } // CommonDoubleM.LoadAppConfig(); } catch (Exception ex) { CommonDoubleM.LogDM(ex.Message); } }
internal int UpdateSector(string sSector, int iSectorID) { int iResult = -1; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdSector = _oConnDM.CreateCommand(); cmdSector.Connection = _oConnDM; try { /* Update to TStockCat Table */ cmdSector.CommandType = CommandType.StoredProcedure; cmdSector.CommandText = "QryUpdateCats"; cmdSector.Parameters.Clear(); //Assign parameters should be in order cmdSector.Parameters.Add("@Category", OleDbType.VarChar).Value = sSector; cmdSector.Parameters.Add("@SectorID", OleDbType.Integer).Value = iSectorID; iResult = cmdSector.ExecuteNonQuery(); } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.Message + " was encountered while updating Table TStockCat."; CommonDoubleM.LogDM("Sector has been not update for CatID " + iSectorID.ToString()); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }
//private DataGridViewPrinter _DataGridViewPrinter; public frmMain() { InitializeComponent(); CommonDoubleM.LoadAppConfig(); _pdalStock = new DALDoubleM(lblDMMsg, pBarDM); _pdalStock.MarqueeUpdate(); CommonDoubleM._pdalStock1 = new DALDoubleM(lblDMMsg, pBarDM); ////////////////////////// _groupPaneBar.Add(CreateButton("Basics", CommonDoubleM.Basics.Length), "Basics ", imglstMain.Images[0], true); _groupPaneBar.Add(CreateButton("Online", CommonDoubleM.Online.Length), "Online ", imglstMain.Images[1], true); _groupPaneBar.Add(CreateButton("Analysis", CommonDoubleM.Analysis.Length), "Analysis ", imglstMain.Images[2], true); _groupPaneBar.Add(CreateButton("Views", CommonDoubleM.Views.Length), "Views ", imglstMain.Images[3], true); _groupPaneBar.Add(CreateButton("Configuration", CommonDoubleM.Configuration.Length), "Configuration ", imglstMain.Images[4], true); _groupPaneBar.Add(CreateButton("About", CommonDoubleM.About.Length), " About ", imglstMain.Images[5], true); _groupPaneBar.CollapseAll(false); _groupPaneBar.CanResize = false; _groupPaneBar[0].Expanded = true; _groupPaneBar.ShowExpandCollapseButton = false; selectAllToolStripMenuItem.Checked = false; /*Winform FAQ*/ //http://www.syncfusion.com/faq/windowsforms/default.aspx /*Hiding Tab Pages on tab control*/ //http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_21549892.html tbMain.Top = tbMain.Top - tbMain.ItemSize.Height; tbMain.Height = tbMain.Height + tbMain.ItemSize.Height; tbMain.Region = new Region(new RectangleF(tpMain.Left, tpMain.Top, tpMain.Width, tpMain.Height + tbMain.ItemSize.Height)); LoadStocks(); LoadStock(); ddlPeriod.DataSource = DoubleM.CommonDoubleM.Period; chkAllStocks.Checked = true; rdobPeriod.Checked = true; pTradings = new frmTradingHist(_pdalStock); pAccount = new frmAc(_pdalStock); }
static void Main(string[] args) { //OS: Vista give control layout problems //Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CommonDoubleM.LoadAppConfig(); if (!IsPrevInstance()) { if (args.Length == 0) { DoubleM.CommonDoubleM.LogDM("DoubleM GUI starting.."); Application.Run(new frmMain()); } else { //Start in bactch mode - just to update the stock price DoubleM.CommonDoubleM.LogDM("Batch mode starting.."); DoubleM.CommonDoubleM.LoadAppConfig(); if (args[0].ToLower() == DoubleM.CommonDoubleM._sBatchKey.ToLower()) { DoubleM.CommonDoubleM.LogDM("Batch DB updated starting.."); DALDoubleM _pdalStock; _pdalStock = new DALDoubleM(null, null); _pdalStock.UpdateStockprice(true); CommonDoubleM.LogDM("DoubleM Batch mode closing.."); } } } else { MessageBox.Show("DoubleM - Already running\n" + "Multiple instance not allowed in Version-" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version, "DoubleM - Info", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
internal int UpdateRate(long iRate, double dblRate, DateTime dtTradOn) { int iResult = -1; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdRates = _oConnDM.CreateCommand(); cmdRates.Connection = _oConnDM; try { /* Update to TRates Table */ cmdRates.CommandType = CommandType.StoredProcedure; cmdRates.CommandText = "QryUpdateRates"; cmdRates.Parameters.Clear(); //Assign parameters should be in order cmdRates.Parameters.Add("@Price", OleDbType.Currency).Value = dblRate; cmdRates.Parameters.Add("@Date", OleDbType.Date).Value = dtTradOn; cmdRates.Parameters.Add("@RID", OleDbType.Numeric).Value = iRate; iResult = cmdRates.ExecuteNonQuery(); } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.Message + " was encountered while inserting the data."; CommonDoubleM.LogDM("Rate has been not update for RateID " + iRate.ToString()); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }
internal int NewSector(string sSector) { int iResult = -1; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdSector = _oConnDM.CreateCommand(); cmdSector.Connection = _oConnDM; try { /* Add to TStockCat Table */ cmdSector.CommandType = CommandType.StoredProcedure; cmdSector.CommandText = "QryInsCats"; cmdSector.Parameters.Clear(); //Assign parameters should be in order cmdSector.Parameters.Add("@Category", OleDbType.VarChar).Value = sSector; iResult = cmdSector.ExecuteNonQuery(); } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.Message + " was encountered while inserting into table TStockCat."; CommonDoubleM.LogDM("New Sector [" + sSector + "] has not been added."); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }
public bool BulkUpdateStockprice(DataTable dtBulkData) { if (dtBulkData == null) { return(false); } OleDbDataAdapter adBulkRate = new OleDbDataAdapter(); adBulkRate = new OleDbDataAdapter("Select * from Rates", _oConnDM); adBulkRate.InsertCommand = new OleDbCommand(); adBulkRate.InsertCommand.CommandType = CommandType.StoredProcedure; adBulkRate.InsertCommand.CommandText = "QryInsRates"; adBulkRate.InsertCommand.Connection = _oConnDM; try { adBulkRate.InsertCommand.Parameters.Add("@StockID", OleDbType.Numeric, 8, dtBulkData.Columns[0].ColumnName); adBulkRate.InsertCommand.Parameters.Add("@Price", OleDbType.Currency, 32, dtBulkData.Columns[1].ColumnName); adBulkRate.InsertCommand.Parameters.Add("@Ondate", OleDbType.Date, 20, dtBulkData.Columns[2].ColumnName); adBulkRate.InsertCommand.Connection.Open(); adBulkRate.Update(dtBulkData); adBulkRate.InsertCommand.Connection.Close(); return(true); } catch (Exception ex) { _lblMsgDoubleM.Text = ex.Message; CommonDoubleM.LogDM(ex.Message); return(false); } finally { adBulkRate.Dispose(); } }
internal int DeleteStock(int SID) { int iResult = -1; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdStocks = _oConnDM.CreateCommand(); cmdStocks.Connection = _oConnDM; try { /* Delete to TRates Table */ cmdStocks.CommandType = CommandType.StoredProcedure; cmdStocks.CommandText = "QryDeleteStocks"; cmdStocks.Parameters.Clear(); //Assign parameters should be in order cmdStocks.Parameters.Add("@SID", OleDbType.Integer).Value = SID; iResult = cmdStocks.ExecuteNonQuery(); } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.Message + " was encountered while Deleting the data."; CommonDoubleM.LogDM("Stock has been not deleted for StockID " + SID.ToString()); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }
internal int getRates_Count(int SID) { int iResult = -1; if (_oConnDM.State != ConnectionState.Open) { _oConnDM.Open(); } OleDbCommand cmdStocks = _oConnDM.CreateCommand(); cmdStocks.Connection = _oConnDM; try { /* TRates Table - rate count*/ cmdStocks.CommandType = CommandType.StoredProcedure; cmdStocks.CommandText = "QryRatesCount"; cmdStocks.Parameters.Clear(); //Assign parameters should be in order cmdStocks.Parameters.Add("@SID", OleDbType.Integer).Value = SID; iResult = (int)cmdStocks.ExecuteScalar(); } catch (Exception ex) { iResult = -1; _lblMsgDoubleM.Text = "An exception of type " + ex.Message + " was encountered while counting rates."; CommonDoubleM.LogDM("Stock rates count not completed for StockID " + SID.ToString()); } finally { if (_oConnDM.State != ConnectionState.Closed) { _oConnDM.Close(); } } return(iResult); }