Sunday, 19 July 2020

Consuming Webserive in DOTNET C#.net C sharp .net

Here I am consuming test webservice of Meeseva

Lets Create a sample Application

I am taking a DropDown to check whether the user having Income Certificate or not. If so the certificate number is supplied to our application and after pressing getData button the details of the certificate are populated and shown in our application.

To do this lets create our design page i.e., income.aspx page..

Create a panel with the controls:

 <asp:Panel ID="income_panel" runat="server">
                <table>
                    <tr>
                        <td colspan="2" align="center" style="font-size: 20px; font-weight: bold; color: darkblue">Consuming Web Service
                            <br />
                            <br />
                        </td>
                    </tr>
                    <tr>
                        <td align="right" style="width: 50%">
                            <asp:Label ID="Label99" runat="server" Font-Bold="true" Text="Do you belongs to Fee-Exemption  category ? (Y/N):"></asp:Label>
                        </td>
                        <td align="left" class="auto-style1">
                            <asp:DropDownList ID="ddl_income" runat="server" Width="93px" AutoPostBack="True" Height="30px" OnSelectedIndexChanged="ddl_income_SelectedIndexChanged">
                                <asp:ListItem Selected="True" Value="1">--Select--</asp:ListItem>
                                <asp:ListItem Value="N">NO</asp:ListItem>
                                <asp:ListItem Value="Y">YES</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center" style="width: 50%">
                            <asp:Label ID="lbl_inc_msg" runat="server" Font-Bold="true" ForeColor="Green" Font-Size="15px"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <asp:Label ID="lbl_inc_cer" runat="server" Font-Bold="true" Text="Enter Income Certificate No :"></asp:Label>

                        </td>
                        <td align="left" class="auto-style1">
                            <br />
                            <asp:TextBox ID="txt_inc" runat="server" ValidationGroup="income" MaxLength="14"></asp:TextBox>
                            <asp:Button ID="btn_income" runat="server" Text="GetData" OnClick="btn_income_Click" />
                            <asp:RequiredFieldValidator ID="rqfv_income_no" runat="server" ErrorMessage="*Required" ControlToValidate="txt_inc" ValidationGroup="income" ForeColor="Red"></asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ID="rgfv_income_no" runat="server" ErrorMessage="Invalid Income Certificate Number" ControlToValidate="txt_inc" ValidationGroup="income" ForeColor="Red" ValidationExpression="IC[0-9]{12,12}"></asp:RegularExpressionValidator>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2">
                            <div id="div_inc_online" runat="server">
                                <table width="100%" class='box'>
                                    <tr style="background-color: aquamarine">
                                        <td colspan="2" align="center" style="font-size: 20px; font-weight: bold; color: green">Online Income Certificate Details</td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="Label10" runat="server" Font-Bold="true" Text="Certificate Number :"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lbl_inc_cer_no" runat="server"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="Label14" runat="server" Font-Bold="true" Text="Name:"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lbl_inc_name" runat="server"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="Label18" runat="server" Font-Bold="true" Text="Father Name:"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lbl_inc_fname" runat="server"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="Label20" runat="server" Font-Bold="true" Text="Date of Birth:"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lbl_inc_dob" runat="server"></asp:Label>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="Label22" runat="server" Font-Bold="true" Text="Total Income:"></asp:Label>
                                        </td>
                                        <td align="left">
                                            <asp:Label ID="lbl_inc_inc" runat="server"></asp:Label>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                   
                </table>
          <asp:HiddenField ID="hid_mobile" runat="server"></asp:HiddenField>
            </asp:Panel>

The Image of the page looks like








Now Lets create our CS page with the code behind for each control:

The CS Code is

 protected void Page_Load(object sender, EventArgs e)
    {
        lbl_inc_cer.Visible = false;
        txt_inc.Visible = false;
        income_panel.Visible = false;

        lbl_inc_cer_no.Visible = false;

        lbl_inc_msg.Text = "";

        btn_income.Visible = false;
    }

    protected void ddl_income_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddl_income.SelectedValue == "Y")
        {
            lbl_inc_cer.Visible = true;
            txt_inc.Visible = true;
            income_panel.Visible = true;
         
            lbl_inc_cer_no.Visible = true;

            lbl_inc_msg.Text = "";
        
            btn_income.Visible = true;
        }
        else
        {
            lbl_inc_cer.Visible = false;
            txt_inc.Visible = false;
            income_panel.Visible = false;
           
            lbl_inc_cer_no.Visible = false;

            lbl_inc_msg.Text = "";
         
            btn_income.Visible = false;
        }
    }

    protected void btn_income_Click(object sender, EventArgs e)
    {
        this.Validate();
        if (!this.IsValid) return;
        Get_service_data();
        div_inc_online.Visible = true;
        //string mobile = Session["mobileno"].ToString();
        string mobile = hid_mobile.Value.ToString();
     
    }

    public void Get_service_data()
    {
        XmlDocument xmldoc = new XmlDocument();
        string uname, pwd;
        uname = "APCET";
        pwd = "************"; // Provide the Password Here

  IncomeService.MeeSevaTransactions CI = new IncomeService.MeeSevaTransactions();


        if (txt_inc.Text == "")
        {
            lbl_inc_msg.Text = "Certificate Number not given";
            return;
        }
        else if (txt_inc.Text != "")
        {
            string inc_cer_no = txt_inc.Text;
            string response;
            try
            {
                response = CI.GetDetailsByAppNo(inc_cer_no, uname, pwd);
                xmldoc.LoadXml(response);
                //Response.Write("meeseva income Response:" + response.ToString().Trim());

            }
            catch (Exception ex)
            {
                // Response.Write("Meeseva Service Error" + ex.Message.ToString());
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Not Fetching the Data from Service.Please try again.')", true);
            
                div_inc_online.Visible = false;


            }

            if (xmldoc.SelectSingleNode("//Application_Number") != null)
            {
                if (xmldoc.SelectSingleNode("//Applicant_Name") != null)
                    lbl_inc_name.Text = xmldoc.SelectSingleNode("//Applicant_Name").InnerText;
                if (xmldoc.SelectSingleNode("//FatHus_Name") != null)
                    lbl_inc_fname.Text = xmldoc.SelectSingleNode("//FatHus_Name").InnerText;
                if (xmldoc.SelectSingleNode("//Date_Of_Birth") != null)
                    lbl_inc_dob.Text = xmldoc.SelectSingleNode("//Date_Of_Birth").InnerText;
                if (xmldoc.SelectSingleNode("//Application_Number") != null)
                    lbl_inc_cer_no.Text = xmldoc.SelectSingleNode("//Application_Number").InnerText;
                if (xmldoc.SelectSingleNode("//Total_Income") != null)
                    lbl_inc_inc.Text = xmldoc.SelectSingleNode("//Total_Income").InnerText;

                //Send OTP
                string mobile = hid_mobile.Value.ToString();
                    
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('No Data Available .')", true);

            }
        }


    }

So Now the IncomeService is to be included in our Project To do this follow the steps

Adding a Web Service Reference in the ASP.Net Web Application

The most important task when consuming a Web Service in an ASP.Net Web Application is adding the Web Service reference into the ASP.Net web application. So how to add it? Let us see the procedure.

Right-click on the ASP.Net Web Application and click on "Add Service Reference" as in the following:
AddServiRef.png 

 Now Give the URL provided for you in the following dialog BOX

 After Providing the URL click Go, the service is populated in the below Dialog where the services are shown.. And provide a Namespace , Here I have given as "IncomeService"
Click on Advanced Button, 
Click On Add Web Reference button in the advanced dialog box ,
Click the AddReference Button, You will get a new web reference in Solution Explorer
As shown in above Picture, Now Run the Program note that the Same Webservice name used in our CS page Which was highlighted in CS Code i.e., IncomeService










Monday, 10 September 2018

How to change the root password for MySQL in XAMPP

Method 1: reset XAMPP MySQL root password through web interface:

After you started your XAMPP server, go to the browser and type the URL http://localhost/security/ (incase you’ve modified XAMPP server port, you need to include that port number also in previous URL). The security page will be shown where you can change the root password for MySQL. This will update the phpMyAdmin config also.

Method 2: reset XAMPP MySQL root password through SQL update:

  1. Start the Apache Server and MySQL instances from the XAMPP control panel.
  2. After the server started, open any web browser and give http://localhost:8090/phpmyadmin/ (if you are running XAMPP on 8090 port). This will open the phpMyAdmin interface. Using this interface we can manager the MySQL server from the web browser.
  3. In the phpMyAdmin window, select SQL tab from the right panel. This will open the SQL tab where we can run the SQL queries.
  4. Now type the following query in the textarea and click Go
    UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root'; FLUSH PRIVILEGES;
  5. Now you will see a message saying that the query has been executed successfully.
  6. If you refresh the page, you will be getting a error message. This is because the phpMyAdmin configuration file is not aware of our newly set root passoword. To do this we have to modify the phpMyAdmin config file.
  7. Open the file [XAMPP Installation Path] / phpmyadmin / config.inc.php in your favorite text editor.
  8. Search for the string $cfg\['Servers'\]\[$i\]['password'] = ''; and change it to like this, $cfg\['Servers'\]\[$i\]['password'] = 'password'; Here the ‘password’ is what we set to the root user using the SQL query.
  9. Now all set to go. Save the config.inc.php file and restart the XAMPP server.

Method 3: reset XAMPP MySQL root password through Command Prompt



Set the mysql/bin folder path to the environment variables $path and $temp in computer

Run the mysql in xamp server.

and execute the following command in command prompt (Don't forget to choose 'Run as Administrator' option while selecting command prompt)

c:\>mysqladmin.exe -u root password root_password (provide your root_password).

All set, now connect to mysql using the following command

c:\>mysql -u root -p
Enter password: *********
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.4.20-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> > show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
| test               |
+--------------------+
5 rows in set (0.023 sec)

The above command shows list of databases in mysql. 

Wednesday, 1 August 2018

Facybox in yii -- show images using fancy box

Previously I used thumbnail image and by clicking on the image the page redirects to another tab which shows complete image in the browser
 I done using this

 echo "<a target='_blank' href='$imagepath'>
        <img class='limg' src='$imagepath' alt='Latest Image' style='width:150px'>
      </a>";

Source link: https://www.w3schools.com/howto/howto_css_thumbnail.asp

Code as

<style>
img {
    border: 1px solid #ddd; /* Gray border */
    border-radius: 4px;  /* Rounded border */
    padding: 5px; /* Some padding */
    width: 150px; /* Set a small width */
}

/* Add a hover effect (blue shadow) */
img:hover {
    box-shadow: 0 0 2px 1px rgba(0, 140, 186, 0.5);
}
</style>
<body>

<a target="_blank" href="img_forest.jpg">
  <img src="img_forest.jpg" alt="Forest">
</a>

</body>

But I am not satisfied with this everyimage I need to open in seperate tabs and check them instead the fancy box looking cool to achieve this in YII download the extension from the below link


https://www.yiiframework.com/extension/fancybox

download the extension and copy the folder fancybox in app_folder/extensions/ location and give permissions to the folder (read and write). 

if(strtoupper((string)$image)!='NIL'){

  echo "<td>";

  echo CHtml::link("<img src='$imagepath' alt='Latest Image' style='width:150px' /><p><b> Updated on $recentimgupd</b></p>","#oimg", array('id'=>'latestimg'));
    /* echo '&lt;div style="display:none"&gt;
    &lt;div id="data"&gt;
        Lorem ipsum dolor sit amet, consectetur adipiscing elit.
    &lt;/div&gt;
    &lt;/div&gt;';  */
echo "<div style='display:none'>;
    <div id='oimg'>
        <a target='_blank' href='$imagepath'><img src='$imagepath' alt='Latest Image' />
         <p><b> Latest Photo Updated on $recentimgupd</b></p></a>
    </div>;
</div>";
 $this->widget('application.extensions.fancybox.EFancyBox', array(
    'target'=>'a#latestimg',
    'config'=>array(
        'scrolling'   => 'yes',
        'titleShow'   => true,
        'mouseEnabled'  => true,
        /* 'prevEffect' => 'none',
        'nextEffect' => 'none',
        'closeBtn' => false,
         'helpers' => (
                  'title' => ('type' => 'inside'),
                  'buttons' => (),
                ),   */
            ),
    )
);

    /* echo "<a target='_blank' href='$imagepath'>
        <img class='limg' src='$imagepath' alt='Latest Image' style='width:150px'>
      </a>"; */
      echo "</td>";
}else{
  echo "<td><center>No Image</center></td>";
}

Thursday, 21 June 2018

MySQL Incorrect datetime value: '0000-00-00 00:00:00' Problem rectification Error 1292 (22007) in mysql

Solution for  ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'created' at row 1

(on MySQL 5.7.13).
I kept getting the Incorrect datetime value: '0000-00-00 00:00:00' error.
Strangely, this worked: SELECT * FROM users WHERE created = '0000-00-00 00:00:00'. I have no idea why the former fails and the latter works... maybe a MySQL bug?

At any case, this UPDATE query worked:
UPDATE users SET created = NULL WHERE CAST(created AS CHAR(20)) = '0000-00-00 00:00:00'
All the best !!!

Install phpMyAdmin in Ubuntu 16.04 LTS

phpMyAdmin is available in the default repositories of Ubuntu operating system. Once LAMP stack is installed and ready, install phpMyAdmin as shown below:


sudo apt-get install phpmyadmin


Install phpmyadmin
Install phpmyadmin
During installing, you’ll be asked to choose the web server that should be automatically configured to run phpMyAdmin. In our case, it is Apache webserver.
Choose apache2 and click OK.
sk@ubuntuserver: ~_002
Select Yes and hit ENTER to configure database for phpmyadmin with dbconfig-common.
sk@ubuntuserver: ~_003
Enter a password for phpmyadmin to register with the database server. If left blank, a random password will be generated.
sk@ubuntuserver: ~_004
Re-enter the password to confirm:
sk@ubuntuserver: ~_005
Oops! You might be encountered with the following error message:
An error occurred while installing the database: 

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using 
password: NO) . Your options are: 
* abort - Causes the operation to fail; you will need to downgrade, 
   reinstall, reconfigure this package, or otherwise manually intervene 
   to continue using it. This will usually also impact your ability to 
   install other packages until the installation failure is resolved. 
* retry - Prompts once more with all the configuration questions 
   (including ones you may have missed due to the debconf priority 
   setting) and makes another attempt at performing the operation. 
* retry (skip questions) - Immediately attempts the operation again, 
   skipping all questions. This is normally useful only if you have 
   solved the underlying problem since the time the error occurred.
sk@ubuntuserver: ~_006
To fix this issue, click OK and abort the phpMyAdmin installation.
sk@ubuntuserver: ~_007
Log in to MariaDB or MySQL prompt with root user using command:
mysql -u root -p
Create a new database and database user for phpMyAdmin and grant full permission to the phpmyadmin user.
For the purpose of this tutorial, I am going to create a database called “phpmyadmindb”, and database user “phpmyadminuser” with password “ubuntu”. Please use a strong password which is very hard to guess in the production environment.
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.0.25-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE phpmyadmindb;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> GRANT ALL ON phpmyadmindb.* TO phpmyadminuser@localhost IDENTIFIED BY 'ubuntu';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> \q
Bye
sk@ubuntuserver: ~_009
Then, edit phpmyadmin/config-db.php file:
sudo nano /etc/phpmyadmin/config-db.php
Replace the database name, database user and its password with the values that you have created earlier.
[...]

$dbuser='phpmyadminuser';
$dbpass='ubuntu';
$basepath='';
$dbname='phpmyadmindb';
$dbserver='localhost';
$dbport='';
$dbtype='mysql';
sk@ubuntuserver: ~_010
Save and close the file.
Next, you must install the following php modules. Otherwise, you will get an error message that says:
The mbstring extension is missing. Please check your PHP configuration.
To install php modules, run:
sudo apt-get install php-mbstring php7.0-mbstring php-gettext
Then, edit Apache webserver config file:
sudo nano /etc/apache2/apache2.conf
Add the following line at the end:
Include /etc/phpmyadmin/apache.conf
sk@ubuntuserver: ~_011
Save and close the file. Restart apache service to take effect the changes.
sudo systemctl restart apache2

Access phpMyAdmin dashboard

Open up the web browser and navigate to http://IP-Address/phpmyadmin.
You should see the following screen. Enter the MariaDB/MySQL ‘root’ user name and its password.
phpMyAdmin - Chromium_012
Congrats! This is how the phpMyAdmin dashboard looks like.
192.168.1.105 - localhost | phpMyAdmin 4.5.4.1deb2ubuntu2 - Chromium_013
From here, you can create, delete, rename, and manage the databases easily.
Source : https://www.ostechnix.com/install-phpmyadmin-with-lamp-stack-on-ubuntu-16-04/