Mike Askew 131 Veteran Poster Featured Poster

Howdy

I have a timespan that contain in excess of 24 hours. For the example lets use a value of 1 day 6 hours and 32 minutes.

I would like to get this into a string that displays "30:32".

Have so far tried something along the lines of string.Format("{0}:{1}", TimeSpan.TotalHours, TimeSpan.Minutes) however this gives me a scenario where it'll display 13:0 rather than 13:00 which I also failed to resolve.

Mike Askew 131 Veteran Poster Featured Poster

I'm not sure what you are trying to do?

Mike Askew 131 Veteran Poster Featured Poster
Mike Askew 131 Veteran Poster Featured Poster

I realise I have asked the dumbest question ever, just dawned on me the EndGetResponse returns a HttpWebResponse object.... It's early I tell you!

Mike Askew 131 Veteran Poster Featured Poster

Using code from StackOverflow:

HttpWebRequest webRequest;

void StartWebRequest()
{
    webRequest.BeginGetResponse(new AsyncCallback(FinishWebRequest), null);
}

void FinishWebRequest(IAsyncResult result)
{
    webRequest.EndGetResponse(result);
}

How do you access the response to the request?

Mike Askew 131 Veteran Poster Featured Poster

You should look into using a SQL transaction to execute all of your requests in one go, rather than one at a time.

Mike Askew 131 Veteran Poster Featured Poster

As Suzie said, seeing the code would help here.

Mike Askew 131 Veteran Poster Featured Poster

Hi

So I have a silverlight 5 front end and some PDF generating code that is not silverlight compatible and so needs to sit server side and is called via WCF.

I am struggling to work out how to return the PDF data back to the silverlight application and effectively download the file?

The PDF code currently ends up as a MemoryStream and then need to do something with it from there.

Mike Askew 131 Veteran Poster Featured Poster

Sorry blud, I wasn't aware of the last responses, do you still want email?

Latest amusing email of the day... commented on a post and 5 minutes later got an email telling me about a thread reply... that happened before I even posted/watched the article :D

Edit: Being named blud makes my posts look worse :(

Mike Askew 131 Veteran Poster Featured Poster

There are multiple topics on this in both languages you have posted this under on codeproject which I found in about 10 seconds using Google.

Why do you want to use OpenCV over some of the other libraries available?

Mike Askew 131 Veteran Poster Featured Poster

I hadn't tin and it was the solution, Prit beat you too it

Mike Askew 131 Veteran Poster Featured Poster

Solved

Mike Askew 131 Veteran Poster Featured Poster

Ok time for the 2nd dumb question of the day that I should probably already know the answer too..

I have string.Format(" {0, -22} | {1, 5} of {2, -5} | {3, 5}% | where {3} is a double that is being used for a percentage.

The longest allowed format is 5 characters so capable of support something like 99.99

I currently use string.Format("{0:#.00}", x) for the number going into there which works fine for say 64.29

However for other numbers it doesn't display cleanly.

I want to be able to have like:
100%
90%
90.8%
80.70%
1%
1.5%

So basically looking for a more flexible formatting pattern to put instead of {0:#.00}

Mike Askew 131 Veteran Poster Featured Poster

Good shout, it's Courier New though for monospacing

Mike Askew 131 Veteran Poster Featured Poster

and Prit takes the gold star once again... now to find a fixed width font that looks pretty...

Mike Askew 131 Veteran Poster Featured Poster

Aha shall try that and report back

Mike Askew 131 Veteran Poster Featured Poster

So I have recently come across string.Format("{0, x}", "Word") for aligning strings, with demonstration code that works fine in the CMD.

Does this also function correctly when pumping text to a label? I am finding that it does not behave as expected and instead misaligns the text.

Using an example I nicked off a site

Console.WriteLine("-------------------------------");
Console.WriteLine("First Name | Last Name  |   Age");
Console.WriteLine("-------------------------------");
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Bill", "Gates", 51));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Edna", "Parker", 114));
Console.WriteLine(String.Format("{0,-10} | {1,-10} | {2,5}", "Johnny", "Depp", 44));
Console.WriteLine("-------------------------------");

Is shown to work fine in console however if you look at it within debugging or on a label its completely misaligned.

Are there any alternatives short of using /t to align or building everything up with strings, pad them and then append them onto the string builder I am using?

Mike Askew 131 Veteran Poster Featured Poster

A man who has impacted generation's childhood's. A developer and CEO. Some of his developmental achievements are damn impressive.

A sad day :(

Mike Askew 131 Veteran Poster Featured Poster

Resolved.

Within the DPGlobal.parseDate method it was looking for a format of mm whereas the format was MM so was defaulting to the current month. :)

Mike Askew 131 Veteran Poster Featured Poster

Can you not just restrict access to the folder holding your backups via user permissions on the OS?

savedlema commented: Ok, thank you. +2
Mike Askew 131 Veteran Poster Featured Poster

Just been digging. Traced it down to the constructor.

this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');

and then

this.date = DPGlobal.parseDate(typeof newDate === 'string' ? newDate : (this.isInput ? this.element.prop('value') : this.element.data('date')), this.format);

where

typeof newDate === 'string' ? newDate : (this.isInput ? this.element.prop('value') : this.element.data('date'))

returns "01/01/2010" and then

this.date = DPGlobal.parseDate(typeof newDate === 'string' ? newDate : (this.isInput ? this.element.prop('value') : this.element.data('date')), this.format);

returns "Thu Jul 1 00:00:00 UTC+0100 2010".

I'm presuming something is off in the formatting?

Edit: woo 1k posts xD

Mike Askew 131 Veteran Poster Featured Poster

I've inherited some code utilising the bootstrap framework.

I'm currently seeing some odd behaviour where no matter what date was last picked, the date picker always seems to open showing the month of July. Is there any particular places in the code I should be looking to see if anything funny is happening? Nothing looks out of the ordinary to me and I cannot see a method call setting it's value within the show() event.

Cheers

Mike

Mike Askew 131 Veteran Poster Featured Poster

Howdy

So I have a set of data coming back from a process with five different pieces of data per entry in the set.

Are there any fancy ways you can generate some kind of look-a-like report on the fly in WCF, else what would be the best way to go with presenting the information?

Cheers

Mike

Mike Askew 131 Veteran Poster Featured Poster

I got it yesterday at 10:20am :)

Still a tad late :p

Mike Askew 131 Veteran Poster Featured Poster

I just got the email about the above post, down to 10 mins behind!

Mike Askew 131 Veteran Poster Featured Poster

Yes I turned on the mailing list when you first released it when we all didn't know what to expect :D

Guess I'll settle for hourly! Just got to wait for the backlog to clear

Mike Askew 131 Veteran Poster Featured Poster

Oh my days.

Simple things... I didn't update the field size in db from 50 when moving to hashings. Set to 255 and re-created user and now it works. Issues solved! ++rep

Mike Askew 131 Veteran Poster Featured Poster

Just done some reading on stack overflow. It is correct that I don't see the same as password_hash won't give the same response twice.

So just have to figure out the code error.

Hashing code:

                        $conn = new PDO($dsn, $user, $pass);

                        $sql = "INSERT INTO user (username,password,staff) 
                                VALUES (:username,:password,:staff)";
                        $q = $conn->prepare($sql);
                        $q->execute(array(':username'=>$regUsername, 
                                          ':password'=>password_hash($regPassword, PASSWORD_DEFAULT),
                                          ':staff'=>false));

Compare code:

                        $conn = new PDO($dsn, $user, $pass);

                        $sql = "SELECT * FROM user WHERE username = :user";
                        $q = $conn->prepare($sql);
                        $q->bindParam(':user', $subUsername);
                        $q->execute();

                        $result = $q->fetchAll();
                        echo  $result[0]["password"];

                        if (count($result) > 0 && password_verify($subPassword, $result[0]["password"])) {

                        }
Mike Askew 131 Veteran Poster Featured Poster

jkon, yeah the data is coming through now, just the password hashing that isn't lining up for some reason..

Mike Askew 131 Veteran Poster Featured Poster
password_hash($regPassword, PASSWORD_DEFAULT)

`$2y$10$fVVIZoq1WrgW6trHhp0hCe7jeAeMExKjOJH3dx92rHznCOL2BAsuC`

is generating a different hash for the same password

password_verify($subPassword, $result[0]["password"])

`$2y$10$IHO5FhB62/LrIFyAf0K2quDFe4yN6Jv9z1unzf2EHVL`

Same password entered on both pages but echoing password_hash on the same page as the verify returns the 2nd hash, that differs from the first

Mike Askew 131 Veteran Poster Featured Poster

Ok putting this thread back on topic as to where I am, partially going mad been looking at this all day.

                        $sql = "SELECT * FROM user WHERE username = :user";
                        $q = $conn->prepare($sql);
                        $q->bindParam(':user', $subUsername);
                        $q->execute();

                        $result = $q->fetchAll();
                        print_r($result);

                        if (count($result) > 0 && password_verify($subPassword, $result[0]["password"])) {

The above code works however password_verify appears to be failing when the password is correct and the database version is hashed using password_hash()

Mike Askew 131 Veteran Poster Featured Poster

EDITED

Ok so I get data if I use:

                        $sql = "SELECT * FROM user WHERE username = 'mike'";
                        $q = $conn->prepare($sql);
                        //$q->bindParam(':user', $subUsername);
                        $q->execute();

                        $result = $q->fetchAll();
                        print_r($result);

But as soon as I try changing it to a param it fails to work

                        $sql = "SELECT * FROM user WHERE username = :user";
                        $q = $conn->prepare($sql);
                        $q->bindParam(':user', $subUsername);
                        $q->execute();

                        $result = $q->fetchAll();
                        print_r($result);
Mike Askew 131 Veteran Poster Featured Poster

Yes it does Prit, returns one row, which is all I expect to see. So something on the where must be off...

Mike Askew 131 Veteran Poster Featured Poster

I did also try $result = $q->fetchAll(); which again returned an empty array, so I dont think the FETCH_ASSOC is the route cause :(

Mike Askew 131 Veteran Poster Featured Poster

was just trying it, didnt work without them either.

Have also tried

                        $sql = "SELECT userID, username, password FROM user WHERE username = ?)";
                        $q = $conn->prepare($sql);
                        $q->execute(array($subUsername));
Mike Askew 131 Veteran Poster Featured Poster

I have the following

                        $subUsername = trim($_POST["user"]);
                        $sql = "SELECT userID, username, password FROM user WHERE username = ':user')";
                        $q = $conn->prepare($sql);
                        $q->bindParam(':user', $subUsername);
                        $q->execute();

                        $result = $q->fetch(PDO::FETCHASSOC);
                        print_r($result);
                        echo "</p>";
                        print_r($subUsername);
                        echo "</p>";
                        print_r($subPassword);

However $result is always just an empty array, if I run the SQL on the database it works fine. Is anything obviously wrong?

The username and password print fine using print_r()

Mike Askew 131 Veteran Poster Featured Poster

Only just got the email for a post update 7 hours ago

Mike Askew 131 Veteran Poster Featured Poster

Issue resolved.

upload_max_filesize was 65m
post_max_size was 3m

upped post_max_size to 70m

Kudos to prit also in solving

Mike Askew 131 Veteran Poster Featured Poster

Just noticed [16-Jun-2015 11:10:50 Europe/Paris] PHP Warning: POST Content-Length of 3821214 bytes exceeds the limit of 3145728 bytes in Unknown on line 0 in the error logs when I run it on the desktop. Not sure how I change the limit?

Mike Askew 131 Veteran Poster Featured Poster

Just tried this code on my work laptop rather than desktop.

It all works as expected on there... something must be messed up with my wamp installation on desktop...

Mike Askew 131 Veteran Poster Featured Poster

I can't figure out why but at the minute I have no instant emails about thread updates etc.

Have I got any settings wrong or is something else amiss under the hood?

Mike Askew 131 Veteran Poster Featured Poster

It also seems to erase any form of echo I have on the page, however if the file upload input isn't involved then echoing works fine...

For example if I run the script you posted lps I just get the blank form and no print outs at all on post

Mike Askew 131 Veteran Poster Featured Poster

receiving script currently is

<?php
    $target_dir = "imageuploads/";

    print_r($_POST);
    print_r($_GET);
    print_r($_FILES);
?>

which prints

Array ( ) Array ( ) Array ( )

Strange that it works on lps's local. Maybe I have a setting wrong somewhere?

Mike Askew 131 Veteran Poster Featured Poster

I've abandoned this idea and simplified my goals just to get the project done in time. I would rather submit something than nothing at this point... Thanks for the inputs.

Mike Askew 131 Veteran Poster Featured Poster

Me again...

So now I am confused...

I have a form:

        <form action="addanimal_submit.php" method="post" enctype="multipart/form-data" style="padding-left:10px">
            <p>Name: <input type="text" name="name"></p>
            <p>Date of Birth: <input type="text" name="dateofbirth"></p>
            <p>Description: <input type="text" name="description"></p>
            <p>Available For Adoption? 
                <select type="text" name="available">
                    <option value="1" selected>Yes</option>
                    <option value="0">No</option>
                </select>
            </p>
            <p>Image Of Animal:</p>
            <p><input type="file" name="fileToUpload"></p>
            <input type="submit" name="submit" value="Submit Details" />
        </form>

however when I submit it and echo the vars on the new form, none exist. If I get rid of the <input type="file"> then it magically works. What is the catch with having a file upload and additional data in the same form? It seems awful if you have to make a seperate one just for adding an image?

Mike Askew 131 Veteran Poster Featured Poster

Nailed it Toby.

Was missing some code within the Controller class for the specific report handling certain url actions. Now getting some errors around injection but I can resolve those hopefully. Will mark this as resolved.

Thanks!

Mike Askew 131 Veteran Poster Featured Poster

RouteConfig.cs

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "ConfigJs",
            url: "DScripts/Config.js",
            defaults: new { controller = "General", action = "Config" }
        );


        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "General", action = "Index", id = UrlParameter.Optional }
        );
    }
}

Under the controllers folder I have
- GeneralController
- ReportControllerBase
- NewReportNameController

and the other existing controllers that all work fine.

The above RouteConfig appears to work for everything else

Mike Askew 131 Veteran Poster Featured Poster

Why don't you allow the user to enter the entire number in one go, and then convert it to a Char[]

You can then look at the Char[].Length to see how many they have entered?

Mike Askew 131 Veteran Poster Featured Poster

Url rewrite isn't installed on these servers.

Will try and debug the routing stuff

Mike Askew 131 Veteran Poster Featured Poster

Haven't a clue where the route config is, I can see a RouteConfig.cs class but nothing of interest in it...