|
Yes Im using SQL Server...
|
|
|
|
|
Then create a stored procedure in you database with the method which was linked to in my previous post.
Then convert you information into an XML format and call the stored procedure with the XML.
Simple...
hmmm pie
|
|
|
|
|
|
I type this same thing over and over in emails to my customers and i was wondering how to write a macro to paste
Please acknowledge receipt of this order by email to me.
into the body of email by hitting a button on the task bar called "Please Acknowledge"
i have visual studio 2008 and using outlook 2007
anyone have any ideas.
Thank you
-Ryan
|
|
|
|
|
|
I'm not a programmer by any measure so I'm turning to you all for help.
I'm creating an InfoPath form which is housing some C# code to run WMI queries when the form is entered. The user will then enter in a few bits of information about them self and submit the form to a SharePoint library to help keep track of our users inventory.
My question is can someone help me clean up this code before i get too far into it? I've been using the WMI Code Creator from Microsoft's Website to get the code samples and by brut force I've gotten them to start to pull the information i'm looking for, but the code seems a little ugly and messy for me. I'm sure there has to be a way to condense some of this code and make it easier to manage and i want to start to figure that out before i get too far, once I see how it's done I should be able to figure it out from there. My code sample just has the video card and the sound card query, but eventually i'll have RAM, Hard drive, CPU, etc.
Code Sample:
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Management;
namespace Inventory_Rev1
{
public partial class FormCode
{
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
ManagementObjectSearcher searcherRAM =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_PhysicalMemory");
ManagementObjectSearcher searcherDisplay =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_VideoController");
ManagementObjectSearcher searcherAudio =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_SoundDevice");
ManagementObjectSearcher searcherNIC =
new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_NetworkAdapter");
foreach (ManagementObject queryObj in searcherAudio.Get())
{
string audioController = queryObj["Name"].ToString();
XPathNavigator xnMyForm = this.CreateNavigator();
XmlNamespaceManager ns = this.NamespaceManager;
xnMyForm.SelectSingleNode("/my:myFields/my:SoundCard", ns).SetValue(audioController);
}
foreach (ManagementObject queryObj in searcherDisplay.Get())
{
string displayAdapter = queryObj["Name"].ToString();
XPathNavigator xnMyForm = this.CreateNavigator();
XmlNamespaceManager ns = this.NamespaceManager;
xnMyForm.SelectSingleNode("/my:myFields/my:VideoAdapter", ns).SetValue(displayAdapter);
}
}
}
}
|
|
|
|
|
Is the subject line too long? Probably.
I'm experiencing an issue with my dataset that seems to be telling me that the values for a foreign key in my child table does not exist within the parent table. As far as I can see, the value does exist. This happens when I try to fill a datagridview using a tableadapter.
If the program throws the exception as normal I get the usual "Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
If I use a try/catch around the query it fills the datagridview but gives me a red warning sign that reads "ForeignKeyConstraint [ForeignKey] requires the child key values (value) to exist in the parent table."
Has anyone come across this particular issue? Where can I usually find the properties for foreign key contraints?
Any help would be hugely appreciated!
(I'm using the generic Fill query created for tables in sqlserver.)
|
|
|
|
|
Fill the reference table first and then fill the main table. Your error means that the referenfed DataTable does not have data that the maintable is refering to.
Post your code and ill see if i can assist you.
|
|
|
|
|
I came across this error to when I thought the parent value did exist. For me the solution was that I had to make sure that the ParentColumns and ChildColumns for the constraint listed the columns in the same order.
|
|
|
|
|
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if ((e.ColumnIndex == 3) && (e.RowIndex >= 0))
{
Rectangle textRange = new Rectangle(e.ClipBounds.X + 20, e.ClipBounds.Y, e.ClipBounds.Width - 20, e.ClipBounds.Height);
e.PaintBackground(e.ClipBounds, selected);
e.PaintContent(textRange);
e.Handled = true;
}
}
I'm trying to ofset the location of a text string in a winform DataGridView cell, but while the clipbounds parameter of of PaintContent appears like it should let my specify where to paint at, the text is always painted in the default location regardless of what I pass in. Am I doing something wrong with how I'm calling PaintContent , or is it not designed to do what I want? I can use e.Graphics.Drawstring if I have to, but would much prefer to let MS handle all the edge cases for me if possible.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
AFAIK PaintContent acts exactly like Invalidate(aRectangle) . That is, it repaints the rectangular area you pass.
Someone else may know how to do this, but all examples I have ever seen use either DrawString or a TextRenderer .
Sorry not to be of more help.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks. It's painting the entire cell area though, not just the part I passed. What your describing would have the 1st char or two of the string not shown in my example (starting at x+20). Seems like it's just retarded/buggy.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
I got sort of interested in this, so I've been doing some ferreting around.
Try something like this:
private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
{
if ((e.ColumnIndex == 3) && (e.RowIndex >= 0))
{
Rectangle textRange = new Rectangle(e.ClipBounds.X + 20, e.ClipBounds.Y, e.ClipBounds.Width - 20, e.ClipBounds.Height);
e.Paint(textRange,
DataGridViewPaintParts.ContentForeground |
DataGridViewPaintParts.Border |
DataGridViewPaintParts.ErrorIcon |
DataGridViewPaintParts.Focus);
}
}
According to the MSDN page for the DataGridViewCellPaintingEventArgs.Paint method, the Rectangle Parameter is
"A Rectangle that specifies the area of the DataGridView to be painted"
Worth a try?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
That's still left aligning the text with the edge of the cell, not the textrange rectangle. What I'm trying to do is to offset it to the right so that I can draw a small image in the leftmost portion of the cell without covering up the text.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
I figured that was what you were trying to do, or at least something like that.
The only way I know that will do that is to use DrawString , or a TextRenderer .
Of course the *ahem* 'correct' way to do this sort of thing is to create your own DataGridViewCell class and include that in your own DataGridViewColumn class. One advantage of that is, of course that it will be available for use in other situations.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: Of course the *ahem* 'correct' way to do this sort of thing is to create your own DataGridViewCell class and include that in your own DataGridViewColumn class. One advantage of that is, of course that it will be available for use in other situations.
True, and I intend to go that route with whatever the text render ends up being; however that was overkill for the proof of concept stage.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Good luck!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I don't know if you have gotten the answer you were looking for since posting, but this should give you what you want.
If you added the columns with the designer you can go to DefaultCellSyle in the column properties. Click the [...] button and change the Padding to the offset you want the cell content to be.
or you can use:
YourDataGridView.Columns[TheColumn].DefaultCellStyle.Padding = new Padding(Left, Top, Right, Bottom);
Inside a custom cell:
this.Style.Padding = new Padding(Left, Top, Right, Bottom);
|
|
|
|
|
I hadn't found this, thanks.
PS what triggered this act of threadcromancy?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Did it work in the way you wanted?
As to how i came upon this:
I had been using the Graphics.DrawString method in a custom DataGridViewTextBoxCell . But i had lost the textbox look and feel when editing the value. After stumbling upon this thread in the search of ways to move the cell content around, i decided to search through the Style Methods of the cell again.
When i saw padding close to the bottom, i had one of those eureka moments. Thinking to myself, "Why would a cell have the need for padding if it didn't have any components to offset from the borders?". The Content of course. Threw some random numbers in and sure enough it offset the cell content.
|
|
|
|
|
It did. I've been working on other stuff and haven't had time to take this from a proof of concept into a custom cell yet. Are there any other gotchas I should be aware of when I do so?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
So far that was the only hitch i have come across when making a custom cell. Everything else has been pretty straight forward, but we all know that can change quickly.
modified on Friday, May 1, 2009 12:23 PM
|
|
|
|
|
I am trying to lock and unlock accounts in Active Directory. This is what I have but it is giving this error:
System.Reflection.TargetInvocationException was unhandled
Message="Exception has been thrown by the target of an invocation."
Source="System.DirectoryServices"
StackTrace:
at System.DirectoryServices.DirectoryEntry.InvokeGet(String propertyName)
at ITApp.GetInfo.get_IsLocked() in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\GetInfo.cs:line 125
at ITApp.GetInfo.GetInfo_Load(Object sender, EventArgs e) in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\GetInfo.cs:line 37
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at ITApp.Main.button1_Click_1(Object sender, EventArgs e) in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\Main.cs:line 346
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at ITApp.Program.Main() in C:\Visual Studio 2008\Projects\ITApp\ITApp\ITApp\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Runtime.InteropServices.COMException
Message="Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"
Source=""
ErrorCode=-2147467259
InnerException:
I am not realy understanding it, but this is the code I have to do this:
This is to get the adspath:
private object GetDN(string Name)
{
object userDN = null;
using (DirectoryEntry root = new DirectoryEntry())
{
root.Path = "LDAP://adem.arkansas.gov";
using (DirectorySearcher searcher = new DirectorySearcher())
{
searcher.SearchRoot = root;
searcher.SearchScope = SearchScope.Subtree;
searcher.Filter = "(&(objectClass=user)(name="+Name+"))";
searcher.PropertiesToLoad.Add("adspath");
SearchResultCollection results = searcher.FindAll();
if (results != null)
{
foreach (SearchResult result in results)
{
ResultPropertyCollection props = result.Properties;
foreach (string propName in result.Properties.PropertyNames)
{
if (propName.ToLower() == "adspath") userDN = props[propName][0].ToString();
}
}
}
}
if (userDN != null) return userDN;
else return null;
}
}
This is to unlock/lock the account (got this from CodeProject.com):
public bool IsLocked
{
get { return Convert.ToBoolean(dEntry.InvokeGet("IsAccountLocked")); }
set { dEntry.InvokeSet("IsAccountLocked", value); }
}
This is how I am calling it:
private DirectoryEntry dEntry;
private void GetInfo_Load(object sender, EventArgs e)
{
object GetDNString = GetDN("Dixon, Jacob");
MessageBox.Show(GetDNString.ToString());
dEntry = new DirectoryEntry(GetDNString.ToString());
MessageBox.Show(IsLocked.ToString());
IsLocked = true;
}
BTW our AD is running at Server 2008.
|
|
|
|
|
Hey I'm quite new to programming and C# is my first language. I think I understand the basics and now I want to try some networking. I have looked at some tutorials but they seem a little too advanced and usually work with forms, I have only used the console so far.
I want to do something like have a client which sends some data, say a person's name and his favorite color. The Server saves the data and replies "transfer success" or something. Then also from the client update a persons favorite color and change it from say blue to red.
I have not much clue how to start however. I was thinking to make the server store the data in a hash table or something? But how this would work with the client I don't know.
Thanks and sorry for my bad english.
|
|
|
|
|
This is my code so far. I'm having problems to integrate a hashtable into the server but can get one working in its own.
Any help appreciated.
using System;
using System.Collections;
using System.Net.Sockets;
using System.Linq;
using System.Text;
using System.IO;
namespace Server
{
class Program
{
static void Main(string[] args)
{
runServer();
}
static public void runServer()
{
TcpListener listener;
Socket connection;
NetworkStream socketStream;
int port = 43;
try
{
listener = new TcpListener(port);
listener.Start();
Console.WriteLine(" Whereis Server Started....");
while (true)
{
connection = listener.AcceptSocket();
socketStream = new NetworkStream(connection);
doRequest(socketStream);
socketStream.Close();
connection.Close();
}
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.ToString());
}
}
static void doRequest(NetworkStream socketStream)
{
StreamWriter sw = new StreamWriter(socketStream);
StreamReader sr = new StreamReader(socketStream);
String cmd = sr.ReadLine();
Hashtable table = new Hashtable();
table.Add("bob", "in bed");
table.Add("sam", "test_location2");
table.Add("mark", "test_location3");
if (cmd.Contains(' '))
{
String person = cmd;
int SpaceChr = person.IndexOf(" ");
person = person.Substring(0,SpaceChr);
Console.WriteLine("person test <" + person + ">");
String location = cmd;
SpaceChr++;
location = location.Substring(SpaceChr);
Console.WriteLine("location test <" + location + ">");
table.Add(person, location);
table[person] = location;
sw.WriteLine(person + " location changed to " + location);
Console.WriteLine("\n" + person + " location changed to " + location);
sw.Flush();
}
else
{
String person = cmd;
Console.WriteLine("Request for " + person + "\n\nReplied " + table[person]);
sw.WriteLine(person + " is " + table[person]);
sw.Flush();
}
}
}
}
<pre>using System;
using System.Collections;
using System.Net.Sockets;
using System.Linq;
using System.Text;
using System.IO;
namespace HashTableTest
{
class Program
{
static void Main(string[] args)
{
string name = "bob";
string location = "at home";
Hashtable table = new Hashtable();
table.Add(name, location);
table.Add("sam", "test_location2");
table.Add("mark", "test_location3");
Console.WriteLine("Has the hashtable worked:" + table[name]);
Console.ReadLine();
}
}
}
using System;
using System.Net.Sockets;
using System.IO;
public class Whois
{
static void Main(string[] args)
{
string name = "localhost";
int port = 43;
TcpClient client = new TcpClient();
Console.WriteLine("Whereis Server Requested...\n");
try
{
client.Connect(name, port);
}
catch (Exception noServer)
{
Console.WriteLine("Server refused connection. Is the server up and listening on port " + port + "? \n");
Console.WriteLine("Exception: \n\n" + noServer.ToString());
}
StreamWriter sw = new StreamWriter(client.GetStream());
StreamReader sr = new StreamReader(client.GetStream());
Console.WriteLine("Client:");
string person = args[0];
if (args.Length > 1)
{
string location = args[1];
sw.WriteLine(person + " " + location);
Console.WriteLine("Attempting to Change location of <" + person + "> to <" + location + ">\n");
}
else
{
Console.WriteLine("Looking up <" + person + ">");
sw.WriteLine(person);
}
sw.Flush();
Console.WriteLine("Server:\n" + sr.ReadToEnd());
Console.ReadLine();
}
}
|
|
|
|