Пример #1
0
        private void FormAutoCodeEdit_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult != DialogResult.OK)
            {
                if (IsNew)
                {
                    try {
                        AutoCodes.Delete(AutoCodeCur);
                    }
                    catch (ApplicationException ex) {
                        //should never happen
                        MessageBox.Show(ex.Message);
                    }
                    return;
                }
                if (listForCode.Count == 0)
                {
                    //Since changes to AutoCodeItems and AutoCodeConds are written to the database already, Cancel isn't a true cancel.
                    MsgBox.Show(this, "Must have at least one Code in the list.");                   //Block this invalid AutoCode state.
                    e.Cancel = true;
                    return;
                }
            }
            AutoCodeItems.RefreshCache();
            AutoCodeConds.RefreshCache();
            for (int i = 0; i < listForCode.Count; i++)       //Attach the conditions to the items for better organization
            {
                listForCode[i].ListConditions = new List <AutoCodeCond>();
                for (int j = 0; j < _listAutoCodeConds.Count; j++)//Fill conditions for this AutoCodeItem
                {
                    if (_listAutoCodeConds[j].AutoCodeItemNum == listForCode[i].AutoCodeItemNum)
                    {
                        listForCode[i].ListConditions.Add(_listAutoCodeConds[j]);
                    }
                }
            }
            //Must have same number of conditions for each AutoCodeItem.----------------------------------------------------------------------------------
            for (int i = 1; i < listForCode.Count; i++)       //start at 1 and compare to the 0 index.
            {
                if (listForCode[i].ListConditions.Count != listForCode[0].ListConditions.Count)
                {
                    MsgBox.Show(this, "All AutoCode items must have the same number of conditions.");
                    e.Cancel = true;
                    return;
                }
            }
            if (listForCode[0].ListConditions.Count == 0)           //Rest of the checks assume at least one condition.
            {
                return;
            }
            //Check for duplicate AutoCodeItem condition lists.-------------------------------------------------------------------------------------------
            for (int i = 1; i < listForCode.Count; i++) //start at 1
            {
                for (int j = 0; j < i; j++)             //loop through the lower-indexed entries
                {
                    int matches = 0;
                    for (int k = 0; k < listForCode[i].ListConditions.Count; k++)                           //For each condition in i, check for matches with conditions in j
                    {
                        if (listForCode[i].ListConditions[k].Cond == listForCode[j].ListConditions[k].Cond) //if the same condition is in both rows.
                        {
                            matches++;
                        }
                    }
                    if (matches == listForCode[i].ListConditions.Count)                   //If the number of matches equals the number of conditions on this row
                    {
                        MsgBox.Show(this, "Cannot have two AutoCode Items with duplicate conditions.");
                        e.Cancel = true;
                        return;
                    }
                }
            }
            //Decide which categories are involved.------------------------------------------------------------------------------------------------------
            bool isAnt          = false; //Not a category, could be isAntPost or isAntPreMol
            bool isAntPost      = false;
            bool isAntPreMol    = false; //Anterior/premolar/molar
            bool isNumSurf      = false;
            bool isFirstEachAdd = false;
            bool isMaxMand      = false;
            bool isPriPerm      = false;
            bool isPontRet      = false;

            for (int i = 0; i < listForCode.Count; i++)
            {
                //If the item matches the category, set the boolean to true.
                for (int j = 0; j < listForCode[i].ListConditions.Count; j++)
                {
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.Anterior)
                    {
                        isAnt = true;
                        //We want to also set either isAntPost or isAntPreMol, but we don't have enough information yet to set that.
                        continue;
                    }
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.Posterior)
                    {
                        isAntPost = true;
                        continue;
                    }
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.Premolar ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Molar
                        )
                    {
                        isAntPreMol = true;
                        continue;
                    }
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.One_Surf ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Two_Surf ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Three_Surf ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Four_Surf ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Five_Surf
                        )
                    {
                        isNumSurf = true;
                        continue;
                    }
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.First ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.EachAdditional
                        )
                    {
                        isFirstEachAdd = true;
                        continue;
                    }
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.Maxillary ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Mandibular
                        )
                    {
                        isMaxMand = true;
                        continue;
                    }
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.Primary ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Permanent
                        )
                    {
                        isPriPerm = true;
                        continue;
                    }
                    if (listForCode[i].ListConditions[j].Cond == AutoCondition.Pontic ||
                        listForCode[i].ListConditions[j].Cond == AutoCondition.Retainer
                        )
                    {
                        isPontRet = true;
                        continue;
                    }
                }
            }
            //After the loop, you had better have exactly the same number of booleans true as number of conditions on each item.--------------------
            if (isAntPost && isAntPreMol)
            {
                MsgBox.Show(this, "Cannot have both Posterior and Premolar/Molar categories.");
                e.Cancel = true;
                return;
            }
            if (isAnt)             //This is the only purpose of the isAnt bool.  We won't use it anymore.
            {
                if (!isAntPost && !isAntPreMol)
                {
                    MsgBox.Show(this, "Anterior condition is present without any corresponding posterior or premolar/molar condition.");
                    e.Cancel = true;
                    return;
                }
            }
            //Count how many categories were hit.
            int numCategories = 0;

            if (isAntPost)
            {
                numCategories++;
            }
            if (isAntPreMol)
            {
                numCategories++;
            }
            if (isNumSurf)
            {
                numCategories++;
            }
            if (isFirstEachAdd)
            {
                numCategories++;
            }
            if (isMaxMand)
            {
                numCategories++;
            }
            if (isPriPerm)
            {
                numCategories++;
            }
            if (isPontRet)
            {
                numCategories++;
            }
            if (numCategories != listForCode[0].ListConditions.Count)           //Every row has to have the same number of conditions
            {
                MessageBox.Show(Lan.g(this, "When using ") + listForCode[0].ListConditions.Count + Lan.g(this, " condition(s), you must use conditions from ")
                                + listForCode[0].ListConditions.Count + Lan.g(this, " logical categories. You are using conditions from ") + numCategories + Lan.g(this, " logical categories."));
                e.Cancel = true;
                return;
            }
            //Make sure that the number of AutoCodeItems is right. For example, if isAntPost and isNumSurf are the only true one, there should be 10 items.----------------------------------------
            int reqNumAutoCodeItems = 1;

            if (isAntPost)
            {
                reqNumAutoCodeItems = reqNumAutoCodeItems * 2;
            }
            if (isAntPreMol)
            {
                if (isPriPerm)
                {
                    reqNumAutoCodeItems = reqNumAutoCodeItems * 5;                //normally this would be 2*3 but primary molars don't exist, so we have 2*3-1=5
                }
                else
                {
                    reqNumAutoCodeItems = reqNumAutoCodeItems * 3;
                }
            }
            else
            {
                if (isPriPerm)
                {
                    reqNumAutoCodeItems = reqNumAutoCodeItems * 2;
                }
            }
            if (isNumSurf)
            {
                reqNumAutoCodeItems = reqNumAutoCodeItems * 5;
            }
            if (isFirstEachAdd)
            {
                reqNumAutoCodeItems = reqNumAutoCodeItems * 2;
            }
            if (isMaxMand)
            {
                reqNumAutoCodeItems = reqNumAutoCodeItems * 2;
            }
            if (isPontRet)
            {
                reqNumAutoCodeItems = reqNumAutoCodeItems * 2;
            }
            if (listForCode.Count != reqNumAutoCodeItems)
            {
                MessageBox.Show(Lan.g(this, "For the condition categories you are using, you should have ")
                                + reqNumAutoCodeItems + Lan.g(this, " entries in your list. You have ") + listForCode.Count + ".");
                e.Cancel = true;
                return;
            }
        }
Пример #2
0
        private void butOK_Click(object sender, System.EventArgs e)
        {
            if (textDescript.Text == "")
            {
                MessageBox.Show(Lan.g(this, "You must type in a description."));
                return;
            }
            if (listADA.Items.Count == 0 && listAutoCodes.SelectedIndices.Count == 0)
            {
                MessageBox.Show(Lan.g(this, "You must pick at least one Auto Code or Procedure Code."));
                return;
            }
            foreach (int index in listAutoCodes.SelectedIndices)
            {
                AutoCode autoCode = _listShortDeep[index];
                if (AutoCodeItems.GetListForCode(autoCode.AutoCodeNum).Count == 0)
                {
                    //This AutoCode was saved with no AutoCodeItems attached, which is invalid.
                    MessageBox.Show(this, Lan.g(this, "The following AutoCode has no associated Procedure Codes: ") + "\r\n" + autoCode.Description + "\r\n"
                                    + Lan.g(this, "AutoCode must be setup correctly before it can be used with a Quick Proc Button."));
                    return;
                }
            }
            //Point of no return.
            ProcButtonCur.Description = textDescript.Text;
            if (ProcButtonCur.Category != _listProcButtonCatDefs[comboCategory.SelectedIndex].DefNum)
            {
                //This will put it at the end of the order in the new category
                ProcButtonCur.ItemOrder
                    = ProcButtons.GetForCat(_listProcButtonCatDefs[comboCategory.SelectedIndex].DefNum).Length;
            }
            ProcButtonCur.Category     = _listProcButtonCatDefs[comboCategory.SelectedIndex].DefNum;
            ProcButtonCur.ButtonImage  = POut.Bitmap((Bitmap)pictureBox.Image, System.Drawing.Imaging.ImageFormat.Png);
            ProcButtonCur.IsMultiVisit = checkMultiVisit.Checked;
            if (IsNew)
            {
                ProcButtonCur.ItemOrder = ProcButtons.GetCount();
                ProcButtons.Insert(ProcButtonCur);
            }
            else
            {
                ProcButtons.Update(ProcButtonCur);
            }
            ProcButtonItems.DeleteAllForButton(ProcButtonCur.ProcButtonNum);
            ProcButtonItem item;

            for (int i = 0; i < listADA.Items.Count; i++)
            {
                item = new ProcButtonItem();
                item.ProcButtonNum = ProcButtonCur.ProcButtonNum;
                item.CodeNum       = ProcedureCodes.GetCodeNum(listADA.Items[i].ToString());
                item.ItemOrder     = i + 1;        //not i++, that would mess up the itteration.
                ProcButtonItems.Insert(item);
            }
            for (int i = 0; i < listAutoCodes.SelectedIndices.Count; i++)
            {
                item = new ProcButtonItem();
                item.ProcButtonNum = ProcButtonCur.ProcButtonNum;
                item.AutoCodeNum   = _listShortDeep[listAutoCodes.SelectedIndices[i]].AutoCodeNum;
                item.ItemOrder     = i + 1;        //not i++, that would mess up the itteration.
                ProcButtonItems.Insert(item);
            }
            DialogResult = DialogResult.OK;
        }