Ejemplo n.º 1
0
        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
        }