예제 #1
0
 ///<summary>The supplied DataRows must include the following columns: Priority,ToothRange,ToothNum,ProcCode.  This sorts procedures based on priority, then tooth number, then procCode.  It does not care about dates or status.  Currently used in TP module and Chart module sorting.</summary>
 public static int CompareProcedures(DataRow x, DataRow y)
 {
     //first, by priority
     if (x["Priority"].ToString() != y["Priority"].ToString())           //if priorities are different
     {
         if (x["Priority"].ToString() == "0")
         {
             return(1);                   //x is greater than y. Priorities always come first.
         }
         if (y["Priority"].ToString() == "0")
         {
             return(-1);                   //x is less than y. Priorities always come first.
         }
         return(DefB.GetOrder(DefCat.TxPriorities, PIn.PInt(x["Priority"].ToString())).CompareTo
                    (DefB.GetOrder(DefCat.TxPriorities, PIn.PInt(y["Priority"].ToString()))));
     }
     //priorities are the same, so sort by toothrange
     if (x["ToothRange"].ToString() != y["ToothRange"].ToString())
     {
         //empty toothranges come before filled toothrange values
         return(x["ToothRange"].ToString().CompareTo(y["ToothRange"].ToString()));
     }
     //toothranges are the same (usually empty), so compare toothnumbers
     if (x["ToothNum"].ToString() != y["ToothNum"].ToString())
     {
         //this also puts invalid or empty toothnumbers before the others.
         return(Tooth.ToInt(x["ToothNum"].ToString()).CompareTo(Tooth.ToInt(y["ToothNum"].ToString())));
     }
     //priority and toothnums are the same, so sort by proccode.
     return(x["ProcCode"].ToString().CompareTo(y["ProcCode"].ToString()));
     //return 0;//priority, tooth number, and proccode are all the same
 }
예제 #2
0
        private static DataTable GetTreeListTableForPatient(string patNum)
        {
            DataConnection dcon  = new DataConnection();
            DataTable      table = new DataTable("DocumentList");
            DataRow        row;
            DataTable      raw;
            string         command;
            //Rows are first added to the resultSet list so they can be sorted at the end as a larger group, then
            //they are placed in the datatable to be returned.
            List <Object> resultSet = new List <Object>();

            //columns that start with lowercase are altered for display rather than being raw data.
            table.Columns.Add("DocNum");
            table.Columns.Add("MountNum");
            table.Columns.Add("DocCategory");
            table.Columns.Add("DateCreated");
            table.Columns.Add("docFolder");            //The folder order to which the Document category corresponds.
            table.Columns.Add("description");
            table.Columns.Add("ImgType");
            //Move all documents which are invisible to the first document category.
            command = "SELECT DocNum FROM document WHERE PatNum='" + patNum + "' AND "
                      + "DocCategory<0";
            raw = dcon.GetTable(command);
            if (raw.Rows.Count > 0)          //Are there any invisible documents?
            {
                command = "UPDATE document SET DocCategory='" + DefB.Short[(int)DefCat.ImageCats][0].DefNum
                          + "' WHERE PatNum='" + patNum + "' AND (";
                for (int i = 0; i < raw.Rows.Count; i++)
                {
                    command += "DocNum='" + PIn.PInt(raw.Rows[i]["DocNum"].ToString()) + "' ";
                    if (i < raw.Rows.Count - 1)
                    {
                        command += "OR ";
                    }
                }
                command += ")";
                dcon.NonQ(command);
            }
            //Load all documents into the result table.
            command = "SELECT DocNum,DocCategory,DateCreated,Description,ImgType,MountItemNum FROM document WHERE PatNum='" + patNum + "'";
            raw     = dcon.GetTable(command);
            for (int i = 0; i < raw.Rows.Count; i++)
            {
                //Make sure hidden documents are never added (there is a small possibility that one is added after all are made visible).
                if (DefB.GetOrder(DefCat.ImageCats, PIn.PInt(raw.Rows[i]["DocCategory"].ToString())) < 0)
                {
                    continue;
                }
                //Do not add individual documents which are part of a mount object.
                if (PIn.PInt(raw.Rows[i]["MountItemNum"].ToString()) != 0)
                {
                    continue;
                }
                row                = table.NewRow();
                row["DocNum"]      = PIn.PInt(raw.Rows[i]["DocNum"].ToString());
                row["MountNum"]    = 0;
                row["DocCategory"] = PIn.PInt(raw.Rows[i]["DocCategory"].ToString());
                row["DateCreated"] = PIn.PDate(raw.Rows[i]["DateCreated"].ToString());
                row["docFolder"]   = DefB.GetOrder(DefCat.ImageCats, PIn.PInt(raw.Rows[i]["DocCategory"].ToString()));
                row["description"] = PIn.PDate(raw.Rows[i]["DateCreated"].ToString()).ToString("d") + ": "
                                     + PIn.PString(raw.Rows[i]["Description"].ToString());
                row["ImgType"] = PIn.PInt(raw.Rows[i]["ImgType"].ToString());
                resultSet.Add(row);
            }
            //Move all mounts which are invisible to the first document category.
            command = "SELECT MountNum FROM mount WHERE PatNum='" + patNum + "' AND "
                      + "DocCategory<0";
            raw = dcon.GetTable(command);
            if (raw.Rows.Count > 0)           //Are there any invisible mounts?
            {
                command = "UPDATE mount SET DocCategory='" + DefB.Short[(int)DefCat.ImageCats][0].DefNum
                          + "' WHERE PatNum='" + patNum + "' AND (";
                for (int i = 0; i < raw.Rows.Count; i++)
                {
                    command += "MountNum='" + PIn.PInt(raw.Rows[i]["MountNum"].ToString()) + "' ";
                    if (i < raw.Rows.Count - 1)
                    {
                        command += "OR ";
                    }
                }
                command += ")";
                dcon.NonQ(command);
            }
            //Load all mounts into the result table.
            command = "SELECT MountNum,DocCategory,DateCreated,Description,ImgType FROM mount WHERE PatNum='" + patNum + "'";
            raw     = dcon.GetTable(command);
            for (int i = 0; i < raw.Rows.Count; i++)
            {
                //Make sure hidden mounts are never added (there is a small possibility that one is added after all are made visible).
                if (DefB.GetOrder(DefCat.ImageCats, PIn.PInt(raw.Rows[i]["DocCategory"].ToString())) < 0)
                {
                    continue;
                }
                row                = table.NewRow();
                row["DocNum"]      = 0;
                row["MountNum"]    = PIn.PInt(raw.Rows[i]["MountNum"].ToString());
                row["DocCategory"] = PIn.PInt(raw.Rows[i]["DocCategory"].ToString());
                row["DateCreated"] = PIn.PDate(raw.Rows[i]["DateCreated"].ToString());
                row["docFolder"]   = DefB.GetOrder(DefCat.ImageCats, PIn.PInt(raw.Rows[i]["DocCategory"].ToString()));
                row["description"] = PIn.PDate(raw.Rows[i]["DateCreated"].ToString()).ToString("d") + ": "
                                     + PIn.PString(raw.Rows[i]["Description"].ToString());
                row["ImgType"] = PIn.PInt(raw.Rows[i]["ImgType"].ToString());
                resultSet.Add(row);
            }
            //We must soft the results after they are returned from the database, because the database software (i.e. MySQL)
            //cannot return sorted results from two or more result sets like we have here.
            resultSet.Sort(delegate(Object o1, Object o2) {
                DataRow r1     = (DataRow)o1;
                DataRow r2     = (DataRow)o2;
                int docFolder1 = Convert.ToInt32(r1["docFolder"].ToString());
                int docFolder2 = Convert.ToInt32(r2["docFolder"].ToString());
                if (docFolder1 < docFolder2)
                {
                    return(-1);
                }
                else if (docFolder1 > docFolder2)
                {
                    return(1);
                }
                return(PIn.PDate(r1["DateCreated"].ToString()).CompareTo(PIn.PDate(r2["DateCreated"].ToString())));
            });
            //Finally, move the results from the list into a data table.
            for (int i = 0; i < resultSet.Count; i++)
            {
                table.Rows.Add((DataRow)resultSet[i]);
            }
            return(table);
        }