using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MySql.Data.MySqlClient;
using System.Configuration;
using System.Web.Services;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
public partial class module_bonafideapprove : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]

    public static object GetData()
    {
        string data = " ";
        using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
        {
            using (MySqlCommand cmd = new MySqlCommand("select add_certificates.*,date_format(issuedate,'%d-%m-%Y') as paymentdt from  add_certificates where certtype = 'bonafidecertificate'", con))
            {
                if (con.State != ConnectionState.Open) { con.Open(); }
                DataSet ds = new DataSet();
                using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
                {
                    da.Fill(ds);
                    if (ds.Tables[0].Rows.Count > 0)
                    {
                        data = JsonConvert.SerializeObject(ds.Tables[0]);
                    }
                    con.Close();
                    con.Dispose();
                    cmd.Dispose();
                }
            }
        }
        return data;
    }
    [WebMethod]
    public static string PopulateDropDownListselectmemb(string certiids)
    {
        DataTable dtnew = new DataTable();
        DataTable dtnew1 = new DataTable();
        //    DataTable dt = JsonConvert.DeserializeObject<DataTable>(membersids);
        string data = "";
        string[] splitcertid = certiids.Split(',');
        for (int i = 0; i < splitcertid.Length; i++)
        {
            using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
            {
                using (MySqlCommand cmdnew = new MySqlCommand("SELECT * from add_certificates where   id='" + splitcertid[i].ToString() + "' AND status='Pending For Approval'", con))
                {
                    if (con.State != ConnectionState.Open) { con.Open(); }
                    using (MySqlDataAdapter danew = new MySqlDataAdapter(cmdnew))
                    {
                        danew.Fill(dtnew);
                        con.Close();
                        if (dtnew.Rows.Count > 0)
                        {

                          

                            using (MySqlConnection con1 = new MySqlConnection(ConfigurationManager.ConnectionStrings["conStr"].ConnectionString))
                            {
                                using (MySqlCommand cmdnew1 = new MySqlCommand("update add_certificates set status = 'Approved' where id='" + splitcertid[i].ToString() + "'", con1))
                                {
                                    if (con1.State != ConnectionState.Open) { con1.Open(); }
                                    cmdnew1.ExecuteNonQuery();
                                    data = "approved";
                                    con1.Close();
                                    //using (MySqlDataAdapter danew = new MySqlDataAdapter(cmdnew))
                                    //{
                                    //    danew.Fill(dtnew);
                                    //    con.Close();
                                    //    if (dtnew.Rows.Count > 0)
                                    //    {
                                    //        data = "approved";
                                    //    }
                                    //}
                                }
                            }
                        }
                    }
                }
            }
        }
        return data;
    }
}