data grid

8
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Sql; using System.Data.OleDb; using System.Data.Common; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; using System.Text.RegularExpressions; using Microsoft.Practices.EnterpriseLibrary.Common; using Microsoft.Practices.EnterpriseLibrary.Data; using Microsoft.Practices.EnterpriseLibrary.Data.Sql; using Microsoft.Practices.EnterpriseLibrary.Logging; using iTextSharp.text; using iTextSharp.text.pdf; using System.IO; namespace BSG_SMS { public partial class Form1 : Form { DataSet ds; OleDbConnection con; OleDbCommand oledbCmd; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { test(); LoadSheet(); } private void button1_Click(object sender, EventArgs e) { HttpClient client = new HttpClient(); string msg = textBox1.Text.Trim(); string url = "http://login.smsgatewayhub.com/smsapi/pushsms.aspx? user=bsganesh82&pwd=898457&to=919840817231&sid=WEBSMS&msg="; url += msg + "&fl=0 "; try

description

data grid in C#.NET

Transcript of data grid

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.Sql;using System.Data.OleDb;using System.Data.Common;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Net.Http;using System.Net.Http.Headers;using System.Threading.Tasks;using System.Text.RegularExpressions;using Microsoft.Practices.EnterpriseLibrary.Common;using Microsoft.Practices.EnterpriseLibrary.Data;using Microsoft.Practices.EnterpriseLibrary.Data.Sql;using Microsoft.Practices.EnterpriseLibrary.Logging;

using iTextSharp.text;using iTextSharp.text.pdf;using System.IO;

namespace BSG_SMS{ public partial class Form1 : Form { DataSet ds; OleDbConnection con; OleDbCommand oledbCmd; public Form1() { InitializeComponent(); }

private void Form1_Load(object sender, EventArgs e) { test(); LoadSheet(); }

private void button1_Click(object sender, EventArgs e) { HttpClient client = new HttpClient(); string msg = textBox1.Text.Trim(); string url = "http://login.smsgatewayhub.com/smsapi/pushsms.aspx?user=bsganesh82&pwd=898457&to=919840817231&sid=WEBSMS&msg="; url += msg + "&fl=0 "; try { HttpResponseMessage response = client.GetAsync(url).Result; response.EnsureSuccessStatusCode(); if (response.IsSuccessStatusCode) { Console.WriteLine("Success"); } else { Console.WriteLine("Failed"); } // string responseBody = await response.Content.ReadAsStringAsync(); // Above three lines can be replaced with new helper method below string responseBody = client.GetStringAsync(url).Result; Console.WriteLine(responseBody); } catch (HttpRequestException ee) { Console.WriteLine("\nException Caught!"); Console.WriteLine("Message :{0} ", ee.Message); }

// Need to call dispose on the HttpClient object // when done using it, so the app doesn't leak resources // client.Dispose(true); }

public void LoadSheet() { try { DataTable dt; string path = System.IO.Path.GetFullPath("E:\\BSG\\test.xlsx"); //string excelFile = "@E:\\BSG\\test.xlsx"; //OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + excelFile + ";" + // "Extended Properties='Excel 8.0;HDR={1}'"); con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + path + ";" + "Extended Properties='Excel 12.0;HDR=YES;IMEX=1;';"); con.Open(); dt = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); String[] excelSheets = new String[dt.Rows.Count]; int i = 0;

// Add the sheet name to the string array. foreach (DataRow row in dt.Rows) { excelSheets[i] = row["TABLE_NAME"].ToString(); i++; } cmbTables.DataSource = dt.DefaultView; cmbTables.DisplayMember = "TABLE_NAME"; } catch (Exception e) { } }

public void test() { try { Database db = new SqlDatabase("server=192.168.0.4;database=Fansplay;user=sa;password=Sql@chennai"); DbCommand cmd = db.GetStoredProcCommand("Get_Ff_Team"); ds = db.ExecuteDataSet(cmd); Console.WriteLine(ds.Tables.Count); DataRow dr = ds.Tables[0].Rows[0]; textBox1.Text = dr[1].ToString(); comboBox1.DataSource = ds.Tables[0].DefaultView; comboBox1.DisplayMember = ds.Tables[0].Columns[2].ColumnName; //comboBox1.SelectedIndex = -1; textBox1.Text = (comboBox1.SelectedIndex).ToString(); GeneratePdf(); } catch (Exception e) { } }

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { DataRow dr = ds.Tables[0].Rows[comboBox1.SelectedIndex]; // textBox1.Text = dr[0].ToString() + "-" + dr[1].ToString(); // textBox1.Text = (comboBox1.SelectedIndex).ToString(); }

private void button2_Click(object sender, EventArgs e) { string s=""; foreach (DataGridViewRow dgRow in dataGridView1.Rows) { int id = Convert.ToInt32(dgRow.Cells[1].Value); s = s + id; } MessageBox.Show(s); string mail = textBox1.Text; try { Regex re = new Regex("^9[0-9]{9}"); //string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + // @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + // @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; string strRegex = @"^(?("")("".+?(?