|
Thank u harold aptroot for Appreciation.
|
|
|
|
|
No. As has been said, they can work in .NET 2, but they were introduced in .NET 3 which was released with VS2008. As the OP said he was dealing with LINQ however, it's a safe bet that he's using VS2008/VS2010.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
That's what I thought - but the OP post was talking about 2005, so that's why I asked. He probably has something a bit confused...
Sharma Dinesh Kumar wrote: in my project which is winForm app. in VS 2005
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
The best you can probably do is use extension methods[^].
My signature "sucks" today
|
|
|
|
|
public void InsertPlannedMaterialMasterRequest(int id, string requestDocument, string requestDescription, string requestType, string hodApproval, int companyCode, string hodRemarks, string det_Description, string name, int qty, string code)
{
string query = "INSERT INTO MasterRequest (ID,Req_Document,Req_Description,ReqType,HODApproval,CompanyCode,HODRemarks) VALUES (@ID,@Req_Document,@Req_Description,@ReqType,@HODApproval,@CompanyCode,@HODRemarks)";
SqlConnection con = new SqlConnection(constr);
SqlCommand com = new SqlCommand(query, con);
com.Parameters.Add("@ID", SqlDbType.Int).Value = id;
com.Parameters.Add("@Req_Document", SqlDbType.NVarChar).Value = requestDocument;
com.Parameters.Add("@Req_Description", SqlDbType.NVarChar).Value = requestDescription;
com.Parameters.Add("@ReqType", SqlDbType.NVarChar).Value = requestType;
com.Parameters.Add("@HODApproval", SqlDbType.NVarChar).Value = hodApproval;
com.Parameters.Add("@CompanyCode", SqlDbType.Int).Value = companyCode;
com.Parameters.Add("@HODRemarks", SqlDbType.NVarChar).Value = hodRemarks;
con.Open();
com.ExecuteNonQuery();
con.Close();
string query2 = "INSERT INTO DetailRequest (ID,Req_Document,Description,Approval) VALUES (@ID,@Req_Document,@Description,@Approval)";
SqlConnection con2 = new SqlConnection(constr);
SqlCommand com2 = new SqlCommand(query2, con2);
com2.Parameters.Add("@ID", SqlDbType.Int).Value = id;
com2.Parameters.Add("@Req_Document", SqlDbType.NVarChar).Value = requestDocument;
com2.Parameters.Add("@Description", SqlDbType.NVarChar).Value = det_Description;
com2.Parameters.Add("@Approval", SqlDbType.NVarChar).Value = hodApproval;
con2.Open();
com2.ExecuteNonQuery();
con2.Close();
string query3 = "INSERT INTO ITEMS (ID,Code,Name,Quantity) VALUES (@ID,@Code,@Name,@Quantity)";
SqlConnection con3 = new SqlConnection(constr);
SqlCommand com3 = new SqlCommand(query3, con3);
com3.Parameters.Add("@ID", SqlDbType.Int).Value = id;
com3.Parameters.Add("@Code", SqlDbType.NVarChar).Value = code;
com3.Parameters.Add("@Name", SqlDbType.NVarChar).Value = name;
com3.Parameters.Add("@Quantity", SqlDbType.Int).Value = qty;
con3.Open();
com3.ExecuteNonQuery();
con3.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{
MasterRequest_DAL helper = new MasterRequest_DAL();
PlannedMaterialRequest pnd = new PlannedMaterialRequest();
ItemsHandling itm = new ItemsHandling();
string[] labelName = new string[100];
string[] coder = new string[100];
string[] quantity = new string[100];
if (TextBox6.Text != "0")
{
labelName[1] = itm.Code(0).ToString();
labelName[2] = TextBox6.Text;
helper.InsertPlannedMaterialMasterRequest(Convert.ToInt32(TextBox1.Text), TextBox2.Text, TextBox4.Text, DropDownList6.SelectedValue, DropDownList2.SelectedValue, Convert.ToInt32(TextBox11.Text), TextBox12.Text, TextBox13.Text, Label8.Text, Convert.ToInt32(TextBox6.Text), labelName[1]);
}
if (TextBox12.Text != "0")
{
labelName[1] = itm.Code(1).ToString();
labelName[2] = TextBox12.Text;
helper.InsertPlannedMaterialMasterRequest(Convert.ToInt32(TextBox1.Text), TextBox2.Text, TextBox4.Text, DropDownList6.SelectedValue, DropDownList2.SelectedValue, Convert.ToInt32(TextBox11.Text), TextBox12.Text, TextBox13.Text, Label12.Text, Convert.ToInt32(TextBox8.Text), labelName[1]);
}
}
The problem I am facing is that using the above code. The ID goes multiple times in MasterRequest table which should go only once, while the same ID must go to Items table multiple times as per the quantities being entered. I want only the ID to go into MasterRequest table just once not multiple times.
|
|
|
|
|
Do you want to say the it insert data into the MasterRequest table multiple times? Is there any postback issues.
|
|
|
|
|
yes this is exactly what it is happening. I just want the ID to enter into Master Request table for once while the same ID to enter into ITEMS table as many times the quantities are entered.
|
|
|
|
|
Thanks to all who assisted. My little flow calculator, ugly stepchild that it is, works nicely now.
My boss thanks you, my HP-15c calculator thanks you; my work PC has mixed feelings...
For the next version I'm going to figure out how to draw my pipe and channel cross-sections, rather than do them in AutoCAD, export them to pdf in CutePDF, import them and resize them in GIMP 2, then save them as jpg so Windows can render them.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Great. This may be the right time to write that long overdue second article, and tell us a bit about flow equations.
PS: points for a unique subject line!
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I'm sure the world can wait for another article from me. I'm a decent writer, but a lousy programmer. Maybe when I get around to cleaning it up, adding validation code, and making the images self-drawing I'll consider posting it.
But since you asked, Manning's equation is used to calculate fluid flows in an open channel, and works well enough in a closed pipe to use as a general purpose calculation. It's based on empirical measurements, and doesn't rely on knowledge of the type of flow (turbulent or laminar) or the viscosity (which leads to a whole bunch of details). Simply stated:
V, ft/sec = (1.486/n) * R2/3 * S1/2 where,
n = Manning's coefficient, a frictional factor determined by the material of the channel,
R = Hydraulic radius
S = Slope
The hydraulic radius is simply, R = A/P, where A is the cross-sectional area of the fluid flow, and P is the wetted perimeter of the pipe or channel. While the basic equation is easy, these parameters are difficult to calculate. As an exercise for the student, try determining the area of a water flow that fills a pipe only 1/3; it's not a trivial solution.
The goal in designing a sewer pipe is to keep the flow rate between 2 and 10 ft/sec. Any slower, material will tend to accumulate in the pipe rather than flow through smoothly. Above 10 ft/sec, though, the momentum of the water will cause pipes to shift and separate at curves and tees. Water also becomes corrosive at high flow rates, causing erosion of the pipes.
I use the equation to iterate through various slopes assuming minimal flow levels and nearly full levels to arrive at a slope that will meet both constraints. Then I calculate the maximum gpm the pipe can carry and compare it to the load the line is expected to carry. If it's not enough, I pick a larger pipe and start over.
As you can see, it's tedious, and this little app will save me hours!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Thanks. That information too would be welcome in an article; focus doesn't have to be on the code, the application domain itself can be interesting too. Throw in a few drawings/photo's, some typical values for Manning's coefficient, the units to be used in the formula(s), and we can get a pleasant read out of it.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Congratulations
Roger Wright wrote: do them in AutoCAD, export them to pdf in CutePDF, import them and resize them in GIMP 2, then save them as jpg
Yeah, just drawing them will be way easier!
If you're using WinForms (I seem to remember you were) then the easiest way to start is to draw your own control and drop that on a form rather than try to draw on the form itself. A Panel is a good control to derive from for this.
The little snippet below shows the basic principle - I've made this control redraw and realign a legend when the Padding property changes as an example.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace RogerWright.Drawing
{
public class DrawingSurface : Panel
{
private const string Legend = "Drawing Surface";
public DrawingSurface()
{
DoubleBuffered = true;
}
private Rectangle GetLayoutRectangle()
{
return new Rectangle(
Padding.Left,
Padding.Top,
Width - Padding.Horizontal,
Height - Padding.Vertical);
}
protected override void OnPaddingChanged(EventArgs e)
{
Invalidate();
base.OnPaddingChanged(e);
}
protected override void OnPaint(PaintEventArgs e)
{
Rectangle layoutRectangle = GetLayoutRectangle();
using (Brush textBrush = new SolidBrush(ForeColor))
{
e.Graphics.DrawString(Legend, Font, textBrush, layoutRectangle);
}
float yOffset = e.Graphics.MeasureString(Legend, Font).Height;
base.OnPaint(e);
}
}
} Hope it helps!
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks, Dave! I spent days trying to figure it out, and gave up in frustration, as I have done over and over for 15+ years. My first intro to graphics in the Microsoft world was an utterly useless tutorial called 'Scribble' - it's crippled me for life, I think.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
I tried the past few nights to apply what I think you were trying to show me, but I'm lost. I hope maybe you can steer me in the right direction.
I made a user control, derived from UserControl, added a few buttons and textboxes, and reserved space for a graphic. To wit:
namespace MyPanel
{
public partial class FlowPanel : UserControl
{
public FlowPanel()
{
InitializeComponent();
Graphics dc = this.CreateGraphics();
this.Show();
Pen bluePen = new Pen(Color.Blue, 3);
dc.DrawRectangle(bluePen, 170, 10, 100, 100);
}
}
}
The Designer added the appropriate controls:
private System.Windows.Forms.GroupBox gbSelect;
private System.Windows.Forms.RadioButton rbTrap;
private System.Windows.Forms.RadioButton rbRect;
private System.Windows.Forms.RadioButton rbCircular;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
In the constructor above I added a device context and method calls to draw a rectangle 100 x 100 to the right of the other controls. There are no error messages or warnings, but when I add the skeleton control to a test form, nothing draws. The other elements look great - positioned right where I want them. I don't understand why the drawing part doesn't work, since I copied it almost word for word from a text that has been otherwise reliable.
Is a UserControl unable to support graphic operations like a Panel? I did try to put a Panel in the UserControl, but I couldn't find anyplace to add the drawing code - there's no constructor I can add to.
Any suggestions will be greatly appreciated...
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Hi Roger,
You're nearly there! Firstly a few comments/points...
1. Dispose of anything that is disposable if you are creating it yourself. In your code above dc and bluePen should both be disposed as you have created them.
1a. If the system creates them for you (i.e. if you used Pens.Blue instead) then don't dispose!
1b. If you are storing them in class member variables for use elsewhere, make sure they are disposed of in the class's Dispose method instead.
1c. If 1a and 1b don't apply, wrapping in a using block automatically disposes for you:
using (Pen bluePen = new Pen(Color.Blue, 3))
{
}
2. Drawing anywhere but in OnPaint is sure to create you problems. The window/control will repaint for many reasons - if another window is moved over or from the top, restore from minimized, resized etc... If you are drawing in the contructor, that is never going to get called when such things happen so your drawing will disappear! Also, creating your own Graphics is an expensive operation, OnPaint supplies you one for free! OnPaint gets called automatically when any repainting is required. You can force it by calling Invalidate(); as well.
To get yourself an OnPaint method, override the existing one. The free Graphics object is available as e.Graphics . So the code in your constructor can be moved and becomes:
protected override void OnPaint(PaintEventArgs e)
{
using (Pen bluePen = new Pen(Color.Blue, 3))
{
e.Graphics.DrawRectangle(bluePen, 170, 10, 100, 100);
}
base.OnPaint(e);
}
If you need any more help, post back. Always happy to help if I can
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Thanks, Dave... works great!
I haven't a clue why, but it does.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Cool
|
|
|
|
|
Most excellent!
/ravi
|
|
|
|
|
Roger Wright wrote: my work PC has mixed feelings...
I know what would cheer it up...
|
|
|
|
|
How to use C # to implement a user management module, the main function of the user add and remove.
|
|
|
|
|
1) The title of your message doesn't say anything about your problem. Every message in this Forum is about C#.
2) A "user management module" could be a lot of things. I have no idea what specifically you need help with.
3) What have you tried so far? Where is it giving you problems?
CQ de W5ALT
Walt Fair, Jr., P. E.
Comport Computing
Specializing in Technical Engineering Software
|
|
|
|
|
I know this is not a big problem, but I'm not familiar with C #, so I do not know how to connect to the database.
|
|
|
|
|
Are you trying to add and remove SQL Server users? Use System.Data.SqlClient.SqlCommand to execute commands against SQL Server and get back results. Google for "SQL Server create user", "SQL Server 2005 create login" and the like and you'll come across which commands you need to perform the SQL Server operations. You might also consider SMO, but that sometimes has problems depending on the version of SQL Server you are using. Some other tips:
*SqlConnection (a C# class available via the .Net Framework) will help you connect to the database.
*SqlConnection requires a connection string. Use SqlConnectionStringBuilder (another C# class) to create one.
*Make sure you have SQL Server Management Studio installed and you are able to browse a database using it (I am assuming you are using SQL Server since you didn't mention what database you are using).
Play around with that stuff a bit. It might take you some time to get things working, but that's all part of the learning process. Ask us when you have SPECIFIC questions, after you've already tried searching and trying things. Good luck.
|
|
|
|
|
|
Make Up Forever wrote: user add and remove
Manager.Add(user);
Manager.Delete(user);
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Individuality is fine, as long as we do it together - F. Burns
|
|
|
|
|