Example #1
0
        public override bool AddImperativeToBOM(string iniName, string busName, string catName, BOMTool bomForm)
        {
            IMPERATIVE imperative;
            if (!GetImperative(iniName, out imperative))
            {
                imperative = new IMPERATIVE();
                imperative.NAME = iniName;
                BUSINESSOBJECTIVE objective;
                if (!GetObjective(busName, out objective))
                {
                    objective = new BUSINESSOBJECTIVE();
                    objective.NAME = busName;
                    CATEGORY category;
                    if (!GetCategory(catName, out category))
                    {
                        category = new CATEGORY();
                        category.NAME = catName;
                        if (!AddCategory(category))
                        {
                            MessageBox.Show("Failed to add Category to Database", "Error");
                            return false;
                        }
                    }

                    objective.CATEGORY = category;
                    if (!AddObjective(objective))
                    {
                        MessageBox.Show("Failed to add Objective to Database", "Error");
                        return false;
                    }
                }

                else if (objective.CATEGORY.NAME.TrimEnd() != catName)
                {
                    MessageBox.Show("Objective already exists under category " + objective.CATEGORY.NAME.TrimEnd(), "Error");
                    return false;
                }

                imperative.BUSINESSOBJECTIVE = objective;
                if (!AddImperative(imperative))
                {
                    MessageBox.Show("Failed to add Imperative to Database", "Error");
                    return false;
                }
            }

            else if (imperative.BUSINESSOBJECTIVE.NAME.TrimEnd() != busName)
            {
                MessageBox.Show("Imperative already exists under objective " + imperative.BUSINESSOBJECTIVE.NAME.TrimEnd(), "Error");
                return false;
            }

            BUSINESSOBJECTIVE testObjective;
            if (GetObjective(busName, out testObjective) && testObjective.CATEGORY.NAME.TrimEnd() != catName)
            {
                MessageBox.Show("Objective already exists under category " + testObjective.CATEGORY.NAME.TrimEnd(), "Error");
                return false;
            }

            BOM bom = new BOM();
            bom.IMPERATIVE = imperative;
            if (!AddBOM(bom, ClientDataControl.Client.EntityObject))
            {
                MessageBox.Show("Failed to add Imperative to BOM", "Error");
                return false;
            }
            if (!SaveChanges())
            {
                MessageBox.Show("Failed to save changes to database", "Error");
                return false;
            }

            else
            {
                //Successfully added to database, update GUI
                catName = bom.IMPERATIVE.BUSINESSOBJECTIVE.CATEGORY.NAME.TrimEnd();
                NewCategory category = bomForm.Categories.Find(delegate(NewCategory cat)
                {
                    return cat.name == catName;
                });
                if (category == null)
                {
                    category = bomForm.AddCategory(catName);
                }

                bomForm.CategoryWorkspace.SelectTab(category.name);

                busName = bom.IMPERATIVE.BUSINESSOBJECTIVE.NAME.TrimEnd();
                NewObjective objective = category.Objectives.Find(delegate(NewObjective bus)
                {
                    return bus.ObjName == busName;
                });
                if (objective == null)
                {
                    objective = category.AddObjective(busName);
                }

                iniName = bom.IMPERATIVE.NAME.TrimEnd();
                NewImperative imperativeObj = objective.Imperatives.Find(delegate(NewImperative ini)
                {
                    return ini.Name == iniName;
                });
                if (imperativeObj == null)
                {
                    imperativeObj = objective.AddImperative(iniName);
                }
                else
                {
                    MessageBox.Show("Imperative already exists in BOM", "Error");
                }
            }

            return true;
        }
Example #2
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);
        }
Example #3
0
        public bool AddCategory(CATEGORY category)
        {
            //If already in DB, return 1
            if ((from ent in dbo.CATEGORY
                 where ent.NAME.TrimEnd() == category.NAME.TrimEnd()
                 select ent).Count() != 0)
            {
                dbo.Detach(category);
                return false;
            }

            dbo.AddToCATEGORY(category);

            return true;
        }
Example #4
0
        public bool GetCategory(string catName, out CATEGORY category)
        {
            try
            {
                category = (from ent in dbo.CATEGORY
                            where ent.NAME.TrimEnd() == catName
                            select ent).Single();
            }

            catch
            {
                category = null;
                return false;
            }

            return true;
        }
 /// <summary>
 /// Create a new CATEGORY object.
 /// </summary>
 /// <param name="cATEGORYID">Initial value of the CATEGORYID property.</param>
 /// <param name="nAME">Initial value of the NAME property.</param>
 public static CATEGORY CreateCATEGORY(global::System.Int32 cATEGORYID, global::System.String nAME)
 {
     CATEGORY cATEGORY = new CATEGORY();
     cATEGORY.CATEGORYID = cATEGORYID;
     cATEGORY.NAME = nAME;
     return cATEGORY;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the CATEGORY EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCATEGORY(CATEGORY cATEGORY)
 {
     base.AddObject("CATEGORY", cATEGORY);
 }
Example #7
0
        private void AddInitiativeToTableButton_Click(object sender, EventArgs e)
        {
            List<int> idList;
            var selectedInitiativeQuery = from ini in mainForm.dbo.INITIATIVE
                                          where ini.NAME == InitiativeComboBox.Text
                                          select ini;

            if (selectedInitiativeQuery.Count() == 0)
            {
                selectedInitiative = new INITIATIVE();
                selectedInitiative.NAME = InitiativeComboBox.Text;
                idList = (from ini in mainForm.dbo.INITIATIVE
                          select ini.INITIATIVEID).ToList();
                selectedInitiative.INITIATIVEID = mainForm.GetUniqueID(idList);
                var selectedBusinessObjectiveQuery = from bus in mainForm.dbo.BUSINESSOBJECTIVE
                                                     where bus.NAME == BusinessObjectiveComboBox.Text
                                                     select bus;

                if (selectedBusinessObjectiveQuery.Count() == 0)
                {
                    selectedBusinessObjective = new BUSINESSOBJECTIVE();
                    selectedBusinessObjective.NAME = BusinessObjectiveComboBox.Text;
                    idList = (from bus in mainForm.dbo.BUSINESSOBJECTIVE
                              select bus.BUSINESSOBJECTIVEID).ToList();
                    selectedBusinessObjective.BUSINESSOBJECTIVEID = mainForm.GetUniqueID(idList);
                    var selectedCategoryQuery = from cat in mainForm.dbo.CATEGORY
                                                where cat.NAME == CategoryComboBox.Text
                                                select cat;

                    if (selectedCategoryQuery.Count() == 0)
                    {
                        selectedCategory = new CATEGORY();
                        selectedCategory.NAME = CategoryComboBox.Text;
                        idList = (from cat in mainForm.dbo.CATEGORY
                                 select cat.CATEGORYID).ToList();
                        selectedCategory.CATEGORYID = mainForm.GetUniqueID(idList);
                        selectedCategory.BUSINESSOBJECTIVE.Add(selectedBusinessObjective);
                        mainForm.dbo.AddToCATEGORY(selectedCategory);
                    }

                    selectedBusinessObjective.CATEGORY = selectedCategory;
                    selectedBusinessObjective.INITIATIVE.Add(selectedInitiative);
                    mainForm.dbo.AddToBUSINESSOBJECTIVE(selectedBusinessObjective);
                }

                selectedInitiative.BUSINESSOBJECTIVE = selectedBusinessObjective;

                mainForm.dbo.AddToINITIATIVE(selectedInitiative);
            }

            BOM newBOM = new BOM();
            idList = (from bom in mainForm.dbo.BOM
                     select bom.BOMID).ToList();
            newBOM.BOMID = mainForm.GetUniqueID(idList);
            newBOM.CLIENT = mainForm.currentClient;
            newBOM.INITIATIVE = selectedInitiative;
            selectedInitiative.BOM.Add(newBOM);

            mainForm.dbo.SaveChanges();

            DataGridViewRow row = (DataGridViewRow)mainForm.BOMTable.Rows[0].Clone();
            row.Cells[0].Value = selectedCategory.NAME;
            row.Cells[1].Value = selectedBusinessObjective.NAME;
            row.Cells[2].Value = selectedInitiative.NAME;
            mainForm.BOMTable.Rows.Add(row);
            this.Close();
        }
Example #8
0
        private void CategoryComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                var selectedCategoryQuery = from cat in mainForm.dbo.CATEGORY
                                            where cat.NAME == CategoryComboBox.Text
                                            select cat;

                selectedCategory = selectedCategoryQuery.Single();
            }

            catch { }

            BusinessObjectiveComboBox.Items.Clear();
            BusinessObjectiveComboBox.Text = "";
            foreach (BUSINESSOBJECTIVE businessObjective in selectedCategory.BUSINESSOBJECTIVE)
            {
                BusinessObjectiveComboBox.Items.Add(businessObjective.NAME);
            }

            InitiativeComboBox.Items.Clear();
            InitiativeComboBox.Text = "";
        }
Example #9
0
        private void initiativeAddButton_Click(object sender, EventArgs e)
        {
            string catName;
            string busName;
            string iniName = initiativeNames.Text.Trim();
            INITIATIVE initiative;
            if (!db.GetInitiative(iniName, out initiative))
            {
                initiative = new INITIATIVE();
                initiative.NAME = iniName;
                BUSINESSOBJECTIVE objective;
                busName = objectiveNames.Text.Trim();
                if(!db.GetObjective(busName, out objective))
                {
                    objective = new BUSINESSOBJECTIVE();
                    objective.NAME = objectiveNames.Text.Trim();
                    CATEGORY category;
                    catName = categoryNames.Text.Trim();
                    if(!db.GetCategory(catName, out category))
                    {
                        category = new CATEGORY();
                        category.NAME = catName;
                        if(!db.AddCategory(category))
                        {
                            MessageBox.Show("Failed to add Category to Database", "Error");
                            return;
                        }
                    }

                    objective.CATEGORY = category;
                    if (!db.AddObjective(objective))
                    {
                        MessageBox.Show("Failed to add Objective to Database", "Error");
                        return;
                    }
                }

                initiative.BUSINESSOBJECTIVE = objective;
                if (!db.AddInitiative(initiative))
                {
                    MessageBox.Show("Failed to add Initiative to Database", "Error");
                    return;
                }
            }

            BOM bom = new BOM();
            bom.INITIATIVE = initiative;
            if (!db.AddBOM(bom, client))
            {
                MessageBox.Show("Failed to add Initiative to BOM", "Error");
                return;
            }
            if (!db.SaveChanges())
            {
                MessageBox.Show("Failed to save changes to database", "Error");
                return;
            }

            else
            {
                //Successfully added to database, update GUI
                catName = bom.INITIATIVE.BUSINESSOBJECTIVE.CATEGORY.NAME.TrimEnd();
                Category category = categories.Find(delegate(Category cat)
                {
                    return cat.Name == catName;
                });
                if (category == null)
                {
                    category = new Category(this, catName);
                    categories.Add(category);
                    categoryCount++;
                    category.Click += new EventHandler(category_Click);
                }

                busName = bom.INITIATIVE.BUSINESSOBJECTIVE.NAME.TrimEnd();
                BusinessObjective objective = category.Objectives.Find(delegate(BusinessObjective bus)
                {
                    return bus.Name == busName;
                });
                if (objective == null)
                {
                    objective = category.AddObjective(busName);
                }

                iniName = bom.INITIATIVE.NAME.TrimEnd();
                Initiative initiativeObj = objective.Initiatives.Find(delegate(Initiative ini)
                                                                   {
                                                                       return ini.Name == iniName;
                                                                   });
                if (initiativeObj == null)
                {
                    initiativeObj = objective.AddInitiative(iniName);
                }
                else
                {
                    MessageBox.Show("Initiative already exists in BOM", "Error");
                }
            }
        }