|
Hello, i have trie this code and i get only the values of the date selectionned, but i need to show if the currect date does not exist, to show the previews values in crystal repor, how can i use previous () fonction?
for example
if ({myadate.datelqd}={?date}) then{mydate.restrlqd}={mydate.restrlqd}
else if mydate does not exists then show previews value
here is what i have tried
if ({?date}={mydate.datelqd}) then {mydate.restrlqd}={mydate.restrlqd}
but I want that when the requested date is not in the database, that I display the last recording for example
on 10/12/2021 i have qty = 55
on 13/12/2021 i qty = 85
on 14/12/2021 I have qty = 55
when I enter 12/12/2021 for example, let it display the data for 10/12/2021 where the qty = 55
modified 14-Dec-21 14:52pm.
|
|
|
|
|
|
Let's write our own Point class
using System;
namespace PointNamespace
{
public class Point
{
public int X{get;set;}
public int Y{get;set;}
public Point(int x = 0,int y=0)
{
X = x;
Y = y;
}
public bool TryParse(string s,out Point p)
{
}
public override string ToString()
{
return string.Format("({0},{1})",X,Y);
}
}
}
How can I write TryParse method
I would like to use methods like
string.Trim() ,
int.TryParse(string s, out int d),
string.IndexOf(); // Here is few overloads and which should I choose
string.Substring(int startIndex,int length);
Format of parsed string is shown in ToString method
Suppose we want also version for double coordinates
how method TryParse should look like then
In my native language comma and dot are switched in meaning when displaying
numbers and C# includes that
|
|
|
|
|
Think about what you are trying to achieve here. Your point class is constrained to using integers so you can put in a constraint that you only accept integers in your string so you can remove any "requirement" that is decimal based. You also have to decide what format you are going to accept your string in, and set rules on it. Personally speaking, I would use Point.Parse[^] as an example.
|
|
|
|
|
Point.Parse does not seem to cater for the fact that the OP has 'swapped' commas and periods in his/her locale. Nor is it clear if the '(' and ')' are mandatory / banned / optional. The best that I have come up with is ...
public static bool TryParse(string s, out Point p)
{
int x = 0;
int y = 0;
string unparenthesisedValue =
s.StartsWith("(") && s.EndsWith(")")
? s.Substring(1, s.Length - 2)
: s;
string[] parts = unparenthesisedValue.Split(',');
if (parts.Length != 2)
parts = unparenthesisedValue.Split('.');
bool validPoint =
parts.Length == 2
&& int.TryParse(parts[0], out x)
&& int.TryParse(parts[1], out y);
p = new Point(x, y);
return validPoint;
}
This will parse with '(' and ')' as optional (both or neither; but not just one of the pair; either ',' or '.' as separator; any spaces either side of the numbers. If you have more than one '.' or ',' it gets rejected as there are either too many components of you have floating point nos.
|
|
|
|
|
You don't have to check for parens before deleting them. This will work:
s = s.Replace("(", "").Replace(")", "").Replace(" ", "").Trim();
I would also make the parser work more generally:
List<string> parts = new List<string>();
parts.AddRange(s.Split(new char[]{',' }, 2));
while (parts.Count < 2)
{
parts.Add("0");
}
for(int i = 0; i < parts.Count; i++)
{
int value;
if (Int32.TryParse(parts[i], out value))
{
parts[i] = value.ToString();
}
else
{
parts[i] = "0";
}
}
At this point you now have a reasonably valid list of values, and you can use the .net Int32.TryParse() method.
int x;
if (!Int32.TryParse(parts[0], out x))
{
x = 0;
}
int y;
if (!Int32.TryParse(parts[0], out y))
{
y = 0;
}
Point myPoint = new Point(x,y);
EDIT ====================
Fixed some code typos
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 15-Dec-21 13:03pm.
|
|
|
|
|
All good points (no pun on Point() intended). But it depends on what Point.TryParse() is meant to be parsing. A text like )(, could be parsed as meaning (0, 0) which (I think) your modifications allow, or it could be treated as being syntactically invalid. We don't have a specification of what the OP had intended to be valid and what was intended to be invalid.
|
|
|
|
|
In the absence of a well-defined specification, make it up as you go. My assumptions are valid, and will provide a valid "point" object regardless of the supplied data. I would prefer to return unintended data rather than stop the app with an exception.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
modified 15-Dec-21 13:05pm.
|
|
|
|
|
Hi!
Im having some problem in my function to search on all users in my active directory, root and subtree.
my ad is like this:
ad.company
-> se.ad.company
-> fin.ad.company
-> no.ad.company
I can search , but only get some results from ad.company, not the other subtree directorys.
What have i done wrong?
And this is my code:
private void AutoCompleteTextBox_ReferenceUser()
{
try
{
var attributeName = "sn";
string OU = "DC=ad,DC=company";
var searchString = textBox_manager.Text;
var ent = new DirectoryEntry("GC://" + OU);
var mySearcher = new DirectorySearcher(ent);
mySearcher.Filter = string.Format("(&(anr={0})(objectCategory=user)(objectClass=user))", attributeName, searchString);
SearchResultCollection result = mySearcher.FindAll();
List<string> names = new List<string>();
foreach(SearchResult sr in result)
{
var n = sr.Properties["cn"][0].ToString();
if (!names.Contains(n))
{
stringCollection.Add(n);
}
}
textBox_referenceuser.AutoCompleteMode = AutoCompleteMode.Suggest;
textBox_referenceuser.AutoCompleteSource = AutoCompleteSource.CustomSource;
textBox_referenceuser.AutoCompleteCustomSource = stringCollection;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
|
|
|
|
|
jwradhe wrote: I can search , but only get some results from ad.company, not the other subtree directorys. This statement doesn't make sense to me, because all of the subtrees you've listed contain "ad.company" as part of their names.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I am trying to access the Authors fields from a picture.
I am using System.Windows.Media.Imaging;
My code:
BitmapSource img = BitmapFrame.Create(fs);
BitmapMetadata md = (BitmapMetadata)img.Metadata;
lblTitle.Text = md.Title;
lblSubject.Text = md.Subject;
lblAuthors.Text = md.Author;
lblComments.Text = md.Comment;
lblDateTaken.Text = md.DateTaken;
It doesn't like highlighted line:
Cannot implicitely convert type "System.Collections.ObjectModel.ReadOnlyCollection<string> to <string>.
Evidently, I don't have a good enough grasp of C#. Can anyone help?
Thanks in advance.
|
|
|
|
|
The Author property does not return a string: BitmapMetadata.Author Property (System.Windows.Media.Imaging) | Microsoft Docs[^]
It returns a collection of strings, one for each author - since there can be multiple author credits, a single string would not work well.
That's what the error is saying: you can't convert a ReadOnlyCollection of strings to a string - you need to either retriev the first, or work out what to do when you do get multiple authors.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
So how do I process that collection of strings?
|
|
|
|
|
Depends on what you want to do with the author(s)...
BitmapMetadata.Author is a collection of strings, and it implements IEnumerable. So one of the things you could do is
string authors=string.Join(", ", md.Author);
Or turn them into an array like so:
string[] authors=bmd.Author.ToArray();
Or submit them to some LINQ magic...
Luc Pattyn [My Articles]
If you can't find it on YouTube try TikTok...
|
|
|
|
|
Luc, you are on my Christmas list. Thank you! Your first reply worked perfectly, and gave me exactly the results I needed!
|
|
|
|
|
How do you check to see if the string collection is null first? Now my program is crashing because of that.
|
|
|
|
|
|
string authors = string.Join(", ", md.Author ?? new string[] { "<nn>" });
That didn't work.
Operator '??" cannot be applied to operands of type 'ReadOnlyCollection<string>; and 'string[]'
Thank you.
|
|
|
|
|
Use simple statements:
if (md.Author != null)
{
string[] authors = md.Author;
}
else
{
}
|
|
|
|
|
Try:
string authors = string.Join(", ", md.Author.AsEnumerable() ?? Array.Empty<string>());
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Good afternoon,
I am adding a spot to create the initial Access DB for my program and I am able to get the tables & columns created just fine.
I have one column that has program specific information, (ex: paydays (weekly, 2x month, bi monthly, monthly, etc.)
Where can I find information as to how to load that specific information from a list or something into that one specific column? There are 5 or 6 items.
Richard
Disable Vet
Grandfather
Pain in the @ss
|
|
|
|
|
The best idea is not to: create a second table that contains each of the various options and has two columns: an ID (can be integer) and a description.
Then your main table contains ID values which are a foreign key to the new table.
That way, you can only hold valid values, and people don't add new ones by mistake by mistyping, or adding punctuation, or the wrong case.
Access is a relational database, and relations between tables are one of the things it is good at: See SQL JOINs for more info: SQL Joins[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I agree with @OriginalGriff but over 20 years ago I had a requirement to do what you wanted (I forget the details now), probably for a report or some such. The code that I used was ...
(This code was run in-stream as a column inside the query in MS-Access, not as 'external' C# accessing an Ms-Access table)
Function MakeList( _
ByVal InSQL As String, _
Optional ByVal InColName = 0, _
Optional ByVal InSeparator As String = ",", _
Optional ByVal InDataBase = "" _
) As String
Dim DB As Database
Dim rs
If IsObject(InDataBase) Then
Set DB = InDataBase
Else
Set DB = IIf(InDataBase = "", CurrentDb, OpenDatabase(InDataBase))
End If
Set rs = DB.OpenRecordset(InSQL)
While Not rs.EOF
MakeList = MakeList & InSeparator & rs(InColName)
rs.MoveNext
Wend
rs.Close
DB.Close
MakeList = Mid(MakeList, Len(InSeparator) + 1)
End Function
|
|
|
|
|
I have a asp view.
I need to pass a field to the .cs method
I have a : < form...> with a post method.
This is the field on the .chtml i need to read:
<input type="text" name="username" id="username" class="form-control ewControl" value="@_login.Username" placeholder="@Language.Phrase("Username")" autocomplete="username">
Using this:
<a href= 'login?expire=1' class="btn btn-ic btn-link pkg-photo">Olvide mi clave</a>
the data it is lost when i try to used it on the .cs
Any want can help me?
|
|
|
|
|
An <a> element will navigate to the URL specified by its href attribute. It will not submit the form.
If you want to submit the form instead, use a <button type="submit"></button> or an <input type="submit"/> .
If you want the data to be sent to a different URL than the form's action , use the formaction attribute[^] on the button.
<button type="submit" formaction="login?expire=1" class="btn btn-ic btn-link pkg-photo">Olvide mi clave</button>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|