using System;
using System.Data;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;
using System.Text;
namespace SDM
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void browsefiles_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog()==DialogResult.OK)
{
display(openFileDialog1.FileName);
}
}
private void display(string text)
{
textBox1.Text = string.Format("{0}", openFileDialog1.FileName);
}
private void importFile_Click(object sender, EventArgs e)
{
string PathConn = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + textBox1.Text + "; Jet OLEDB:Engine Type=5;Extended Properties=\"Excel 12.0;\"");
OleDbConnection conn= new OleDbConnection(PathConn);
OleDbDataAdapter myDataAdapter = new OleDbDataAdapter("Select * from [" + textBox2.Text+ "$]", conn);
DataTable dt = new DataTable();
myDataAdapter.Fill(dt);
if (textBox2.Text.Contains("Life Group"))
{
dt.Columns.Add("Agent Code", typeof(string));
}
else if (textBox2.Text.Contains("Life Individual"))
{
DataColumn col = dt.Columns[9].ToString();
String.Format("####-###");
Console.WriteLine(col);
myDataAdapter.Fill(dt);
}
I am trying to change the format of Column [9] from "1234567" to "1234-567". I just want to add a dash after the 4th number but am having trouble calling on that entire column to make the change. Can anybody lend any suggestions? It would be greatly appreciated.
Related
I installed sharepoint foundation 2010 (in 'Standalone' type) on windows 2012 r2.
And I created a windows app project.
When Load , New Counter(farm) is success.
But, SPFarm.local.GetObject return null;
Does someone konw the reason,please help me.
source like this:
//-------source start-------
//Counter.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
namespace WinAppTest
{
class Counter : SPPersistedObject
{
public static String SettingName = "Counter";
public static String SettingGuid = "62648e50-8aee-42b2-b074-2f49ced85587";
[Persisted]
public String name;
[Persisted]
public String count;
public Counter()
{
}
public Counter(SPPersistedObject parent)
: base(SettingName, parent, new Guid(SettingGuid))
{
}
}
}
// Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.SharePoint.Administration;
namespace WinAppTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Write_Click(object sender, EventArgs e)
{
SPFarm farm = SPFarm.Local;
//------- *conf is null*-----
Counter conf = (Counter)farm.GetObject(new Guid(Counter.SettingGuid));
//------- *conf is null*-----
conf.Name = "pf1";
conf.count = "1";
conf.Update();
}
private void Form1_Load(object sender, EventArgs e)
{
SPFarm farm = SPFarm.Local;
Counter conf = (Counter)farm.GetObject(new Guid(Counter.SettingGuid));
if (conf == null)
{
conf = new Counter(farm);
}
//------- *conf is null*-----
conf = (Counter)farm.GetObject(new Guid(Counter.SettingGuid));
//------- *conf is null*-----
String name = conf.name;
String count = conf.count;
}
}
}
Finally , I think the source has error in it.
modify like this, It's OK.
private void Write_Click(object sender, EventArgs e)
{
SPFarm farm = SPFarm.Local;
Counter conf = (Counter)farm.GetObject(new Guid(Counter.SettingGuid));
if (conf == null)
{
conf = new Counter(farm);
}
conf.Name = "pf1";
conf.count = "1";
conf.Update();
}
private void Form1_Load(object sender, EventArgs e)
{
SPFarm farm = SPFarm.Local;
Counter conf = (Counter)farm.GetObject(new Guid(Counter.SettingGuid));
String name = conf.name;
String count = conf.count;
}
I need some help with error..
Error 2 The type 'AForge.Video.NewFrameEventArgs' exists in both 'c:\Users\anton\OneDrive\Документы\Visual Studio 2013\Projects\WindowsFormsApplication4\packages\Accord.Video.3.0.2\lib\net45\Accord.Video.dll' and 'c:\Users\anton\OneDrive\Documents\Visual Studio 2013\Projects\WindowsFormsApplication4\packages\AForge.Video.2.2.5\lib\AForge.Video.dll' C:\Users\anton\onedrive\Documents\visual studio 2013\Projects\WindowsFormsApplication4\WindowsFormsApplication4\Form1.cs 50 42 WindowsFormsApplication4
this is my code:`
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Video.FFMPEG;
namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private VideoCaptureDevice FinalVideo = null;
private VideoCaptureDeviceForm captureDevice;
private Bitmap video;
private VideoFileWriter FileWriter = new VideoFileWriter();
private SaveFileDialog saveAvi;
private FilterInfoCollection webcam;
private VideoCaptureDevice cam;
private void Form1_Load(object sender, EventArgs e)
{
webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in webcam)
{
comboBox1.Items.Add(VideoCaptureDevice.Name);
comboBox1.SelectedIndex = 0;
}
pictureBox1.Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom);
comboBox1.Anchor = (AnchorStyles.Bottom);
button1.Anchor = (AnchorStyles.Bottom);
button2.Anchor = (AnchorStyles.Bottom);
button3.Anchor = (AnchorStyles.Bottom);
}
private void button1_Click(object sender, EventArgs e)
{
cam = new VideoCaptureDevice(webcam[comboBox1.SelectedIndex].MonikerString);
cam.NewFrame += new NewFrameEventHandler(cam_NewFrame);
cam.Start();
}
void cam_NewFrame(object sender, NewFrameEventArgs EventArgs)
{
Bitmap bit = (Bitmap)EventArgs.Frame.Clone();
pictureBox1.Image = bit;
}
private void button3_Click(object sender, EventArgs e)
{
if (cam.IsRunning)
{
cam.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
saveFileDialog1.InitialDirectory = #"C:\picture";
saveFileDialog1.Filter = "Images|*.png;*.bmp;*.jpg";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image.Save(saveFileDialog1.FileName);
}
}
private void button4_Click(object sender, EventArgs e)
{
saveAvi = new SaveFileDialog();
saveAvi.Filter = "Avi Files (*.avi)|*.avi";
if (saveAvi.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
int h = captureDevice.VideoDevice.VideoResolution.FrameSize.Height;
int w = captureDevice.VideoDevice.VideoResolution.FrameSize.Width;
FileWriter.Open(saveAvi.FileName, w, h, 25, VideoCodec.Default, 5000000);
FileWriter.WriteVideoFrame(video);
//AVIwriter.Open(saveAvi.FileName, w, h);
//FinalVideo = captureDevice.VideoDevice;
//FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
//FinalVideo.Start();
}
}
}
}
I have two DROP DOWN LISTs :one for PROVINCE and one for CITY which are connected to a DB.
I want to be able to select a PROVINCE from the first drop down list and be able to see the
CITIES of that special PROVINCE in the second drop down list.
But I receive the error "Failed to convert parameter value from a String to a Int32." on line "DataSet ds1 = new DataSet();".
My DB:
--------
_Province
Prv_Id --- int (P.key)
Prv_Name --- nvarchar
--------------
_City
Cty_Id --- int (P.key)
Cty_Name --- nvarchar
Cty_Prv_Id --- int (F.key)
----------------------------
----------------------------
My ST.Procedures:
-----------------------
ALTER PROCEDURE [dbo].[_City_selectItems] (#vari int)
AS
BEGIN
SELECT * FROM _City WHERE (Cty_Prv_Id=#vari)
END
--------------------------------------------------
ALTER PROCEDURE [dbo].[_Province_selectAll]
AS
BEGIN
SELECT * FROM _Province
END
--------------------------------------------------
MY CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication3_DrpDwnListAndSQL
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
func1();
func2();
//func3();
}
}
protected void DrpDwnProvince_SelectedIndexChanged(object sender, EventArgs e)
{
Label1.Text =DrpDwnProvince.SelectedValue;
//string a = DrpDwnProvince.SelectedValue;
}
//First function for Province DrpDwnList
private void func1()
{
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DrpBoxDB;Data Source=ARASH-PC");
SqlDataAdapter com = new SqlDataAdapter("_Province_selectAll", con);
com.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
if (com != null)
{ com.Fill(ds); }
DrpDwnProvince.DataSource = ds;
DrpDwnProvince.DataTextField = "Prv_Name";
DrpDwnProvince.DataValueField = "Prv_Id";
DrpDwnProvince.DataBind();
}
//Second function for City DrpDwnList
private void func2()
{
SqlConnection con = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DrpBoxDB;Data Source=ARASH-PC");
SqlDataAdapter com1 = new SqlDataAdapter("_City_selectItems", con);
com1.SelectCommand.Parameters.Add("#vari",SqlDbType.Int).Value=Label1.Text;
com1.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds1 = new DataSet();
if (com1 != null)
{ com1.Fill(ds1); }
DrpDwnCity.DataSource = ds1;
DrpDwnCity.DataTextField = "Cty_Name";
DrpDwnCity.DataValueField = "Cty_Id";
DrpDwnCity.DataBind();
}
//Third function for District DrpDwnList
// private void func3()
// {
// }
}
}
using System.Data.OleDb;
namespace ConnectingToMS_Access1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbDataAdapter da;
DataSet ds;
private void Form1_Load(object sender, EventArgs e)
{
da = new OleDbDataAdapter("Select * from Record", "Provider=Microsoft.Ace.oledb.12.0;data source='D:\\mydb.accdb'");
ds = new DataSet();
da.Fill(ds);
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = ds.Tables[0];
}
private void button2_Click(object sender, EventArgs e)
{
DataRow dr = ds.Tables[0].NewRow();
dr[0] = "abc";
dr[1] = "def";
dr[2] = "ghi";
dr[3] = "jkl";
ds.Tables[0].Rows.Add(dr);
}
private void button3_Click(object sender, EventArgs e)
{
OleDbCommandBuilder cb = new OleDbCommandBuilder(da);
da.Update(ds.Tables[0]);
MessageBox.Show("Saved in Database");
}
}
}
You need to explicitly define the named columns in your query.
The problem is that you can't update columns based on column position. It might have been reasonable to expect that calling the Fill method would return both records and column-names, but it probably won't. After all, running that select query will return only data, not schema.
Hi I want to do something like on screen keyboard. I want user to click a button on inactive application and then key press will be sent to active application while keeping active application active. I wrote the code for hover event of the button in inactive application and it is working. But what I want is to do it in click event. It is not working because inactive application becomes active. The code is below for hover event. Thank you.
private void button1_MouseHover(object sender, EventArgs e)
{
SendKeys.Send("{TAB}");
}
Finally I could figure out a way to do it.
Refer the code below.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Timers;
using tmr = System.Timers;
using System.Threading;
namespace KeyPressTest
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern int GetForegroundWindow();
[DllImport("user32")]
private static extern UInt32 GetWindowThreadProcessId(Int32 hWnd, out Int32 lpdwProcessId);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[System.Runtime.InteropServices.DllImport("user32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);
tmr.Timer tm = new tmr.Timer();
Int32 hwnd = 0;
private Int32 GetWindowProcessID(Int32 hwnd)
{
Int32 pid = 1;
GetWindowThreadProcessId(hwnd, out pid);
return pid;
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
tm.Elapsed += Timer_Elapsed;
tm.Interval = 100;
tm.Start();
}
private void button1_Click(object sender, EventArgs e)
{
SetForegroundWindow((IntPtr)hwnd);
Thread.Sleep(40);
SendKeys.Send("{TAB}");
}
private void Timer_Elapsed(object sender, System.EventArgs args)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(delegate
{
if (this.Handle.ToInt32() != GetForegroundWindow())
{
hwnd = GetForegroundWindow();
}
}));
}
else
{
if (this.Handle.ToInt32() != GetForegroundWindow())
{
hwnd = GetForegroundWindow();
}
}
if (hwnd == 0)
{
return;
}
string appProcessName = "";
string appExePath = "";
string appExeName = "";
try
{
appProcessName = Process.GetProcessById(GetWindowProcessID(hwnd)).ProcessName;
appExePath = Process.GetProcessById(GetWindowProcessID(hwnd)).MainModule.FileName;
appExeName = appExePath.Substring(appExePath.LastIndexOf(#"\") + 1);
}
catch (Exception ex)
{
}
if (textBox1.InvokeRequired)
{
textBox1.Invoke(new MethodInvoker(delegate
{
textBox1.Text = appProcessName + " | " + appExePath + " | " + appExeName;
}));
}
else
{
textBox1.Text = appProcessName + " | " + appExePath + " | " + appExeName;
}
}
}
}
I have never done something similar, but here is what I found in this forum:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern int GetForegroundWindow();
[DllImport("user32")]
private static extern UInt32 GetWindowThreadProcessId(Int32 hWnd, out Int32 lpdwProcessId);
private int teller = 0;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (teller == 1)
{
setTextje();
}
teller++;
}
private Int32 GetWindowProcessID(Int32 hwnd)
{
Int32 pid = 1;
GetWindowThreadProcessId(hwnd, out pid);
return pid;
}
private void setTextje()
{
Int32 hwnd = 0;
hwnd = GetForegroundWindow();
string appProcessName = Process.GetProcessById(GetWindowProcessID(hwnd)).ProcessName;
string appExePath = Process.GetProcessById(GetWindowProcessID(hwnd)).MainModule.FileName;
string appExeName = appExePath.Substring(appExePath.LastIndexOf(#"\") + 1);
textBox1.Text = appProcessName + " | " + appExePath + " | " + appExeName;
}
}
}
It doesn't answer exactly to your question but it will give you a hint. You need to DllImport "User32.dll". After that you can get the id of the foreground window and play with that.
There is also a very interesting article about application switch tracking written in C#