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 System.Globalization;

namespace CheckSheet.setting
{
    public partial class RegisterEquipment_inspection_item : System.Web.UI.Page
    {


        [System.Web.Services.WebMethod]
        public static string DeleteRow(string inspectionid)
        {
            string cmdhd = string.Empty;

            using (FcSql.Function fc = new FcSql.Function())
            {
                try
                {

                    string del_mt = string.Format("update InspectionItem set flagdel=1 Where inspectid='{0}' ", inspectionid);

                    cmdhd = fc.ExecSQLStatement(del_mt.ToString());

                    fc.closeconnection();


                }
                catch { };

            }



            return cmdhd;


        }

        [System.Web.Services.WebMethod]
        public static string DeleteRowXR(string inspectionid)
        {
            string cmdhd = string.Empty;

            using (FcSql.Function fc = new FcSql.Function())
            {
                try
                {

                    string del_mt = string.Format("update InspectionItem set flagdel=1 Where inspectid='{0}' ", inspectionid);

                    cmdhd = fc.ExecSQLStatement(del_mt.ToString());

                    fc.closeconnection();


                }
                catch { };

            }



            return cmdhd;


        }


        [System.Web.Services.WebMethod]
        public static string getdata(string parahd, string currentpage)
        {

            DataSet ds = new DataSet();
            int pagesize = 10;
            string cmdhd = string.Empty;
            string inspidid = string.Empty;
            string userapprove = string.Empty;
            string filter = string.Empty;
            using (FcSql.Function fc = new FcSql.Function())
            {
               


                try
                {
                    byte[] datahd = System.Convert.FromBase64String(parahd);
                    string base64Decoded = System.Text.ASCIIEncoding.UTF8.GetString(datahd);



                    string[] strmt = base64Decoded.Split('|');

                    string linegroupid = strmt[0];
                    string linename = strmt[1];
                    string partnumber = strmt[2];
                    string machineid = strmt[3];
                    string machinename = strmt[4];




                    string query = string.Format("select * from (Select  ROW_NUMBER() OVER (order by create_datetime desc,inspectid)  as RowNum, inspectid, equid, itemno, itemname, whoid, whochecklist, freqid, frequency, howcheck,case when criteriatext is NULL or criteriatext = '' then convert(varchar(10),criteriamin)+'-'+convert(varchar(10),criteriamax) else  criteriatext end as criteriatext, unit from InspectionItem  Where equid in (select equid from EquipmentList Where linegroupid='{2}' and partnumber='{3}' and machineid='{4}') and flagdel=0 and inspection_type='1') as temp WHERE RowNum BETWEEN ({0} - 1) * {1} + 1 AND {0} * {1} ", currentpage, pagesize,linegroupid,partnumber,machineid);
                    ds = fc.SQL_DataSet(query.ToString());



                    fc.closeconnection();

                }
                catch { }
            }
            return ds.GetXml();


        }

        [System.Web.Services.WebMethod]
        public static string getdata_xr_chart(string parahd, string currentpage)
        {

            DataSet ds = new DataSet();
            int pagesize = 10;
            string cmdhd = string.Empty;
            string inspidid = string.Empty;
            string userapprove = string.Empty;
            string filter = string.Empty;
            using (FcSql.Function fc = new FcSql.Function())
            {
        

                try
                {

                    byte[] datahd = System.Convert.FromBase64String(parahd);
                    string base64Decoded = System.Text.ASCIIEncoding.UTF8.GetString(datahd);



                    string[] strmt = base64Decoded.Split('|');

                    string linegroupid = strmt[0];
                    string linename = strmt[1];
                    string partnumber = strmt[2];
                    string machineid = strmt[3];
                    string machinename = strmt[4];


                    string query = string.Format("select * from (Select  ROW_NUMBER() OVER (order by create_datetime desc,inspectid)  as RowNum, inspectid, equid, itemno, itemname, whoid, whochecklist, freqid, frequency, howcheck,case when criteriatext is NULL or criteriatext = '' then convert(varchar(10),criteriamin)+'-'+convert(varchar(10),criteriamax) else  criteriatext end as criteriatext, unit from InspectionItem  Where equid in (select equid from EquipmentList Where linegroupid='{2}' and partnumber='{3}' and machineid='{4}') and flagdel=0 and inspection_type='2') as temp WHERE RowNum BETWEEN ({0} - 1) * {1} + 1 AND {0} * {1} ", currentpage, pagesize,linegroupid,partnumber,machineid);
                    ds = fc.SQL_DataSet(query.ToString());



                    fc.closeconnection();

                }
                catch { }
            }
            return ds.GetXml();


        }


        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnback_Click(object sender, EventArgs e)
        {
            Response.Redirect("RegisterEquipment");
        }

        protected void btnaddmachine_Click(object sender, EventArgs e)
        {
            Response.Redirect("Machine_inspection_item_edit");
        }

        protected void btnaddxr_Click(object sender, EventArgs e)
        {
            Response.Redirect("XR_inspection_item_edit");
        }
    }
}