Exemplo n.º 1
0
 public DBManager(LoadingDatabase loadingScreen)
 {
     loadingScreen.Show();
     loadingScreen.LoadingTextLabel.Update();
     dbo = new SAMPLEEntities();
     loadingScreen.LoadingTextLabel.Text = "Applying offline changes to database...";
     loadingScreen.LoadingTextLabel.Update();
     CheckChangeLog(loadingScreen);
     loadingScreen.LoadingTextLabel.Text = "Updating filesystem...";
     loadingScreen.LoadingTextLabel.Update();
     UpdateDataFile(loadingScreen);
 }
Exemplo n.º 2
0
        public static bool LoadDatabase()
        {
            if (db == null || !isOnline)
            {
                LoadingDatabase loadingScreen = new LoadingDatabase();
                try
                {
                    //throw new Exception();
                    db = new DBManager(loadingScreen);
                    loadingScreen.Close();
                    isOnline = true;
                }
                catch (Exception e)
                {
                    loadingScreen.Close();
                    db       = new FileManager();
                    isOnline = false;
                    MessageBox.Show("Could not connect to database\n\n" + e.Message + "\n\n" + "Offline mode set", "Error");
                }
            }

            return(isOnline);
        }
Exemplo n.º 3
0
        public void CheckChangeLog(LoadingDatabase loadingScreen = null)
        {
            List<string> failedChanges = new List<string>();

            //string line;
            string[] lineArray;

            CLIENT client;
            REGION region;
            COUNTRY country;
            BUSINESSTYPE busType;
            GROUP grp;
            CONTACT contact;
            CATEGORY category;
            BUSINESSOBJECTIVE objective;
            IMPERATIVE imperative;
            BOM bom;
            CUPEQUESTION cupeQuestion;
            CupeQuestionStringData cupeQuestionStringData;
            CUPE cupe;
            CUPERESPONSE cupeResponse;
            DOMAIN domain;
            CAPABILITY capability;
            ITCAPQUESTION itcapQuestion;
            ITCAP itcap;
            COMMENT comment;
            ITCAPOBJMAP itcapObjMap;
            CAPABILITYGAPINFO capGapInfo;

            if (!Directory.Exists("Resources"))
            {
                Directory.CreateDirectory("Resources");
            }

            if (!Directory.Exists(@"Resources\Clients"))
            {
                Directory.CreateDirectory(@"Resources\Clients");
            }

            if (!File.Exists(@"Resources\Changes.log"))
            {
                FileStream file = File.Create(@"Resources\Changes.log");
                file.Close();
            }

            using (System.IO.StreamReader file = new System.IO.StreamReader(@"Resources\Changes.log"))
            {
                if (loadingScreen != null)
                {
                    loadingScreen.LoadingTextLabel.Text = "Applying offline changes to database... Reading change log";
                    loadingScreen.LoadingTextLabel.Update();
                }
                string allLines = file.ReadToEnd();
                string[] allLinesArray = allLines.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                //while ((line = file.ReadLine()) != null)
                float totalLines = allLinesArray.Length;
                int linesComplete = 0;
                foreach(string line in allLinesArray)
                {
                    lineArray = line.Split(' ');
                    if (lineArray[0] == "ADD")
                    {
                        switch(lineArray[1])
                        {
                            case "CLIENT":
                                client = new CLIENT();
                                client.NAME = lineArray[2].Replace('~', ' ');

                                string regionName = lineArray[3].Replace('~', ' ');
                                try
                                {
                                    region = (from ent in dbo.REGION
                                              where ent.NAME.TrimEnd() == regionName
                                              select ent).Single();
                                }
                                catch
                                {
                                    region = new REGION();
                                    region.NAME = regionName;
                                    dbo.AddToREGION(region);
                                }

                                string countryName = lineArray[4].Replace('~', ' ');
                                try
                                {
                                    country = (from ent in region.COUNTRY
                                              where ent.NAME.TrimEnd() == countryName
                                              select ent).Single();
                                }
                                catch
                                {
                                    country = new COUNTRY();
                                    country.NAME = countryName;
                                    country.REGION = region;
                                    dbo.AddToCOUNTRY(country);
                                }

                                client.COUNTRY = country;

                                client.STARTDATE = DateTime.Parse(lineArray[5].Replace('~', ' '));

                                string busTypeName = lineArray[6].Replace('~', ' ');
                                try
                                {
                                    busType = (from ent in dbo.BUSINESSTYPE
                                              where ent.NAME.TrimEnd() == busTypeName
                                              select ent).Single();
                                }
                                catch
                                {
                                    busType = new BUSINESSTYPE();
                                    busType.NAME = busTypeName;
                                    dbo.AddToBUSINESSTYPE(busType);
                                }
                                client.BUSINESSTYPE = busType;

                                client.BOMCOMPLETE = client.CUPECOMPLETE = client.ITCAPCOMPLETE = "N";

                                if (!AddClient(client))
                                {
                                    MessageBox.Show("Add Client Instruction Failed: Client already exists\n\n" + line, "Error");
                                }
                                break;

                            case "REGION":
                                if (!AddRegion(lineArray[2].Replace('~', ' ')))
                                {
                                    MessageBox.Show("Add Region Instruction Failed: Region already exists\n\n" + line, "Error");
                                }
                                break;

                            case "BUSINESSTYPE":
                                if (!AddBusinessType(lineArray[2].Replace('~', ' ')))
                                {
                                    MessageBox.Show("Add BusinessType Instruction Failed: BusinessType already exists\n\n" + line, "Error");
                                }
                                break;

                            case "CONTACT":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetGroup(lineArray[3].Replace('~', ' '), client, out grp))
                                    {
                                        if (!AddContact(Convert.ToInt32(lineArray[4]), grp))
                                        {
                                            MessageBox.Show("Add Contact Instruction Failed: Contact ID already exists\n\n" + line, "Error");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Add Contact Instruction Failed: Group does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add Contact Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;

                            case "CATEGORY":
                                category = new CATEGORY();
                                category.NAME = lineArray[2].Replace('~', ' ');
                                if (!AddCategory(category))
                                {
                                    MessageBox.Show("Add Category Instruction Failed: Category already exists\n\n" + line, "Error");
                                }
                                break;

                            case "BUSINESSOBJECTIVE":
                                if (GetCategory(lineArray[3].Replace('~', ' '), out category))
                                {
                                    objective = new BUSINESSOBJECTIVE();
                                    objective.NAME = lineArray[2].Replace('~', ' ');
                                    objective.CATEGORY = category;
                                    if (!AddObjective(objective))
                                    {
                                        MessageBox.Show("Add BusinessObjective Instruction Failed: BusinessObjective already exists\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add BusinessObjective Instruction Failed: Category does not exist\n\n" + line, "Error");
                                }
                                break;

                            case "IMPERATIVE":
                                if (GetObjective(lineArray[3].Replace('~', ' '), out objective))
                                {
                                    imperative = new IMPERATIVE();
                                    imperative.NAME = lineArray[2].Replace('~', ' ');
                                    imperative.BUSINESSOBJECTIVE = objective;
                                    if (!AddImperative(imperative))
                                    {
                                        MessageBox.Show("Add Imperative Instruction Failed: Imperative already exists\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add Imperative Instruction Failed: BusinessObjective does not exist\n\n" + line, "Error");
                                }
                                break;

                            case "BOM":
                                if (lineArray[2] == "CLIENT")
                                {
                                    if (GetClient(lineArray[3].Replace('~', ' '), out client))
                                    {
                                        if (GetImperative(lineArray[4].Replace('~', ' '), out imperative))
                                        {
                                            bom = new BOM();
                                            bom.IMPERATIVE = imperative;
                                            if (!AddBOM(bom, client))
                                            {
                                                MessageBox.Show("Add BOM Instruction Failed: BOM already exists\n\n" + line, "Error");
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Add BOM Instruction Failed: Imperative does not exist\n\n" + line, "Error");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Add BOM Instruction Failed: Client does not exist\n\n" + line, "Error");
                                    }
                                }

                                else
                                {
                                    MessageBox.Show("Invalid instruction detected:\n\n" + line, "Error");
                                }
                                break;

                            case "CUPERESPONSE":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetGroup(lineArray[3].Replace('~', ' '), client, out grp))
                                    {
                                        if (GetContact(Convert.ToInt32(lineArray[4]), out contact))
                                        {
                                            if (GetCUPE(lineArray[5].Replace('~', ' '), client, out cupe))
                                            {
                                                cupeResponse = new CUPERESPONSE();
                                                cupeResponse.CONTACT = contact;
                                                cupeResponse.CUPE = cupe;
                                                cupeResponse.CURRENT = lineArray[6];
                                                cupeResponse.FUTURE = lineArray[7];
                                                dbo.AddToCUPERESPONSE(cupeResponse);
                                            }
                                            else
                                            {
                                                MessageBox.Show("Add CUPEResponse Instruction Failed: CUPE does not exist\n\n" + line, "Error");
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Add CUPEResponse Instruction Failed: Contact ID does not exist\n\n" + line, "Error");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Add CUPEResponse Instruction Failed: Group does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add CUPEResponse Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;

                            case "CUPEQUESTION":
                                cupeQuestionStringData = new CupeQuestionStringData();
                                cupeQuestionStringData.QuestionText = lineArray[2].Replace('~', ' ');
                                cupeQuestionStringData.ChoiceA = lineArray[3].Replace('~', ' ');
                                cupeQuestionStringData.ChoiceB = lineArray[4].Replace('~', ' ');
                                cupeQuestionStringData.ChoiceC = lineArray[5].Replace('~', ' ');
                                cupeQuestionStringData.ChoiceD = lineArray[6].Replace('~', ' ');
                                AddCupeQuestion(cupeQuestionStringData);
                                break;

                            case "CUPE":
                                if (lineArray[2] == "CLIENT")
                                {
                                    if (GetClient(lineArray[3].Replace('~', ' '), out client))
                                    {
                                        if (GetCUPEQuestion(lineArray[4].Replace('~', ' '), out cupeQuestion))
                                        {
                                            if (!AddCUPE(cupeQuestion.NAME.TrimEnd(), client, Convert.ToInt32(lineArray[5])))
                                            {
                                                MessageBox.Show("Add CUPEResponse Instruction Failed: CUPE already exists\n\n" + line, "Error");
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Add CUPEResponse Instruction Failed: CUPEQuestion does not exist\n\n" + line, "Error");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Add CUPE Instruction Failed: Client does not exist\n\n" + line, "Error");
                                    }
                                }

                                else
                                {
                                    MessageBox.Show("Invalid instruction detected:\n\n" + line, "Error");
                                }
                                break;

                            case "DOMAIN":
                                domain = new DOMAIN();
                                domain.NAME = lineArray[2].Replace('~', ' ');
                                domain.DEFAULT = "N";
                                if (!AddDomain(domain))
                                {
                                    MessageBox.Show("Add Domain Instruction Failed: Domain already exists\n\n" + line, "Error");
                                }
                                break;

                            case "CAPABILITY":
                                if (GetDomain(lineArray[3].Replace('~', ' '), out domain))
                                {
                                    capability = new CAPABILITY();
                                    capability.NAME = lineArray[2].Replace('~', ' ');
                                    capability.DEFAULT = "N";
                                    capability.DOMAIN = domain;
                                    if (!AddCapability(capability))
                                    {
                                        MessageBox.Show("Add Capability Instruction Failed: Capability already exists\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add Capability Instruction Failed: Domain does not exist\n\n" + line, "Error");
                                }
                                break;

                            case "ITCAPQUESTION":
                                if (GetCapability(lineArray[3].Replace('~', ' '), out capability))
                                {
                                    itcapQuestion = new ITCAPQUESTION();
                                    itcapQuestion.NAME = lineArray[2].Replace('~', ' ');
                                    itcapQuestion.DEFAULT = "N";
                                    itcapQuestion.CAPABILITY = capability;
                                    if (!AddITCAPQuestion(itcapQuestion))
                                    {
                                        MessageBox.Show("Add ITCAPQuestion Instruction Failed: ITCAPQuestion already exists\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add ITCAPQuestion Instruction Failed: Capability does not exist\n\n" + line, "Error");
                                }
                                break;

                            case "ITCAP":
                                if (lineArray[2] == "CLIENT")
                                {
                                    if (GetClient(lineArray[3].Replace('~', ' '), out client))
                                    {
                                        if (GetITCAPQuestion(lineArray[4].Replace('~', ' '), out itcapQuestion))
                                        {
                                            itcap = new ITCAP();
                                            itcap.ITCAPQUESTION = itcapQuestion;
                                            if (!AddITCAP(itcap, client))
                                            {
                                                MessageBox.Show("Add ITCAP Instruction Failed: ITCAP already exists\n\n" + line, "Error");
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Add ITCAP Instruction Failed: ITCAPQuestion does not exist\n\n" + line, "Error");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Add ITCAP Instruction Failed: Client does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Invalid instruction detected:\n\n" + line, "Error");
                                }
                                break;

                            case "ITCAPOBJMAP":
                                if (GetClient(lineArray[3].Replace('~', ' '), out client))
                                {
                                    int temp;
                                    if (!GetITCAPOBJMAPScore(client, lineArray[4].Replace('~', ' '), lineArray[5].Replace('~', ' '), out temp))
                                    {
                                        if (!GetCapability(lineArray[4].Replace('~', ' '), out capability))
                                        {
                                            MessageBox.Show("Add ITCAPOBJMAP Instruction Failed: Capability does not exist\n\n" + line, "Error");
                                            break;
                                        }

                                        if (!GetObjective(lineArray[5].Replace('~', ' '), out objective))
                                        {
                                            MessageBox.Show("Add ITCAPOBJMAP Instruction Failed: BusinessObjective does not exist\n\n" + line, "Error");
                                            break;
                                        }

                                        itcapObjMap = new ITCAPOBJMAP();
                                        itcapObjMap.CLIENT = client;
                                        itcapObjMap.CAPABILITY = capability;
                                        itcapObjMap.BUSINESSOBJECTIVE = objective;
                                        itcapObjMap.SCORE = 0;

                                    }
                                    else
                                    {
                                        MessageBox.Show("Add CapabilityObjectiveMap Instruction Failed: CapabilityObjectiveMap already exists\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add CapabilityObjectiveMapping Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "CAPABILITYGAPINFO":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetCapability(lineArray[3].Replace('~', ' '), out capability))
                                    {
                                        capGapInfo = new CAPABILITYGAPINFO();
                                        capGapInfo.CLIENT = client;
                                        capGapInfo.CAPABILITY = capability;
                                        capGapInfo.GAP = 0;
                                        capGapInfo.PRIORITIZEDGAP = 0;
                                        capGapInfo.GAPTYPE = "None";
                                        capGapInfo.PRIORITIZEDGAPTYPE = "None";
                                        dbo.AddToCAPABILITYGAPINFO(capGapInfo);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Add CapabilityGapInfo Instruction Failed: Capability does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Add CapabilityGapInfo Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            default:
                                MessageBox.Show("Invalid instruction detected:\n\n" + line, "Error");
                                break;
                        }
                    }

                    else if (lineArray[0] == "UPDATE")
                    {
                        switch (lineArray[1])
                        {
                            case "CLIENT":
                                if (GetClient(lineArray[3].Replace('~', ' '), out client))
                                {
                                    if (lineArray[2] == "BOMCOMPLETE")
                                    {
                                        client.BOMCOMPLETE = "Y";
                                    }
                                    else if (lineArray[2] == "CUPECOMPLETE")
                                    {
                                        client.CUPECOMPLETE = "Y";
                                    }
                                    else if (lineArray[2] == "ITCAPCOMPLETE")
                                    {
                                        client.ITCAPCOMPLETE = "Y";
                                    }
                                    else
                                    {
                                        MessageBox.Show("Invalid instruction detected:\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Update Client Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "BOM":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetBOM(lineArray[3].Replace('~', ' '), client, out bom))
                                    {
                                        bom.EFFECTIVENESS = Convert.ToSingle(lineArray[4]);
                                        bom.CRITICALITY = Convert.ToSingle(lineArray[5]);
                                        bom.DIFFERENTIAL = Convert.ToSingle(lineArray[6]);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Update BOM Instruction Failed: BOM does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Update BOM Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "CUPE":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetCUPE(lineArray[3].Replace('~', ' '), client, out cupe))
                                    {
                                        if (GetCUPEQuestion(lineArray[4].Replace('~', ' '), out cupeQuestion))
                                        {
                                            cupe.NAME = lineArray[4].Replace('~', ' ');
                                            cupe.COMMODITY = lineArray[5].Replace('~', ' ');
                                            cupe.UTILITY = lineArray[6].Replace('~', ' ');
                                            cupe.PARTNER = lineArray[7].Replace('~', ' ');
                                            cupe.ENABLER = lineArray[8].Replace('~', ' ');
                                            cupe.CUPEQUESTION = cupeQuestion;
                                        }
                                        else
                                        {
                                            MessageBox.Show("Update CUPE Instruction Failed: CUPEQuestion does not exist\n\n" + line, "Error");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Update CUPE Instruction Failed: CUPE does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Update CUPE Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "CUPEQUESTION":
                                if (GetCUPEQuestion(lineArray[2].Replace('~', ' '), out cupeQuestion))
                                {
                                    cupeQuestion.INTWENTY = lineArray[3];
                                    cupeQuestion.INTEN = lineArray[4];
                                }
                                else
                                {
                                    MessageBox.Show("Update CUPEQuestion Instruction Failed: CUPEQuestion does not exist\n\n" + line, "Error");
                                }
                                break;
                           case "ITCAP":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetITCAP(lineArray[3].Replace('~', ' '), client, out itcap))
                                    {
                                        itcap.ASIS = Convert.ToSingle(lineArray[4]);
                                        itcap.TOBE = Convert.ToSingle(lineArray[5]);
                                        itcap.ASISZEROS = Convert.ToInt32(lineArray[6]);
                                        itcap.TOBEZEROS = Convert.ToInt32(lineArray[7]);
                                        itcap.ASISONES = Convert.ToInt32(lineArray[8]);
                                        itcap.TOBEONES = Convert.ToInt32(lineArray[9]);
                                        itcap.ASISTWOS = Convert.ToInt32(lineArray[10]);
                                        itcap.TOBETWOS = Convert.ToInt32(lineArray[11]);
                                        itcap.ASISTHREES = Convert.ToInt32(lineArray[12]);
                                        itcap.TOBETHREES = Convert.ToInt32(lineArray[13]);
                                        itcap.ASISFOURS = Convert.ToInt32(lineArray[14]);
                                        itcap.TOBEFOURS = Convert.ToInt32(lineArray[15]);
                                        itcap.ASISFIVES = Convert.ToInt32(lineArray[16]);
                                        itcap.TOBEFIVES = Convert.ToInt32(lineArray[17]);
                                        List<COMMENT> commentsToDelete = itcap.COMMENT.ToList();
                                        foreach (COMMENT commentToDelete in commentsToDelete)
                                        {
                                            dbo.DeleteObject(commentToDelete);
                                        }
                                        for (int i = 18; i < lineArray.Count(); i++)
                                        {
                                            comment = new COMMENT();
                                            comment.NAME = lineArray[i].Replace('~', ' ');
                                            comment.ITCAP = itcap;
                                            dbo.AddToCOMMENT(comment);
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Update ITCAP Instruction Failed: ITCAP does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Update ITCAP Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "ITCAPOBJMAP":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetITCAPOBJMAP(client, lineArray[3].Replace('~', ' '), lineArray[4].Replace('~', ' '), out itcapObjMap))
                                    {
                                        itcapObjMap.SCORE = Convert.ToInt32(lineArray[5]);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Update CapabilityObjectiveMap Instruction Failed: CapabilityObjectiveMap does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Update CapabilityObjectiveMap Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "CAPABILITYGAPINFO":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetCapabilityGapInfo(lineArray[3].Replace('~', ' '), client, out capGapInfo))
                                    {
                                        capGapInfo.GAPTYPE = lineArray[4];
                                        capGapInfo.PRIORITIZEDGAPTYPE = lineArray[5];
                                        capGapInfo.GAP = Convert.ToSingle(lineArray[6]);
                                        capGapInfo.PRIORITIZEDGAP = Convert.ToSingle(lineArray[7]);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Update CapabilityGapInfo Instruction Failed: CapabilityGapInfo does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Update CapabilityGapInfo Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            default:
                                MessageBox.Show("Invalid instruction detected:\n\n" + line, "Error");
                                break;
                        }
                    }

                    else if (lineArray[0] == "DELETE")
                    {
                        switch (lineArray[1])
                        {
                            case "BOM":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetBOM(lineArray[3].Replace('~', ' '), client, out bom))
                                    {
                                        dbo.DeleteObject(bom);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Delete BOM Instruction Failed: BOM does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Delete BOM Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "CUPE":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    ClearCUPE(client);
                                }
                                else
                                {
                                    MessageBox.Show("Delete CUPE Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "CONTACTS":
                                List<CONTACT> contactsToDelete;
                                List<CUPERESPONSE> responsesToDelete;
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    foreach (GROUP grpToClear in client.GROUP)
                                    {
                                        contactsToDelete = grpToClear.CONTACT.ToList();
                                        foreach (CONTACT contactToDelete in contactsToDelete)
                                        {
                                            responsesToDelete = contactToDelete.CUPERESPONSE.ToList();
                                            foreach (CUPERESPONSE responseToDelete in responsesToDelete)
                                            {
                                                dbo.DeleteObject(responseToDelete);
                                            }
                                            dbo.DeleteObject(contactToDelete);
                                        }
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Delete CUPEResponse Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            case "ITCAP":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    if (GetITCAP(lineArray[3].Replace('~', ' '), client, out itcap))
                                    {
                                        dbo.DeleteObject(itcap);
                                    }
                                    else
                                    {
                                        MessageBox.Show("Delete ITCAP Instruction Failed: ITCAP does not exist\n\n" + line, "Error");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Delete ITCAP Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            default:
                                MessageBox.Show("Invalid instruction detected\n\n" + line, "Error");
                                break;
                        }
                    }

                    else if (lineArray[0] == "CLEAR")
                    {
                        switch (lineArray[1])
                        {
                            case "ITCAP":
                                if (GetClient(lineArray[2].Replace('~', ' '), out client))
                                {
                                    List<ITCAP> itcapsToDelete = client.ITCAP.ToList();
                                    foreach (ITCAP itcapToDelete in itcapsToDelete)
                                    {
                                        dbo.DeleteObject(itcapToDelete);
                                    }

                                    List<CAPABILITYGAPINFO> capGapInfosToDelete = client.CAPABILITYGAPINFO.ToList();
                                    foreach (CAPABILITYGAPINFO capGapInfoToDelete in capGapInfosToDelete)
                                    {
                                        dbo.DeleteObject(capGapInfoToDelete);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Delete ITCAP Instruction Failed: Client does not exist\n\n" + line, "Error");
                                }
                                break;
                            default:
                                MessageBox.Show("Invalid instruction detected\n\n" + line, "Error");
                                break;
                        }

                    }

                    else
                    {
                        MessageBox.Show("Invalid instruction detected:\n\n" + line, "Error");
                    }

                    if (!SaveChanges())
                    {
                        if (MessageBox.Show("Instruction failed to execute: \n" + line +
                                           "\n\nKeep change in log?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            failedChanges.Add(line);
                        }
                        break;
                    }

                    if (loadingScreen != null)
                    {
                        loadingScreen.LoadingTextLabel.Text = "Applying offline changes to database... " + (int)((linesComplete+=100)/totalLines) + "%";
                        loadingScreen.LoadingTextLabel.Update();
                    }
                }
            }

            File.WriteAllText(@"Resources\Changes.log", string.Empty);
            File.WriteAllLines(@"Resources\Changes.log", failedChanges);
        }
Exemplo n.º 4
0
        public void UpdateDataFile(LoadingDatabase loadingScreen = null)
        {
            if (loadingScreen != null)
            {
                loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Clearing old files";
                loadingScreen.LoadingTextLabel.Update();
            }

            if (!Directory.Exists(@"Resources\Clients"))
            {
                Directory.CreateDirectory(@"Resources\Clients");
            }

            List<string> clientFileNames = Directory.EnumerateFiles(@"Resources\Clients").ToList();
            List<string> clientNames = (from ent in clientFileNames
                                        select Path.GetFileNameWithoutExtension(ent)).ToList();

            if (loadingScreen != null)
            {
                loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Loading Clients";
                loadingScreen.LoadingTextLabel.Update();
            }

            CLIENT client;
            foreach (string clientName in clientNames)
            {
                if (!GetClient(clientName, out client)) continue;

                if (loadingScreen != null)
                {
                    loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Writing Client " + client.NAME.TrimEnd();
                    loadingScreen.LoadingTextLabel.Update();
                }
                XElement temp = new XElement("CLIENT");
                temp.Add(new XElement("NAME", client.NAME.TrimEnd()));
                temp.Add(new XElement("STARTDATE", client.STARTDATE.ToString()));
                temp.Add(new XElement("COUNTRY", client.COUNTRY.NAME.TrimEnd()));
                temp.Add(new XElement("REGION", client.COUNTRY.REGION.NAME.TrimEnd()));
                temp.Add(new XElement("BUSINESSTYPE", client.BUSINESSTYPE.NAME.TrimEnd()));
                temp.Add(new XElement("BOMCOMPLETE", client.BOMCOMPLETE));
                temp.Add(new XElement("CUPECOMPLETE", client.CUPECOMPLETE));
                temp.Add(new XElement("ITCAPCOMPLETE", client.ITCAPCOMPLETE));
                XElement grpElement = new XElement("GROUPS");
                foreach (GROUP grp in client.GROUP)
                {
                    XElement tempGrp = new XElement("GROUP");
                    tempGrp.Add(new XElement("NAME", grp.NAME.TrimEnd()));

                    XElement conElement = new XElement("CONTACTS");
                    foreach (CONTACT contact in grp.CONTACT)
                    {
                        XElement tempCon = new XElement("CONTACT");
                        tempCon.Add(new XElement("ID", contact.ID));

                        XElement cupeResConElement = new XElement("CUPERESPONSES");
                        foreach (CUPERESPONSE cupeResponse in contact.CUPERESPONSE)
                        {
                            XElement tempCUPERes = new XElement("CUPERESPONSE");
                            tempCUPERes.Add(new XElement("CUPE", cupeResponse.CUPE.NAME.TrimEnd()));
                            tempCUPERes.Add(new XElement("CURRENT", cupeResponse.CURRENT));
                            tempCUPERes.Add(new XElement("FUTURE", cupeResponse.FUTURE));
                            cupeResConElement.Add(tempCUPERes);
                        }
                        tempCon.Add(cupeResConElement);

                        conElement.Add(tempCon);
                    }
                    tempGrp.Add(conElement);

                    grpElement.Add(tempGrp);
                }
                temp.Add(grpElement);

                XElement bomElement = new XElement("BOMS");
                foreach (BOM bom in client.BOM)
                {
                    XElement tempBom = new XElement("BOM");
                    tempBom.Add(new XElement("IMPERATIVE", bom.IMPERATIVE.NAME.TrimEnd()));
                    tempBom.Add(new XElement("BUSINESSOBJECTIVE", bom.IMPERATIVE.BUSINESSOBJECTIVE.NAME.TrimEnd()));
                    tempBom.Add(new XElement("CATEGORY", bom.IMPERATIVE.BUSINESSOBJECTIVE.CATEGORY.NAME.TrimEnd()));
                    tempBom.Add(new XElement("EFFECTIVENESS", bom.EFFECTIVENESS != null ? bom.EFFECTIVENESS : 0));
                    tempBom.Add(new XElement("CRITICALITY", bom.CRITICALITY != null ? bom.CRITICALITY : 0));
                    tempBom.Add(new XElement("DIFFERENTIAL", bom.DIFFERENTIAL != null ? bom.DIFFERENTIAL : 0));
                    bomElement.Add(tempBom);
                }
                temp.Add(bomElement);

                XElement itcapElement = new XElement("ITCAPS");
                foreach (ITCAP itcap in client.ITCAP)
                {
                    XElement tempItcap = new XElement("ITCAP");
                    tempItcap.Add(new XElement("ITCAPQUESTION", itcap.ITCAPQUESTION.NAME.TrimEnd()));
                    tempItcap.Add(new XElement("CAPABILITY", itcap.ITCAPQUESTION.CAPABILITY.NAME.TrimEnd()));
                    tempItcap.Add(new XElement("DOMAIN", itcap.ITCAPQUESTION.CAPABILITY.DOMAIN.NAME.TrimEnd()));
                    tempItcap.Add(new XElement("ASIS", itcap.ASIS != null ? itcap.ASIS : 0));
                    tempItcap.Add(new XElement("ASISZEROS", itcap.ASISZEROS != null ? itcap.ASISZEROS : 0));
                    tempItcap.Add(new XElement("ASISONES", itcap.ASISONES != null ? itcap.ASISONES : 0));
                    tempItcap.Add(new XElement("ASISTWOS", itcap.ASISTWOS != null ? itcap.ASISTWOS : 0));
                    tempItcap.Add(new XElement("ASISTHREES", itcap.ASISTHREES != null ? itcap.ASISTHREES : 0));
                    tempItcap.Add(new XElement("ASISFOURS", itcap.ASISFOURS != null ? itcap.ASISFOURS : 0));
                    tempItcap.Add(new XElement("ASISFIVES", itcap.ASISFIVES != null ? itcap.ASISFIVES : 0));
                    tempItcap.Add(new XElement("TOBE", itcap.TOBE != null ? itcap.TOBE : 0));
                    tempItcap.Add(new XElement("TOBEZEROS", itcap.TOBEZEROS != null ? itcap.TOBEZEROS : 0));
                    tempItcap.Add(new XElement("TOBEONES", itcap.TOBEONES != null ? itcap.TOBEONES : 0));
                    tempItcap.Add(new XElement("TOBETWOS", itcap.TOBETWOS != null ? itcap.TOBETWOS : 0));
                    tempItcap.Add(new XElement("TOBETHREES", itcap.TOBETHREES != null ? itcap.TOBETHREES : 0));
                    tempItcap.Add(new XElement("TOBEFOURS", itcap.TOBEFOURS != null ? itcap.TOBEFOURS : 0));
                    tempItcap.Add(new XElement("TOBEFIVES", itcap.TOBEFIVES != null ? itcap.TOBEFIVES : 0));

                    XElement commentsElement = new XElement("COMMENTS");
                    foreach (COMMENT comment in itcap.COMMENT)
                    {
                        commentsElement.Add(new XElement("COMMENT", comment.NAME.TrimEnd()));
                    }
                    tempItcap.Add(commentsElement);

                    itcapElement.Add(tempItcap);
                }
                temp.Add(itcapElement);

                XElement cupeElement = new XElement("CUPES");
                foreach (CUPE cupe in client.CUPE)
                {
                    XElement tempCUPE = new XElement("CUPE");
                    tempCUPE.Add(new XElement("CUPEQUESTION", cupe.CUPEQUESTION.NAME.TrimEnd()));
                    tempCUPE.Add(new XElement("NAME", cupe.NAME.TrimEnd()));
                    tempCUPE.Add(new XElement("COMMODITY", cupe.COMMODITY.TrimEnd()));
                    tempCUPE.Add(new XElement("UTILITY", cupe.UTILITY.TrimEnd()));
                    tempCUPE.Add(new XElement("PARTNER", cupe.PARTNER.TrimEnd()));
                    tempCUPE.Add(new XElement("ENABLER", cupe.ENABLER.TrimEnd()));
                    tempCUPE.Add(new XElement("QUESTIONNUMBER", cupe.QUESTIONNUMBER));
                    cupeElement.Add(tempCUPE);
                }
                temp.Add(cupeElement);

                XElement itcapObjMapElement = new XElement("ITCAPOBJMAPS");
                foreach (ITCAPOBJMAP itcapObjMap in client.ITCAPOBJMAP)
                {
                    XElement tempITCAPObjMap = new XElement("ITCAPOBJMAP");
                    tempITCAPObjMap.Add(new XElement("CAPABILITY", itcapObjMap.CAPABILITY.NAME.TrimEnd()));
                    tempITCAPObjMap.Add(new XElement("BUSINESSOBJECTIVE", itcapObjMap.BUSINESSOBJECTIVE.NAME.TrimEnd()));
                    tempITCAPObjMap.Add(new XElement("SCORE", itcapObjMap.SCORE));
                    itcapObjMapElement.Add(tempITCAPObjMap);
                }
                temp.Add(itcapObjMapElement);

                XElement capGapInfoElement = new XElement("CAPABILITYGAPINFOS");
                foreach (CAPABILITYGAPINFO capGapInfo in client.CAPABILITYGAPINFO)
                {
                    XElement tempCapGapInfo = new XElement("CAPABILITYGAPINFO");
                    tempCapGapInfo.Add(new XElement("CAPABILITY", capGapInfo.CAPABILITY.NAME.TrimEnd()));
                    tempCapGapInfo.Add(new XElement("GAP", capGapInfo.GAP));
                    tempCapGapInfo.Add(new XElement("GAPTYPE", capGapInfo.GAPTYPE.TrimEnd()));
                    tempCapGapInfo.Add(new XElement("PRIORITIZEDGAP", capGapInfo.PRIORITIZEDGAP));
                    tempCapGapInfo.Add(new XElement("PRIORITIZEDGAPTYPE", capGapInfo.PRIORITIZEDGAPTYPE.TrimEnd()));
                    capGapInfoElement.Add(tempCapGapInfo);
                }
                temp.Add(capGapInfoElement);

                temp.Save(@"Resources\Clients\" + client.NAME.TrimEnd() + ".xml");
            }

            XElement root = new XElement("root");

            if (loadingScreen != null)
            {
                loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Writing Regions";
                loadingScreen.LoadingTextLabel.Update();
            }

            List<REGION> regList = dbo.REGION.ToList();
            XElement regElement = new XElement("REGIONS");
            foreach (REGION region in regList)
            {
                XElement tempReg = new XElement("REGION");
                tempReg.Add(new XElement("NAME", region.NAME.TrimEnd()));

                XElement counElement = new XElement("COUNTRIES");
                foreach (COUNTRY country in region.COUNTRY)
                {
                    XElement tempCoun = new XElement("COUNTRY");
                    tempCoun.Add(new XElement("NAME", country.NAME.TrimEnd()));
                    counElement.Add(tempCoun);
                }
                tempReg.Add(counElement);

                regElement.Add(tempReg);
            }
            root.Add(regElement);

            if (loadingScreen != null)
            {
                loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Writing BusinessTypes";
                loadingScreen.LoadingTextLabel.Update();
            }

            List<string> busTypeList = GetBusinessTypeNames();
            XElement busTypeElement = new XElement("BUSINESSTYPES");
            foreach (string busTypeName in busTypeList)
            {
                XElement tempBusType = new XElement("BUSINESSTYPE");
                tempBusType.Add(new XElement("NAME", busTypeName));
                busTypeElement.Add(tempBusType);
            }
            root.Add(busTypeElement);

            if (loadingScreen != null)
            {
                loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Writing BOM";
                loadingScreen.LoadingTextLabel.Update();
            }

            List<CATEGORY> catList = GetCategories();
            XElement catElement = new XElement("CATEGORIES");
            foreach (CATEGORY category in catList)
            {
                XElement temp = new XElement("CATEGORY");
                temp.Add(new XElement("NAME", category.NAME.TrimEnd()));

                XElement busElement = new XElement("BUSINESSOBJECTIVES");
                foreach (BUSINESSOBJECTIVE objective in category.BUSINESSOBJECTIVE)
                {
                    XElement tempBus = new XElement("BUSINESSOBJECTIVE");
                    tempBus.Add(new XElement("NAME", objective.NAME.TrimEnd()));

                    XElement iniElement = new XElement("IMPERATIVES");
                    foreach (IMPERATIVE imperative in objective.IMPERATIVE)
                    {
                        XElement tempIni = new XElement("IMPERATIVE");
                        tempIni.Add(new XElement("NAME", imperative.NAME.TrimEnd()));
                        iniElement.Add(tempIni);
                    }
                    tempBus.Add(iniElement);

                    busElement.Add(tempBus);
                }
                temp.Add(busElement);

                catElement.Add(temp);
            }
            root.Add(catElement);

            if (loadingScreen != null)
            {
                loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Writing CUPE";
                loadingScreen.LoadingTextLabel.Update();
            }

            List<CUPEQUESTION> cqList = dbo.CUPEQUESTION.ToList();
            XElement cqElement = new XElement("CUPEQUESTIONS");
            foreach (CUPEQUESTION cupeQuestion in cqList)
            {
                XElement tempCQ = new XElement("CUPEQUESTION");
                tempCQ.Add(new XElement("NAME", cupeQuestion.NAME.TrimEnd()));
                tempCQ.Add(new XElement("COMMODITY", cupeQuestion.COMMODITY.TrimEnd()));
                tempCQ.Add(new XElement("UTILITY", cupeQuestion.UTILITY.TrimEnd()));
                tempCQ.Add(new XElement("PARTNER", cupeQuestion.PARTNER.TrimEnd()));
                tempCQ.Add(new XElement("ENABLER", cupeQuestion.ENABLER.TrimEnd()));
                tempCQ.Add(new XElement("INTWENTY", cupeQuestion.INTWENTY));
                tempCQ.Add(new XElement("INTEN", cupeQuestion.INTEN));
                cqElement.Add(tempCQ);
            }
            root.Add(cqElement);

            if (loadingScreen != null)
            {
                loadingScreen.LoadingTextLabel.Text = "Updating filesystem... Writing ITCAP";
                loadingScreen.LoadingTextLabel.Update();
            }

            List<DOMAIN> domList = GetDomains();
            XElement domElement = new XElement("DOMAINS");
            foreach (DOMAIN domain in domList)
            {
                XElement temp = new XElement("DOMAIN");
                temp.Add(new XElement("NAME", domain.NAME.TrimEnd()));
                temp.Add(new XElement("ID", domain.ID.TrimEnd()));
                temp.Add(new XElement("DEFAULT", domain.DEFAULT));

                XElement capElement = new XElement("CAPABILITIES");
                foreach (CAPABILITY capability in domain.CAPABILITY)
                {
                    XElement tempCap = new XElement("CAPABILITY");
                    tempCap.Add(new XElement("NAME", capability.NAME.TrimEnd()));
                    tempCap.Add(new XElement("ID", capability.ID.TrimEnd()));
                    tempCap.Add(new XElement("DEFAULT", capability.DEFAULT));

                    XElement questionElement = new XElement("ITCAPQUESTIONS");
                    foreach (ITCAPQUESTION itcapQuestion in capability.ITCAPQUESTION)
                    {
                        XElement tempItcq = new XElement("ITCAPQUESTION");
                        tempItcq.Add(new XElement("NAME", itcapQuestion.NAME.TrimEnd()));
                        tempItcq.Add(new XElement("ID", itcapQuestion.ID.TrimEnd()));
                        tempItcq.Add(new XElement("DEFAULT", itcapQuestion.DEFAULT));
                        questionElement.Add(tempItcq);
                    }
                    tempCap.Add(questionElement);

                    capElement.Add(tempCap);
                }
                temp.Add(capElement);

                domElement.Add(temp);
            }
            root.Add(domElement);

            if (!Directory.Exists("Resources"))
            {
                Directory.CreateDirectory("Resources");
            }

            root.Save(@"Resources\Data.xml");
        }
Exemplo n.º 5
0
        public static bool LoadDatabase()
        {
            if (db == null || !isOnline)
            {
                LoadingDatabase loadingScreen = new LoadingDatabase();
                try
                {
                    //throw new Exception();
                    db = new DBManager(loadingScreen);
                    loadingScreen.Close();
                    isOnline = true;
                }
                catch (Exception e)
                {
                    loadingScreen.Close();
                    db = new FileManager();
                    isOnline = false;
                    MessageBox.Show("Could not connect to database\n\n" + e.Message + "\n\n" + "Offline mode set", "Error");
                }
            }

            return isOnline;
        }