using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Web.Script.Serialization;
using Newtonsoft.Json;
using System.Net;
using System.Collections;
using System.IO;
using System.Diagnostics;
using System.Web.Script.Services;
public partial class module_useregistration : System.Web.UI.Page
{
    public static string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    static MySqlConnection con = new MySqlConnection(constring);
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]
    public static string Add_Complaint(string name, string usernm, string pwds,string designations, string images)
    {
        using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
        {
            using (MySqlCommand cmd = new MySqlCommand("insert into userregsitartion (name,username,password,designation,profilepic,softwaredate,today) values (@name,@username,@password,@designation,@profilepic,@softwaredate,@today)", con))
            {
                if (con.State != ConnectionState.Open) { con.Open(); }
                cmd.Parameters.AddWithValue("@name", name);
              

                cmd.Parameters.AddWithValue("@username", usernm);
                cmd.Parameters.AddWithValue("@password", pwds);
              
                cmd.Parameters.AddWithValue("@profilepic", images);
                cmd.Parameters.AddWithValue("@designation", designations);
                cmd.Parameters.AddWithValue("@softwaredate", DateTime.UtcNow.ToString("yyyy/MM/dd"));
                cmd.Parameters.AddWithValue("@today", DateTime.UtcNow.ToString("yyyy/MM/dd"));


                cmd.ExecuteNonQuery();
                con.Close();

            }
        }
        return "submit";
    }

    [WebMethod]
    public static string Show()
    {
        string _data = "";
        using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
        {
            using (MySqlCommand cmd = new MySqlCommand("select userregsitartion.*,userregsitartion.id as usersid from userregsitartion ", con))
            {
                DataSet ds = new DataSet();
                if (con.State != ConnectionState.Open) { con.Open(); }
                using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
                {
                    da.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        _data = JsonConvert.SerializeObject(ds.Tables[0]);
                    }
                    con.Close();

                }
            }
        }
        return _data;
    }

    [WebMethod]
    public static string Edit(int Id)
    {
        string _data2 = "";
        using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
        {
            using (MySqlCommand cmd2 = new MySqlCommand("SELECT * from userregsitartion where id = " + Id, con))
            {
                DataSet ds2 = new DataSet();
                if (con.State != ConnectionState.Open) { con.Open(); }
                using (MySqlDataAdapter da2 = new MySqlDataAdapter(cmd2))
                {
                    da2.Fill(ds2);
                    if (ds2.Tables[0].Rows.Count > 0)
                    {
                        _data2 = JsonConvert.SerializeObject(ds2.Tables[0]);
                    }
                    con.Close();
                }
            }
        }
        return _data2;
    }

    [WebMethod]
    public static string Update(string id,  string name,  string usernm, string pwds,string designations, string images)
    {
        string data = "";
        if (images != null)
        {
            using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
            {
                using (MySqlCommand cmd = new MySqlCommand("update userregsitartion set name =@name,username = @username,password = @password,designation=@designation,today=@today,profilepic=@profilepic where id ='" + id + "'", con))
                {
                    if (con.State != ConnectionState.Open) { con.Open(); }
                    cmd.Parameters.AddWithValue("@name", name);
                  

                    cmd.Parameters.AddWithValue("@username", usernm);
                    cmd.Parameters.AddWithValue("@password", pwds);
                 
                    cmd.Parameters.AddWithValue("@profilepic", images);
                    cmd.Parameters.AddWithValue("@designation", designations);
                    cmd.Parameters.AddWithValue("@today", DateTime.UtcNow.ToString("yyyy/MM/dd"));

                    cmd.ExecuteNonQuery();
                    con.Close();
                    data = "submit";

                }
            }
        }
        return data;
    }

    [WebMethod]
    public static void DeleteData(int Id)
    {
        using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
        {
            using (MySqlCommand cmd = new MySqlCommand("delete from userregsitartion where id =" + Id, con))
            {
                if (con.State != ConnectionState.Open) { con.Open(); }
                cmd.ExecuteNonQuery();
                con.Close();
            }
        }
    }
}