How to read data from html page / web scraping

Here I have a sample code but modify according requirement


public ActionResult GetDetail(FormCollection form, string command)
        {

            try {
            var userInfo = from user in webscrapinEntity.Login_Info
                           select new
                           {
                               Name = user.UserName,
                               id = user.Id
                           };
            SelectList list = new SelectList(userInfo, "id", "Name");
            ViewBag.Roles = list;

            int userId = Convert.ToInt16(Request.Form["users"]);
            var u = webscrapinEntity.Login_Info.Find(userId);
            var un = u.UserName;
            var up = u.Password;

            //    var st = DateTime.Parse(Request.Form["txtformdate"]);
            //var ed = DateTime.Parse(Request.Form["txttodate"]);

            var s = Request.Form["txtformdate"];
            var l = Request.Form["txttodate"];
            var enddate = Request.Form["txttodate"];
            var startdate = Request.Form["txtformdate"];

            int endyear, endate, endmonth, startyear, startday, startmonth;
            var arry = l.Split('/');
            var arrys = s.Split('/');
            endyear = Convert.ToInt32(arry[2]);
            endmonth = Convert.ToInt32(arry[1]);
            endate = Convert.ToInt32(arry[0]);
            startday = Convert.ToInt32(arrys[0]);
            startmonth = Convert.ToInt32(arrys[1]);
            startyear = Convert.ToInt32(arrys[2]);

            var ll = endmonth + "-" + endate + "-" + endyear;
            var sss = startmonth + "-" + startday + "-" + startyear;
            

            if (command == "Submit")
            {
                try
                {               
                UserDetailes userDetails = new UserDetailes();
                var Details = webscrapinEntity.UserDetails.SqlQuery("select * from UserDetail where cast(ApplicationDate as date) between '" + sss + "' and '" + ll + "' and Userid='"+userId+"'").ToList();
                Details = Details.OrderBy(x => x.ApplicationDate).ToList();
                    //var Details = from user in webscrapinEntity.UserDetails
                //              where user.ApplicationDate >= st && user.ApplicationDate <= ed && user.UserId == userId
                //              select user;

                if (Details.Count() >0)
                {
                    return View(Details);
                }

                else
                {
                    return View("err");
                }
                }

                catch
                {
                return View("err");
                }

            }
            else if (command == "Refresh")
            {
                try
                {
                    string url = "https://ipindiaonline.gov.in/trademarkefiling/user/frmlogin.aspx";
                    parameterDetail(url);
                    string vState = viewState;
                    string eValidation = eventValidation;
                    string Ppage = previouspage;
                    string viewSgenerator = viewStategenerator;
                    if (enddate != null && startdate != null)
                    {
                        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://ipindiaonline.gov.in/trademarkefiling/user/frmlogin.aspx");

                        req.CookieContainer = myCookieContainer;
                        req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
                        req.Method = "POST";
                        req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8";
                        req.Headers.Add("Accept-Language: en-us,en;q=0.5");
                        req.Headers.Add("Accept-Encoding: gzip, deflate");
                        req.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
                        req.KeepAlive = true;
                        req.Headers.Add("Keep-Alive: 300");
                        req.Referer = "https://ipindiaonline.gov.in/trademarkefiling/user/frmLogin.aspx";
                        req.ContentType = "application/x-www-form-urlencoded";

                        ServicePointManager.ServerCertificateValidationCallback = delegate(
                            Object obj, X509Certificate certificate, X509Chain chain,
                            SslPolicyErrors errors)
                        {
                            return (true);
                        };

                        StreamWriter sw = new StreamWriter(req.GetRequestStream());
                        //  sw.Write("__LASTFOCUS=&ctl00_ToolkitScriptManager1_HiddenField=&__EVENTTARGET=ctl00%24ContentPlaceHolder1%24LnkSubmitLogin&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwUKMTUyNzQ5ODc0Mg9kFgJmD2QWAgIED2QWAgIFD2QWBAIBDw8WAh4EVGV4dAUNV2VsY29tZSBHdWVzdGRkAgMPDxYCHgdWaXNpYmxlaGRkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBSZjdGwwMCRDb250ZW50UGxhY2VIb2xkZXIxJEltYWdlQnV0dG9uMbCLEg2bar75EorcOcs7er4VaDz43q%2BfSSoKc8mzTqL2&__VIEWSTATEGENERATOR=7BC7494C&__PREVIOUSPAGE=q1wCBIqXAijLb2usGYu02M2B61qhzm7hMMIdRkYX_fIDdeO688TpdBV2nSSDd8sCdXOBPhdylg72nAU-pRVgNg8a65xNt9i_-n4YZiBqXnQf7wpxpsM8JoXvPky90IjD0&__EVENTVALIDATION=%2FwEdAA6NzfoQSd5y8g8J7l%2B66Y3O24JXNRqAXw9%2BW4PYSYRE9COhLZnz1%2FJEH%2FRNwqLuYMEHKen71Z%2FDkLlqtqx7ZONkUI5xHEJzR8Q6IJGDbvN6LmWOPRMiM6gSAhbviX8V19RYkSuKC1cA6tKPJ3uopsI2cBq95RC%2BiBA1lgeIPK6YfOPKE9Bm3rmckTB22SlTRZCrF%2BzYCp6hViqkPyVxspO5SHT1%2Fqlgk31BV%2FdCuWaYgCkX5%2B7YfmtywpyYQgTTTeqNenhCqhDOaYbvKXw3k0%2FkG4n3bo0omzg89pRzfkR8%2BgXXS71B3GcR2GYyvMO0YyY8gcm1%2BgLitEjMkFf8BnxD&ctl00%24ContentPlaceHolder1%24HFCertSrNo=&ctl00%24ContentPlaceHolder1%24HFThumbPrint=&ctl00%24ContentPlaceHolder1%24HFStrHash=&ctl00%24ContentPlaceHolder1%24DDLLoginType=0&ctl00%24ContentPlaceHolder1%24TBUserName=marker&ctl00%24ContentPlaceHolder1%24TBPassword=Plastic1fire");
                        sw.Write("__LASTFOCUS=&ctl00_ToolkitScriptManager1_HiddenField=&__EVENTTARGET=ctl00%24ContentPlaceHolder1%24LnkSubmitLogin&__EVENTARGUMENT=&__VIEWSTATE=" + vState + "&__VIEWSTATEGENERATOR=" + viewSgenerator + "&__PREVIOUSPAGE=" + Ppage + "&__EVENTVALIDATION=" + eValidation + "&ctl00%24ContentPlaceHolder1%24HFCertSrNo=&ctl00%24ContentPlaceHolder1%24HFThumbPrint=&ctl00%24ContentPlaceHolder1%24HFStrHash=&ctl00%24ContentPlaceHolder1%24DDLLoginType=0&ctl00%24ContentPlaceHolder1%24TBUserName=" + un + "&ctl00%24ContentPlaceHolder1%24TBPassword=" + up);
                        sw.Close();

                        //HttpWebResponse response = (HttpWebResponse)req.GetResponse();
                        StreamReader readera = new StreamReader(req.GetResponse().GetResponseStream());
                        string tmp = readera.ReadToEnd();

                        //Formdate  To Todate Section
                        url = "https://ipindiaonline.gov.in/trademarkefiling/online/frmFormFilingHistory.aspx";



                        parameterDetail(url);

                        req = (HttpWebRequest)HttpWebRequest.Create("https://ipindiaonline.gov.in/trademarkefiling/online/frmFormFilingHistory.aspx");
                        req.CookieContainer = myCookieContainer;
                        req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
                        req.Method = "POST";
                        req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8";
                        req.Headers.Add("Accept-Language: en-us,en;q=0.5");
                        req.Headers.Add("Accept-Encoding: gzip,deflate");
                        req.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
                        //req.Headers.Add("Cookie:ASP.NET_SessionId=zctgauqlarcqtxdhz31rpo3o");
                        //   req.Headers.Add("Cookie:ASP.NET_SessionId=zjzqn3nm1ir4jyqfxj0vjo1n");
                        req.KeepAlive = true;
                        req.Headers.Add("Keep-Alive: 300");
                        req.Referer = "https://ipindiaonline.gov.in/trademarkefiling/online/frmFormFilingHistory.aspx";
                        req.ContentType = "application/x-www-form-urlencoded";
                        string page = "Page$1";
                        ServicePointManager.ServerCertificateValidationCallback = delegate(
                  Object obj, X509Certificate certificate, X509Chain chain,
                  SslPolicyErrors errors)
                        {
                            return (true);
                        };
                        StreamWriter str = new StreamWriter(req.GetRequestStream());
                        str.Write("ctl00_ctl00_ToolkitScriptManager1_HiddenField=%3B%3BAjaxControlToolkit%2C+Version%3D3.5.40412.0%2C+Culture%3Dneutral%2C+PublicKeyToken%3D28f01b0e84b6d53e%3Aen-US%3A1547e793-5b7e-48fe-8490-03a375b13a33%3A5546a2b%3A475a4ef5%3Ad2e10b12%3Aeffe2a26%3Af3d989c9%3A37e2e5c9%3A5a682656%3Abfe70f69&__EVENTTARGET=ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24lnkSubmit&__EVENTARGUMENT=&__VIEWSTATE=" + viewState + "&__VIEWSTATEGENERATOR=" + viewStategenerator + "&__PREVIOUSPAGE=" + previouspage + "&__EVENTVALIDATION=" + eventValidation + "&ctl00%24ctl00%24ContentPlaceHolder1%24MenuAccordion_AccordionExtender_ClientState=4&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24txtFromDate=" + s + "&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender1_ClientState=&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender3_ClientState=&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24txtToDate=" + l + "&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender2_ClientState=&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender4_ClientState=");                      
                        str.Close();
                     



                        StreamReader streamReader = new StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.UTF8);

                        string sourceString = streamReader.ReadToEnd();


                        GetGridData(sourceString);
                        int pages = Paging;
                        for (int j = 2; j <= pages; j++)
                        {

                            AfterPaginationParameterDetail(sourceString);
                            req = (HttpWebRequest)HttpWebRequest.Create("https://ipindiaonline.gov.in/trademarkefiling/online/frmFormFilingHistory.aspx");
                            req.CookieContainer = myCookieContainer;
                            req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0";
                            req.Method = "POST";
                            req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*;q=0.8";
                            req.Headers.Add("Accept-Language: en-us,en;q=0.5");
                            req.Headers.Add("Accept-Encoding: gzip,deflate");
                            req.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");                         
                            req.KeepAlive = true;
                            req.Headers.Add("Keep-Alive: 300");
                            req.Referer = "https://ipindiaonline.gov.in/trademarkefiling/online/frmFormFilingHistory.aspx";
                            req.ContentType = "application/x-www-form-urlencoded";
                            //string page = "Page$1";
                            ServicePointManager.ServerCertificateValidationCallback = delegate(
                      Object obj, X509Certificate certificate, X509Chain chain,
                      SslPolicyErrors errors)
                            {
                                return (true);
                            };
                            StreamWriter streamWriter = new StreamWriter(req.GetRequestStream());
                            streamWriter.Write("ctl00_ctl00_ToolkitScriptManager1_HiddenField=%3B%3BAjaxControlToolkit%2C+Version%3D3.5.40412.0%2C+Culture%3Dneutral%2C+PublicKeyToken%3D28f01b0e84b6d53e%3Aen-US%3A1547e793-5b7e-48fe-8490-03a375b13a33%3A5546a2b%3A475a4ef5%3Ad2e10b12%3Aeffe2a26%3Af3d989c9%3A37e2e5c9%3A5a682656%3Abfe70f69&__EVENTTARGET=ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24gridAppList&__EVENTARGUMENT=Page%24" + j + "&__VIEWSTATE=" + viewState + "&__VIEWSTATEGENERATOR=" + viewStategenerator + "&__PREVIOUSPAGE=" + previouspage + "&__EVENTVALIDATION=" + eventValidation + "&ctl00%24ctl00%24ContentPlaceHolder1%24MenuAccordion_AccordionExtender_ClientState=4&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24txtFromDate=" + s + "&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender1_ClientState=&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender3_ClientState=&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24txtToDate=" + l + "&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender2_ClientState=&ctl00%24ctl00%24ContentPlaceHolder1%24ContentPlaceHolder2%24ValidatorCalloutExtender4_ClientState=");
                            streamWriter.Close();
                            StreamReader strmReader = new StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.UTF8);

                            sourceString = strmReader.ReadToEnd();
                            GetGridData(sourceString);

                        }




                        //Each Record
                        WebscapingipindiaEntities2 db = new WebscapingipindiaEntities2();
                        for (int i = 0; i < alluser.Count; i++)
                        {
                            bool IsInsert = true;
                            req = (HttpWebRequest)HttpWebRequest.Create("https://ipindiaonline.gov.in/trademarkefiling/online/frmPreview.aspx?ApplNo=" + alluser[i].formnumber + "&FormType=" + alluser[i].formtype + "");
                            //req = (HttpWebRequest)HttpWebRequest.Create("https://ipindiaonline.gov.in/trademarkefiling/online/frmPreview.aspx?ApplNo=650296&FormType=TM-1");
                            req.CookieContainer = myCookieContainer;

                            // var time = req.Timeout;
                            req.Timeout = 200000;
                            StreamReader sReader = new StreamReader(req.GetResponse().GetResponseStream());
                            string tmpe = sReader.ReadToEnd();

                            UserDetailes userDetails = new UserDetailes();
                            IHTMLElementCollection sub_elementCollection;
                            HTMLSpanElement sp1;
                            HTMLTable htmTable;
                            HTMLTable sub_hTable;
                            HTMLTable HT2;
                            HTMLTable sp;
                            HTMLTable HT3;
                            HTMLTableSection HTS1;
                            HTMLTableRow sub_htmlTableRow;
                            HTMLTableRow HTR2;
                            HTMLTableCell hTableCell;
                            HTMLAnchorElement HAE1;
                            IHTMLElementCollection es11;
                            IHTMLElementCollection sub_trElementCollection;
                            IHTMLElementCollection es22;
                            IHTMLElementCollection es;
                            IHTMLElementCollection sub_tdElementCollection;
                            IHTMLElementCollection es32;
                            HTMLDivElement reporthead1;
                            int getGetLastRow = 17;
                            IHTMLDocument2 IhtmlDocument = (IHTMLDocument2)new mshtml.HTMLDocument();

                            IhtmlDocument.write(tmpe);
                            IHTMLElement2 bElement = IhtmlDocument.body as IHTMLElement2;
                            IHTMLElementCollection SCollection = bElement.getElementsByTagName("TABLE");
                            foreach (IHTMLElement hmElement in SCollection)
                            {
                                sp = hmElement as HTMLTable;
                                int tablecount = 1;
                                es = sp.getElementsByTagName("table");
                                foreach (IHTMLElement et in es)
                                {

                                    htmlTable = et as HTMLTable;
                                    if (tablecount == 2)
                                    {
                                        if (htmlTable != null)
                                        {

                                            trElementCollection = htmlTable.getElementsByTagName("tr");

                                            int getRow = 1;
                                            Detail detail = new Detail();

                                            foreach (IHTMLElement HE2 in trElementCollection)
                                            {
                                                HTableRow = HE2 as HTMLTableRow;

                                                if (HTableRow != null)
                                                {
                                                    int getCell = 1;
                                                    tdElementCollection = HTableRow.getElementsByTagName("td");
                                                    foreach (IHTMLElement HE3 in tdElementCollection)
                                                    {
                                                        HTD = HE3 as HTMLTableCell;
                                                        if (getRow == 1)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Application_no = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Application_date = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 2)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Receipt_Number = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Receipt_Date = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 3)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Class = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Conditions = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 4)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Service_Address = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.TM_Category = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 5)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Branch_Name = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Country = HTD.innerText;

                                                            }
                                                        }


                                                        if (getRow == 6)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.State = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.District = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 7)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Translation = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Transliteration = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 8)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Proposed_to_be_used = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Language_of_Mark = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 9)
                                                        {
                                                            if (getCell == 2)
                                                            {
                                                                detail.Associated_TM_Flag = HTD.innerText;

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Used_Since_Date = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 10)
                                                        {
                                                            if (getCell == 2)
                                                            {


                                                                tdElementCollection = HTableRow.getElementsByTagName("img");

                                                                foreach (IHTMLElement iHtml in tdElementCollection)
                                                                {
                                                                    var HIM = iHtml as HTMLImg;
                                                                    if (HIM.src != null)
                                                                        detail.Trade_Mark_Image = HIM.src;
                                                                }

                                                            }
                                                            if (getCell == 4)
                                                            {
                                                                detail.Trade_Mark_Type = HTD.innerText;

                                                            }
                                                        }

                                                        if (getRow == 11)
                                                        {
                                                            if (getCell == 2)
                                                            {



                                                                detail.Trade_Mark_Text = HTD.innerText;

                                                                userDetails.detail = detail;
                                                            }

                                                        }
                                                        if (getRow == 12)
                                                        {
                                                            ProprietorDetails pDetail = new ProprietorDetails();
                                                            AgentAttorneyDetails aDetail = new AgentAttorneyDetails();
                                                            sub_elementCollection = HTD.getElementsByTagName("table");
                                                            int sGetTable = 1;
                                                            foreach (IHTMLElement ht in sub_elementCollection)
                                                            {
                                                                sub_hTable = ht as HTMLTable;
                                                                if (sub_hTable != null)
                                                                {

                                                                    sub_trElementCollection = sub_hTable.getElementsByTagName("tr");
                                                                    int sGetRow = 1;
                                                                    foreach (IHTMLElement HE in sub_trElementCollection)
                                                                    {
                                                                        sub_htmlTableRow = HE as HTMLTableRow;


                                                                        if (sub_htmlTableRow != null)
                                                                        {
                                                                            int sGetCell = 1;
                                                                            sub_tdElementCollection = sub_htmlTableRow.getElementsByTagName("td");
                                                                            foreach (IHTMLElement HE6 in sub_tdElementCollection)
                                                                            {
                                                                                hTableCell = HE6 as HTMLTableCell;
                                                                                if (sGetTable == 1)
                                                                                {
                                                                                    if (sGetRow == 2)
                                                                                    {
                                                                                        if (sGetCell == 1)
                                                                                        {
                                                                                            pDetail.SrNo = hTableCell.innerText;

                                                                                        }
                                                                                        if (sGetCell == 2)
                                                                                        {
                                                                                            pDetail.ProprietorType = hTableCell.innerText;
                                                                                        }
                                                                                        if (sGetCell == 3)
                                                                                        {
                                                                                            pDetail.ProprietorCode = hTableCell.innerText;
                                                                                        }
                                                                                        if (sGetCell == 4)
                                                                                        {
                                                                                            pDetail.ProprietorAddress = hTableCell.innerText;
                                                                                        }
                                                                                        if (sGetCell == 5)
                                                                                        {
                                                                                            pDetail.ProprietorTradeDesciption = hTableCell.innerText;
                                                                                            userDetails.ProprietorDetails = pDetail;
                                                                                        }
                                                                                    }
                                                                                    if (sGetRow == 3)
                                                                                    {
                                                                                        if (sGetCell == 1)
                                                                                        {
                                                                                            pDetail.Name = hTableCell.innerText;
                                                                                            getGetLastRow++;
                                                                                        }
                                                                                    }
                                                                                    if (sGetRow == 4)
                                                                                    {
                                                                                        if (sGetCell == 1)
                                                                                        {
                                                                                            pDetail.Name += "," + hTableCell.innerText;
                                                                                            getGetLastRow++;
                                                                                        }
                                                                                    }
                                                                                    if (sGetRow == 5)
                                                                                    {
                                                                                        if (sGetCell == 1)
                                                                                        {
                                                                                            pDetail.Name += "," + hTableCell.innerText;
                                                                                            getGetLastRow++;
                                                                                        }
                                                                                    }
                                                                                    if (sGetRow == 6)
                                                                                    {
                                                                                        if (sGetCell == 1)
                                                                                        {
                                                                                            pDetail.Name += "," + hTableCell.innerText;
                                                                                            getGetLastRow++;
                                                                                            userDetails.ProprietorDetails = pDetail;
                                                                                        }
                                                                                    }
                                                                                }
                                                                                if (sGetTable == 2)
                                                                                {
                                                                                    if (sGetRow == 2)
                                                                                    {
                                                                                        if (sGetCell == 1)
                                                                                        {
                                                                                            aDetail.AgentAttorneyCode = hTableCell.innerText;
                                                                                        }
                                                                                        if (sGetCell == 2)
                                                                                        {
                                                                                            aDetail.AgentAttorneyName = hTableCell.innerText;
                                                                                        }
                                                                                        if (sGetCell == 3)
                                                                                        {
                                                                                            aDetail.AgentAttorneyAddress = hTableCell.innerText;
                                                                                            userDetails.AgentAttorneyDetails = aDetail;
                                                                                        }
                                                                                    }
                                                                                }
                                                                                sGetCell++;
                                                                            }
                                                                        }
                                                                        sGetRow++;
                                                                    }
                                                                }
                                                                sGetTable++;
                                                            }
                                                        }
                                                        if (getRow == getGetLastRow)
                                                        {
                                                            ClassDetails cDetails = new ClassDetails();
                                                            sub_elementCollection = HTD.getElementsByTagName("table");
                                                            foreach (IHTMLElement hte in sub_elementCollection)
                                                            {
                                                                HT3 = hte as HTMLTable;
                                                                if (HT3 != null)
                                                                {
                                                                    sub_trElementCollection = HT3.getElementsByTagName("tr");
                                                                    int lGetRow = 1;
                                                                    foreach (IHTMLElement HE9 in sub_trElementCollection)
                                                                    {
                                                                        HTR2 = HE9 as HTMLTableRow;
                                                                        if (HTR2 != null)
                                                                        {
                                                                            int lGetCell = 1;
                                                                            sub_tdElementCollection = HTR2.getElementsByTagName("td");
                                                                            foreach (IHTMLElement HE7 in sub_tdElementCollection)
                                                                            {
                                                                                hTableCell = HE7 as HTMLTableCell;
                                                                                if (lGetRow == 2)
                                                                                {
                                                                                    if (lGetCell == 1)
                                                                                    {
                                                                                        cDetails.SerialNumber = hTableCell.innerText;

                                                                                    }
                                                                                    if (lGetCell == 2)
                                                                                    {
                                                                                        cDetails.Class = hTableCell.innerText;
                                                                                    }
                                                                                    if (lGetCell == 3)
                                                                                    {
                                                                                        cDetails.GoodsDescription = hTableCell.innerText;
                                                                                        userDetails.ClassDetails = cDetails;
                                                                                    }
                                                                                }
                                                                                lGetCell++;
                                                                            }
                                                                        }
                                                                        lGetRow++;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        getCell++;
                                                    }
                                                }
                                                getRow++;
                                            }
                                        }                                       

                                        if (IsInsert)
                                        {
                                          

                                            if (userDetails.detail != null && userDetails.ProprietorDetails != null && userDetails.AgentAttorneyDetails != null && userDetails.ClassDetails != null)
                                            {

                                                int y, m, d;
                                                var date = userDetails.detail.Application_date.Split('/');
                                                y = Convert.ToInt32(date[2]);
                                                m = Convert.ToInt32(date[1]);
                                                d = Convert.ToInt32(date[0]);


                                                UserDetail ud = new UserDetail();
                                                ud.ApplicationNo = userDetails.detail.Application_no;
                                                ud.ApplicationDate = new DateTime(y, m, d);
                                                ud.ReceiptNumber = userDetails.detail.Receipt_Number;
                                                ud.ReceiptDate = userDetails.detail.Receipt_Date;
                                                ud.Class = userDetails.detail.Class;
                                                ud.Conditions = userDetails.detail.Conditions;
                                                ud.ServiceAddress = userDetails.detail.Service_Address;
                                                ud.TMCategory = userDetails.detail.TM_Category;
                                                ud.BranchName = userDetails.detail.Branch_Name;
                                                ud.Country = userDetails.detail.Country;
                                                ud.State = userDetails.detail.State;
                                                ud.District = userDetails.detail.District;
                                                ud.Translation = userDetails.detail.Translation;
                                                ud.Transliteration = userDetails.detail.Transliteration;
                                                ud.Proposedtobeused = userDetails.detail.Proposed_to_be_used;
                                                ud.LanguageofMark = userDetails.detail.Language_of_Mark;
                                                ud.AssociatedTMFlag = userDetails.detail.Associated_TM_Flag;
                                                ud.UsedSinceDate = userDetails.detail.Used_Since_Date;
                                                ud.TradeMarkImage = userDetails.detail.Trade_Mark_Image;
                                                ud.TradeMarkType = userDetails.detail.Trade_Mark_Type;
                                                ud.TradeMarkText = userDetails.detail.Trade_Mark_Text;
                                                ud.SrNo = userDetails.ProprietorDetails.SrNo;
                                                ud.ProprietorType = userDetails.ProprietorDetails.ProprietorType;
                                                ud.ProprietorCodeName = userDetails.ProprietorDetails.ProprietorCode;
                                                ud.ProprietorAddress = userDetails.ProprietorDetails.ProprietorAddress;
                                                ud.ProprietorTradeDesciption = userDetails.ProprietorDetails.ProprietorTradeDesciption;
                                                ud.AgentAttorneyCode = userDetails.AgentAttorneyDetails.AgentAttorneyCode;
                                                ud.AgentAttorneyName = userDetails.AgentAttorneyDetails.AgentAttorneyName;
                                                ud.AgentAttorneyAddress = userDetails.AgentAttorneyDetails.AgentAttorneyAddress;
                                                ud.SerialNumber = userDetails.ClassDetails.SerialNumber;
                                                ud.Class = userDetails.ClassDetails.Class;
                                                ud.GoodsDescription = userDetails.ClassDetails.GoodsDescription;
                                                ud.Name = userDetails.ProprietorDetails.Name;
                                                ud.Status = alluser[i].status;
                                                ud.UserId = userId;
                                                var existsData = from x in webscrapinEntity.UserDetails
                                                                 where (x.ApplicationNo == userDetails.detail.Application_no)
                                                                 select x;
                                                if (existsData.Count() > 0)
                                                {
                                                    ud.Application_id = existsData.FirstOrDefault().Application_id;
                                                    ud.ReferenceFrom = existsData.FirstOrDefault().ReferenceFrom;
                                                    ud.PaymentForFillingIncludingGovtFees = existsData.FirstOrDefault().PaymentForFillingIncludingGovtFees;
                                                    ud.PaymentReport = existsData.FirstOrDefault().PaymentReport;
                                                    ud.ReplyStatus = existsData.FirstOrDefault().ReplyStatus;
                                                    ud.HearingStatus = existsData.FirstOrDefault().HearingStatus;
                                                    ud.NoticeCopySentToClient = existsData.FirstOrDefault().NoticeCopySentToClient;
                                                    ud.PaymentForHearning = existsData.FirstOrDefault().PaymentForHearning;
                                                    ud.FinalStatus = existsData.FirstOrDefault().FinalStatus;
                                                    ud.Notes = existsData.FirstOrDefault().Notes;                                                  

                                                    if (ud.Status != existsData.FirstOrDefault().Status)
                                                    {
                                                        ud.StatusChange = true;
                                                    }

                                                    var x = existsData.FirstOrDefault().StatusChange;
                                                    if (x == true)
                                                    {
                                                        ud.StatusChange = true;
                                                    }
                                                    db.Entry(ud).State = EntityState.Modified;
                                                    //  db.As.Attach(ud);
                                                    db.SaveChanges();
                                                    IsInsert = false;
                                                }
                                                else
                                                {

                                                    db.UserDetails.Add(ud);
                                                    db.SaveChanges();
                                                    IsInsert = false;
                                                }                                               
                                            }

                                        }
                                    }

                                    tablecount++;

                                }
                            }
                            var Details = db.UserDetails.SqlQuery("select * from UserDetail where cast(ApplicationDate as date) between '" + sss + "' and '" + ll + "' and Userid='" + userId + "'").ToList();
                            Details = Details.OrderBy(x => x.ApplicationDate).ToList();
                            if (Details != null)
                            {
                                return View(Details);
                            }
                        }

                    }
                }
                catch
                {
                    return View("err");
                }
            }
            }
            catch
            {
                return View("err");
            }
           
            return View("err");         
        }
       public void GetStatus(int ID)
        {

            var DataS = webscrapinEntity.UserDetails.Find(ID);
            if(DataS.StatusChange==true)
            {
                DataS.StatusChange = false;
                webscrapinEntity.SaveChanges();
            }
           

        }

Comments

Popular posts from this blog

Form submit resulting in “InvalidDataException: Form value count limit 1024 exceeded.” In ASP.NET Core

Calculate Dynamic Current Calendar / Financial Year In C#

Repository Design Pattern in C#