public bool DownloadProjectITPInfo(string sId, string sDescription, string sUser, string sSessionId)
        {
            //			var txtName = (UILabel)View.ViewWithTag (20);
            //			string sUser = txtName.Text;
            //			var hfSessionId = (UILabel)View.ViewWithTag (70);
            //			string sSessionId = hfSessionId.Text;

            //First get all the static info
            if (DownloadStaticTables(sUser, sSessionId))
            {
                clsITPFramework csITP = new clsITPFramework();
                clsTabletDB.ITPHeaderTable clsTabDB = new clsTabletDB.ITPHeaderTable();
                clsTabletDB.ITPDocumentSection clsITPSection = new clsTabletDB.ITPDocumentSection();
                string sRtnMsg = "";

                //****************************************************************************************//
                //                      DOCUMENT HEADER                                                   //
                //****************************************************************************************//
                object[] objListITPs = csITP.DownloadITPInfo(sSessionId, sUser, sId);

                if (objListITPs[0].ToString() == "Success")
                {
                    //Get the header info from the website version. This has to exist before you can download.
                    if (clsTabDB.TableHeaderDeleteAllRecords(sId, ref sRtnMsg))
                    {
                        string sITPDocumentHeaderInfo = objListITPs[1].ToString();
                        string[] sHeaderInfo = sITPDocumentHeaderInfo.Split('~');
                        if (sHeaderInfo[0] == "ITPDocumentHeaderInfo")
                        {
                            string[] delimiters = new string[] { "||" };
                            string[] sHeaderItems = sHeaderInfo[1].Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                            int iHeaderCount = sHeaderItems.Length;
                            if (iHeaderCount > 0)
                            {
                                //First check if the header table exists and if not create it
                                clsTabletDB.ITPHeaderTable ITPDB = new clsTabletDB.ITPHeaderTable();
                                if (ITPDB.CheckHeaderTable())
                                {
                                    this.InvokeOnMainThread(() => {
                                        progBarProjITPHeaderVw.SetProgressBarTitle("Downloading ITP header info for project " + sId);
                                        progBarProjITPHeaderVw.ShowProgressBar(iHeaderCount);
                                    });
                                    for (int i = 0; i < iHeaderCount; i++)
                                    {
                                        string[] delimiters2 = new string[] { "^" };
                                        string[] sHeaderSplitItems = sHeaderItems[i].Split(delimiters2, StringSplitOptions.None);
                                        Array.Resize<string>(ref sHeaderSplitItems, sHeaderSplitItems.Length + 1);
                                        sHeaderSplitItems[sHeaderSplitItems.Length - 1] = sDescription;
                                        ITPDB.TableHeaderAddRecord(sHeaderSplitItems);
                                        this.InvokeOnMainThread(() => { progBarProjITPHeaderVw.UpdateProgressBar(i + 1); });
                                    }
                                    this.InvokeOnMainThread(() => { progBarProjITPHeaderVw.CloseProgressBar(); });
                                }
                            }
                        }
                        //return true;
                    }
                    else
                    {
                        this.InvokeOnMainThread(() => {
                            iUtils.AlertBox alert = new iUtils.AlertBox();
                            alert.SetAlertMessage(sRtnMsg);
                            alert.ShowAlertBox(); });
                        return false;
                    }

                    //****************************************************************************************//
                    //                      QUESTIONNAIRE MASTER                                              //
                    //****************************************************************************************//
                    object[] objITPQuestions = csITP.DownloadProjectITPQuestions(sSessionId, sUser, sId);

                    //Get any questions already raised on the website version into the local DB
                    if (objITPQuestions[0].ToString() == "Success")
                    {
                        if (clsITPSection.ITPProjectSectionDeleteAllQuestions(sId, ref sRtnMsg))
                        {
                            string sITPProjectQuesitonsInfo = objITPQuestions[1].ToString();
                            string[] sProjQuestionInfo = sITPProjectQuesitonsInfo.Split('~');
                            if (sProjQuestionInfo[0] == "ITPProjectQuestionnaireInfo")
                            {
                                string[] delimiters3 = new string[] { "||" };
                                string[] sProjectQuestions = sProjQuestionInfo[1].Split(delimiters3, StringSplitOptions.RemoveEmptyEntries);
                                int iHeaderCount3 = sProjectQuestions.Length;
                                if (iHeaderCount3 > 0)
                                {
                                    //First check if the question master table exists and if not create it
                                    clsTabletDB.ITPDocumentSection ITPQuest = new clsTabletDB.ITPDocumentSection();
                                    if (ITPQuest.CheckQuestionTableMst())
                                    {
                                        this.InvokeOnMainThread(() => {
                                            progBarProjITPQuestionsVw.SetProgressBarTitle("Downloading ITP questions for project " + sId);
                                            progBarProjITPQuestionsVw.ShowProgressBar(iHeaderCount3);
                                        });
                                        for (int i = 0; i < iHeaderCount3; i++)
                                        {
                                            string[] delimiters4 = new string[] { "^" };
                                            string[] sProjectQuestionItems = sProjectQuestions[i].Split(delimiters4, StringSplitOptions.None);
                                            ITPQuest.ITPProjectQuestionAddRecord(sProjectQuestionItems);
                                            this.InvokeOnMainThread(() => { progBarProjITPQuestionsVw.UpdateProgressBar(i + 1); });
                                        }
                                        this.InvokeOnMainThread(() => { progBarProjITPQuestionsVw.CloseProgressBar(); });
                                    }
                                }
                            }
                        }
                        else
                        {
                            this.InvokeOnMainThread(() => {
                                iUtils.AlertBox alert = new iUtils.AlertBox();
                                alert.SetAlertMessage(sRtnMsg);
                                alert.ShowAlertBox();
                            });
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    } //Close the if block for success on project ITP questions

                    //****************************************************************************************//
                    //                      SECTION 10                                                       //
                    //****************************************************************************************//
                    object[] objITPSection10Info = csITP.DownloadProjectITPSection10(sSessionId, sUser, sId);

                    //Get any section 10 info already raised on the website version into the local DB
                    if (objITPSection10Info[0].ToString() == "Success")
                    {
                        if (clsITPSection.ITPProjectSectionDeleteAllSection10Items(sId, ref sRtnMsg))
                        {
                            string sITPProjectSection10Info = objITPSection10Info[1].ToString();
                            string[] sProjSection10Info = sITPProjectSection10Info.Split('~');
                            if (sProjSection10Info[0] == "ITPProjectSection10Info")
                            {
                                string[] delimiters5 = new string[] { "||" };
                                string[] sProjectSection10Items = sProjSection10Info[1].Split(delimiters5, StringSplitOptions.RemoveEmptyEntries);
                                int iHeaderCount5 = sProjectSection10Items.Length;
                                if (iHeaderCount5 > 0)
                                {
                                    //First check if the section 10 table exists and if not create it
                                    clsTabletDB.ITPDocumentSection ITPSection10 = new clsTabletDB.ITPDocumentSection();
                                    if (ITPSection10.CheckSection10Table())
                                    {
                                        this.InvokeOnMainThread(() => {
                                            progBarProjITPSection10Vw.SetProgressBarTitle("Downloading ITP section 10 items for project " + sId);
                                            progBarProjITPSection10Vw.ShowProgressBar(iHeaderCount5);
                                        });
                                        for (int i = 0; i < iHeaderCount5; i++)
                                        {
                                            string[] delimiters6 = new string[] { "^" };
                                            string[] sProjectSection10ItemArray = sProjectSection10Items[i].Split(delimiters6, StringSplitOptions.None);
                                            ITPSection10.ITPSection10AddRecord(sProjectSection10ItemArray);
                                            this.InvokeOnMainThread(() => { progBarProjITPSection10Vw.UpdateProgressBar(i + 1); });
                                        }
                                        this.InvokeOnMainThread(() => { progBarProjITPSection10Vw.CloseProgressBar(); });
                                    }
                                }
                            }
                        }
                        else
                        {
                            this.InvokeOnMainThread(() => {
                                iUtils.AlertBox alert = new iUtils.AlertBox();
                                alert.SetAlertMessage(sRtnMsg);
                                alert.ShowAlertBox();
                            });
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    } //Close the if block for success on project ITP section 10

                    //****************************************************************************************//
                    //                      RFU HEADER INFO                                                   //
                    //****************************************************************************************//
                    object[] objITPRFUInfo = csITP.DownloadProjectITPRFU(sSessionId, sUser, sId);

                    //Get any RFU info already raised on the website version into the local DB
                    if (objITPRFUInfo[0].ToString() == "Success")
                    {
                        if (clsITPSection.ITPProjectSectionDeleteAllRFUItems(sId, ref sRtnMsg))
                        {
                            string sITPProjectRFUInfo = objITPRFUInfo[1].ToString();
                            string[] sProjRFUInfo = sITPProjectRFUInfo.Split('~');
                            if (sProjRFUInfo[0] == "ITPProjectRFUInfo")
                            {
                                string[] delimiters5 = new string[] { "||" };
                                string[] sProjectRFUItems = sProjRFUInfo[1].Split(delimiters5, StringSplitOptions.RemoveEmptyEntries);
                                int iHeaderCount5 = sProjectRFUItems.Length;
                                if (iHeaderCount5 > 0)
                                {
                                    //First check if the RFU table exists and if not create it
                                    clsTabletDB.ITPDocumentSection ITPRFU = new clsTabletDB.ITPDocumentSection();
                                    if (ITPRFU.CheckRFUTable())
                                    {
                                        this.InvokeOnMainThread(() => {
                                            progBarProjITPRFUVw.SetProgressBarTitle("Downloading ITP RFU PwrId items for project " + sId);
                                            progBarProjITPRFUVw.ShowProgressBar(iHeaderCount5);
                                        });
                                        for (int i = 0; i < iHeaderCount5; i++)
                                        {
                                            string[] delimiters6 = new string[] { "^" };
                                            string[] sProjectRFUItemArray = sProjectRFUItems[i].Split(delimiters6, StringSplitOptions.None);
                                            ITPRFU.ITPRFUAddRecord(sProjectRFUItemArray);
                                            this.InvokeOnMainThread(() => { progBarProjITPRFUVw.UpdateProgressBar(i + 1); });
                                        }
                                        this.InvokeOnMainThread(() => { progBarProjITPRFUVw.CloseProgressBar(); });
                                    }
                                }
                            }
                            return true;
                        }
                        else
                        {
                            this.InvokeOnMainThread(() => {
                                iUtils.AlertBox alert = new iUtils.AlertBox();
                                alert.SetAlertMessage(sRtnMsg);
                                alert.ShowAlertBox();
                            });
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    } //Close the if block for success on project ITP section 10
                }
                else
                {
                    return false;
                } //Close the if block for success on project ITP document header
            }
            else
            {
                return false;
            } //Close the if block for success on downlaod of static tables
        }
 public bool SetITPDownloaded(string sId, string sUser, string sSessionId, ref string sRtnMsg)
 {
     clsITPFramework csITP = new clsITPFramework();
     bool bITPDownloaded = csITP.MarkITPDownloaded(sSessionId, sUser, sId, ref sRtnMsg);
     return bITPDownloaded;
 }
 public object[] GetITPsForDownloadLocal()
 {
     string sSessionId = m_sSessionId;
     string sUser = m_sUser;
     clsITPFramework csITP = new clsITPFramework();
     object[] objListITPs = csITP.GetITPsForDownload(sSessionId, sUser);
     return objListITPs;
 }
        void UploadITPQuestion(object sender, EventArgs e, int iMarkUploadType)
        {
            UIButton btnClicked = (UIButton)sender;
            int iClicked = btnClicked.Tag;
            UILabel projId = (UILabel)View.ViewWithTag (iClicked/iUploadBtnTagId*iProjectIdTagId);
            string sId = projId.Text;
            int iOpenBtnId = -1;
            if(iMarkUploadType == 1)
            {
                iOpenBtnId = iClicked/iUploadBtnTagId*iOpenBtnTagId;
            }
            else
            {
                iOpenBtnId = iClicked/iBackupBtnTagId*iOpenBtnTagId;
            }

            var bConnStatus = GetConnectionStatus ();

            if (!bConnStatus)
            {
                iUtils.AlertBox alert = new iUtils.AlertBox();
                alert.CreateAlertDialog();
                alert.SetAlertMessage("The is no network coverage so you cannot upload at this stage");
                alert.ShowAlertBox();
                return;
            }
            else
            {
                //Has the project been made available online again and if so you cannot upload
                clsITPFramework ITPFwrk = new clsITPFramework();
                object[] objUploadable = ITPFwrk.IsITPUploadable(m_sSessionId, m_sUser, sId);
                if (objUploadable[0].ToString() != "Success")
                {
                    iUtils.AlertBox alert4 = new iUtils.AlertBox();
                    alert4.CreateErrorAlertDialog(objUploadable[1].ToString());
                    return;
                }
            }

            if(iMarkUploadType == 1)
            {
                iUtils.AlertBox alert2 = new iUtils.AlertBox();
                alert2.CreateAlertYesNoDialog();
                alert2.SetAlertMessage("This will upload ITP info for Project " + sId + " and lock you out from any further changes. Do you wish to continue?");
                alert2.ShowAlertBox();
                UIAlertView alert3 = alert2.GetAlertDialog();
                alert3.Clicked += (sender2, e2)  => {CheckUploadQuestion(sender2, e2, e2.ButtonIndex, sId, iOpenBtnId, 0);};
            }
            else
            {
                iUtils.AlertBox alert2 = new iUtils.AlertBox();
                alert2.CreateAlertYesNoDialog();
                alert2.SetAlertMessage("This will backup ITP info for Project " + sId + " and allow you to make further changes once complete. Do you wish to continue?");
                alert2.ShowAlertBox();
                UIAlertView alert3 = alert2.GetAlertDialog();
                alert3.Clicked += (sender2, e2)  => {CheckUploadQuestion(sender2, e2, e2.ButtonIndex, sId, iOpenBtnId, 1);};
            }

            return;
        }
        bool UploadITP(string sId, int iOpenBtnId, int iUploadOrBackup)
        {
            string sUser = m_sUser;
            string sSessionId = m_sSessionId;
            clsITPFramework ITPFwrk = new clsITPFramework();
            string sRtnMsg = "";
            bool bUpload = ITPFwrk.UploadITPInfo(sSessionId, sUser, sId, iUploadOrBackup, ref sRtnMsg);
            if (bUpload && sRtnMsg == "")
            {
                //Now also disable the open button for this project
                if(iUploadOrBackup == 0)
                {
                    UIButton btnOpen = (UIButton)View.ViewWithTag (iOpenBtnId);
                    btnOpen.Enabled = false;
                    UILabel hfbtnOpenStatus = (UILabel)View.ViewWithTag (iOpenBtnId/iOpenBtnTagId * iOpenBtnStatusTagId);
                    hfbtnOpenStatus.Text = "0";

                    UIButton btnUpload = (UIButton)View.ViewWithTag (iOpenBtnId/ iOpenBtnTagId * iUploadBtnTagId);
                    btnUpload.Enabled = false;
                    UILabel hfbtnUploadStatus = (UILabel)View.ViewWithTag (iOpenBtnId/iOpenBtnTagId * iUploadBtnStatusTagId);
                    hfbtnUploadStatus.Text = "0";

                    UIButton btnBackup = (UIButton)View.ViewWithTag (iOpenBtnId/ iOpenBtnTagId * iBackupBtnTagId);
                    btnBackup.Enabled = false;

                    //Enable the remove button
                    UIButton btnRemove = (UIButton)View.ViewWithTag (iOpenBtnId/ iOpenBtnTagId * iRemoveBtnTagId);
                    btnRemove.Enabled = true;
                    UILabel hfbtnRemoveStatus = (UILabel)View.ViewWithTag (iOpenBtnId/iOpenBtnTagId * iRemoveBtnStatusTagId);
                    hfbtnRemoveStatus.Text = "1";
                }

                //Change the status text too
                if(iUploadOrBackup == 0)
                {
                    UILabel lblStatus = (UILabel)View.ViewWithTag (iOpenBtnId/ iOpenBtnTagId * iProjStatusTagId);
                    lblStatus.Text = "Uploaded already. You must download again to make changes.";
                }

                iUtils.AlertBox alert = new iUtils.AlertBox();
                alert.CreateAlertDialog();
                if(iUploadOrBackup == 0)
                {
                    alert.SetAlertMessage("ITP info for Project " + sId + " successfully uploaded.");
                }
                else
                {
                    alert.SetAlertMessage("ITP info for Project " + sId + " successfully backed up.");
                }
                alert.ShowAlertBox();
            }
            else
            {
                iUtils.AlertBox alert = new iUtils.AlertBox();
                alert.CreateAlertDialog();
                alert.SetAlertMessage(sRtnMsg);
                alert.ShowAlertBox();
            }

            return bUpload;
        }
 public DataSet GetITPsDownloadedLocal()
 {
     string sRtnMsg = "";
     clsITPFramework csITP = new clsITPFramework();
     DataSet objListITPs = csITP.GetITPsDownloaded(ref sRtnMsg);
     return objListITPs;
 }