|
|
I am creating a Cache Manager that will call a GetCacheItem method to get either a DataTable in cache or if the DataTable is not in cache the GetCacheItem method will make the SQL database call and then put the returned DataTable into cache. The parameters I want to pass to the GetCacheItem method are the cache item key and a delegate of type Func<tresult> with a delegate name of QueryExpression. The problem is that I want the Func<t> QueryExpression delegate to be used by several SQL select statments each with a different number of query parameters. How can I implement the Func<t> delegate to be able to take a different number of parameters each time it is called? Below is an example of what I have so far:
public object GetCacheItem(String sCacheKey, Func<object> QueryExpression)
{
object objCacheItem = null;
if (!CachingEnabled)
{
return objCacheItem;
}
if (CacheItem<object>(sCacheKey) != null)
{
return CacheItem<object>(sCacheKey);
}
else
{
lock (syncObject)
{
if (CacheItem<object>(sCacheKey) != null)
{
return CacheItem<object>(sCacheKey);
}
else
{
Object cacheItem = QueryExpression();
AddToCache<object>(sCacheKey, cacheItem);
return cacheItem;
}
}
}
}
</object></object></object></object></object></object>
NOTE: As you can see my Func<t> delegate only has a return argument and not the list of variable parameters. What do I need to do?
Thanks,
Steve
|
|
|
|
|
NOTE:
I used a dictionary to do this in calls before. The problem is that my boss wants to be able to make SQL calls like the following:
DAC_MANAGER.GetCustomers(string sName, string sAge)
and
DAC_MANAGER.GetEmployees(string id, string position, string payRate)
I talked to him about using dictionaries and he does not want to because this would mean changing every method in the DAC layer to use a dictionary.
|
|
|
|
|
helo... i have a client application which has a tcp listener on port 1000 and a server which connects to the same port.but the server should connect first to the client so when i try to connect Exception occurs like client not accepting the connection.
the cliet is listening in the netstat -an on the port 1000 and in the server when i send then the connection to the client is SYN_SENT and not established... will the windows firewall block these connections ..?
|
|
|
|
|
Yes.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
and if the client connects to the server first then will the firewall block the incomming connecton to the client ?
|
|
|
|
|
|
Hi I have a problem i hgaave a table in data grid view and i am updating data from data using a button. what i need to do is once the user update the data and click on update button i want to convert all string values to lower case. i am not using data table to populate my grid and i am updating using stored procedure. so i dnt know how to convert changed values to Lowercase before updating. can any one help me please.
Thanks
|
|
|
|
|
Hi I have a problem i hgaave a table in data grid view and i am updating data from data using a button. what i need to do is once the user update the data and click on update button i want to convert all string values to lower case. i am not using data table to populate my grid, is their any way that i can do that here is my code i am using to upgrade my grid
private void cmd_update_record_Click(object sender, EventArgs e)
{
if (dgRepair.RowCount == 0)
{
MessageBox.Show("No data available for update");
}
else
{
DataSet ChangedRepDataSet = new DataSet();
ChangedRepDataSet = ds_rep.GetChanges();
if (ChangedRepDataSet != null)
{
// Intializing object of Connectionclass to open connection
conn_obj = new ConnectionClass();
store_connection = conn_obj.connect();
// Sqlcommand object
SqlCommand cmdupdate;
cmdupdate = new SqlCommand();
cmdupdate.CommandType = CommandType.StoredProcedure;
cmdupdate.CommandText = "Update_Status_Grid";
//opening connection
cmdupdate.Connection = store_connection;
store_connection.Open();
//Adding Parameters for Repair table
cmdupdate.Parameters.Add("@OrgDescription", SqlDbType.VarChar, 100, "Description");
cmdupdate.Parameters["@OrgDescription"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@Description", SqlDbType.VarChar, 100, "Description");
cmdupdate.Parameters.Add("@OrgStatus", SqlDbType.VarChar, 15, "Status");
cmdupdate.Parameters["@OrgStatus"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@Status", SqlDbType.VarChar, 15, "Status");
cmdupdate.Parameters.Add("@OrgPartDes", SqlDbType.VarChar, 50, "PartDes");
cmdupdate.Parameters["@OrgPartDes"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@PartDes", SqlDbType.VarChar, 50, "PartDes");
cmdupdate.Parameters.Add("@OrgRepAction", SqlDbType.VarChar, 50, "RepAction");
cmdupdate.Parameters["@OrgRepAction"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@RepAction", SqlDbType.VarChar, 50, "RepAction");
cmdupdate.Parameters.Add("@OrgId", SqlDbType.BigInt ,1000, "Id");
cmdupdate.Parameters["@OrgId"].SourceVersion = DataRowVersion.Original;
//Adding the Parameters for invoice table
cmdupdate.Parameters.Add("@OrgRepCost", SqlDbType.Money, 1000, "RepCost");
cmdupdate.Parameters["@OrgRepCost"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@RepCost", SqlDbType.Money, 1000, "RepCost");
cmdupdate.Parameters.Add("@OrgPaymentPaid", SqlDbType.Money, 1000, "PaymentPaid");
cmdupdate.Parameters["@OrgPaymentPaid"].SourceVersion = DataRowVersion.Original;
cmdupdate.Parameters.Add("@PaymentPaid", SqlDbType.Money, 1000, "PaymentPaid");
da_rep.UpdateCommand = cmdupdate;
if (check == true)
{
try
{
da_rep.Update(ds_rep, "Repair");
ds_rep.AcceptChanges();
}
catch (Exception ex)
{
MessageBox.Show("Their is some problem in updating make sure you are entering right values " +
ex);
}
}
//}
//}
}
else
{
MessageBox.Show("no changes made");
}
//int modifiedRows = da_cus.Update(myChangedDataset);
//MessageBox.Show("Database has been updated successfully:" + no_of_rows_chang + " rows has been changed");
}
can any one help me
Thanks
|
|
|
|
|
First can you please use "CODE Block" tag from now-onwards, for your code. its really hard to read the code without that. If I understand correctly then,
Insterad of
cmdupdate.Parameters["@OrgStatus"].SourceVersion = DataRowVersion.Original;
You can use
cmdupdate.Parameters["@OrgStatus"].SourceVersion = DataRowVersion.Original.ToString().ToLower();
Whenever you are storing string values just use .ToString().ToLower() .
|
|
|
|
|
Thanks for the quick replay and thanks for the advice i will keep it in mind for next time. I tried what you suggest me but it is giving me error that can not convert from row version to string and also i am not using it pass parameter value.
I show you what i am trying
// passing value to the parameter
Parameter Type Column Name
cmdupdate.Parameters.Add("@OrgStatus", SqlDbType.VarChar, 15, "Status").ToString().
ToLower()
it does update the data base but do not convert the value into lower case.
|
|
|
|
|
I believe this can be done in numerous ways. One could be that you use ToLower-method on strings when you set the parameter values.
alwaysgull wrote: i am not using data table to populate my grid
But you seem to get the data to update from a dataset. Another option could be to either modify the data in the dataset or use computed columns. However, I didn't quite figure out why you use DataRowVersion.Original everywhere. Won't that lead to a situation where you update the same values back to the database.
|
|
|
|
|
|
If I remember correctly desktop.ini can help help.
|
|
|
|
|
Hi,
I have a TableLayoutPanel that has a couple of cells I filled with buttons, I can see there's a cell property for each button in that panel that I cant access from code, can you say, change it to change its location within the table??
Thanks guys!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
I am not sure about that but,
To change the location of your controls, you can use TableLayoutPanel.SetRow() And TableLayoutPanel.SetColumn() Method. Just pass your control and change the Row / Column.
|
|
|
|
|
I'm designing a small vector graphics app. Right now I'm writing code for painting a shape as it's being moved. For move operations, the shape is painted to a bitmap buffer so refreshes can be more effecient. Everything is working fine except when the drawing surface is scaled (zoomed).
The scaling factor is applied to the Graphics object when a paint message is called. That scaling factor is also used to generate a scaled "move bitmap" for the shape. For example, if the physical size of the shape is: 100 x 100 and the scaling factor is 50% then the move bitmap will be 50 x 50. The bitmap is then drawn as unscaled.
The problem is that the DrawImageUnscaled() method is not working! I get the same scaled results as if I were calling the DrawImage() method. This is rendering the scaled "move bitmap" to an additionaly scaled size!
Has anyone experienced this before?
//Code sample
private void initMoveBitmap()
{
//if the scaling factor is .50 the GetScaledBounds will produce a 50x50 on a 100x100 size
Rectangle r = shape.GetScaledBounds();
bmpMove = new Bitmap(r.Width, r.Height);
System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(bmpMove);
gr.TranslateTransform(-r.X, -r.Y);
gr.ScaleTransform(scale, scale);
paint_move_bitmap(gr);
gr.Dispose();
gr = null;
}
public void PaintShape(Graphics g)
{
//scenario: the graphics object has a scaling factor of .50
if (bmpMove != null)
//produces no difference from the DrawImage() method
graphics.DrawImageUnscaled(bmpMove, pntBmpPos);
else
//paint the shape.. (code excluded)
}
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
Hi Richard,
let me say for starters I never used DrawImageUnscaled; however this is how I understand the Graphics class: there are two different reasons why DrawImage may scale an image:
1. the transformation stuff (properties and methods relating to Matrix and ScaleTransform);
2. the parameters specifying a destination rectangle, and either the entire source image or a specified rectangular part of it.
AFAIK DrawImageUnscaled removes the second reason by ignoring the width and height if you specify one,
but I don't expect it to ignore the first reason. I expect the ScaleTransform/Matrix to rescale everything, like a Xerox copier could, supporting things such as putting several pages of a document on a single sheet of print.
Hope this helps.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:39 AM
|
|
|
|
|
Hi everyone,
Any idea why might the key_down_even of a form may be inactive?? I'm running a simple form with a tabControl and even when I set the focus back to the form, it doesnt capture the key strokes while it works fine on an empty form!
Please help
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Does the focus remain on the tab control?
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
Ok, I found it, I just had to set the this.KeyPreview to true!
Thanks guys!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Hi guys, I have many controls inside a listbox and am displaying the listbox on the left side of the form. If a control is selected a corrospoding control is displayed on the right side of the form.
Simple.
The selected control from the listbox (right sided) control can be zoom like (75%,50%,25%). So for instance, if I zoom, 75% all the elements
inside the control are zoom as well (reflecting the 75%).
Hope it makes sense. Alright...
But how can I display controls inside the listbox not to be 75%. Because the right side pane hold a refece of the selected control from the listbox. so if right side Control is zoom to 75% all its elements reflect to 75% like(Size/Location). All controls inside the listbox should be zoom to 100%
Form.cs
|---------------------------------------------------
| |
| SplitContainer |
| |--------------------------------------------- |
| | | zoom(75%,50%,25%) | |
| | | |----------------------- | |
| | control1 | | | | |
| | | | | | |
| |-----------| | | | |
| | | | Control 2 | | |
| | control2 | | is being displayed | | |
| | | | and it is selected | | |
| |-----------| | | | |
| | | | | | |
| | control3 | | | | |
| | | ----------------------- | |
| --------------------------------------------- |
| |
|--------------------------------------------------
The way I solved this issue is that during the OnDrawItem event of the listbox I am making a copy of an individual
elements, resetting their Size and Location to the
zoom factor of 100% and then readding to new control.
I would apprecaite for your kind suggestions
Thanks
modified on Wednesday, February 25, 2009 1:57 PM
|
|
|
|
|
If you're applying the scaling to the form where all controls reside then it is obviously going to scale everything, including your listbox. A better option would be to make your controls on the "right-side" to be UserControls. Scaling can be applied to it alone without affecting any other control.
Hope this helps,
Richard
My code this week has no errors. But it's Monday morning and I haven't got out of bed.
|
|
|
|
|
Would splitting your zoom/nonzoomed controls into separate panels and only applying the zoom to the former's panel work?
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 idea. I personally like user controls because it allows you create your layout in design mode. Either method should work.
There cannot be a crisis today; my schedule is already full.
|
|
|
|