Beispiel #1
0
        ///<summary>Used by the refresh method above.</summary>
        private static Def[] GetForCategory(int catIndex, bool includeHidden, DataTable table)
        {
            List <Def> list = new List <Def>();
            Def        def;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                if (PIn.PInt(table.Rows[i][1].ToString()) != catIndex)
                {
                    continue;
                }
                if (PIn.PBool(table.Rows[i][6].ToString()) &&            //if is hidden
                    !includeHidden)                       //and we don't want to include hidden
                {
                    continue;
                }
                def           = new Def();
                def.DefNum    = PIn.PInt(table.Rows[i][0].ToString());
                def.Category  = (DefCat)PIn.PInt(table.Rows[i][1].ToString());
                def.ItemOrder = PIn.PInt(table.Rows[i][2].ToString());
                def.ItemName  = PIn.PString(table.Rows[i][3].ToString());
                def.ItemValue = PIn.PString(table.Rows[i][4].ToString());
                def.ItemColor = Color.FromArgb(PIn.PInt(table.Rows[i][5].ToString()));
                def.IsHidden  = PIn.PBool(table.Rows[i][6].ToString());
                list.Add(def);
            }
            return(list.ToArray());
        }
Beispiel #2
0
        ///<summary></summary>
        public static Document Fill(DataRow document)
        {
            if (document == null)
            {
                return(null);
            }
            Document doc = new Document();

            doc.DocNum         = PIn.PInt(document[0].ToString());
            doc.Description    = PIn.PString(document[1].ToString());
            doc.DateCreated    = PIn.PDate(document[2].ToString());
            doc.DocCategory    = PIn.PInt(document[3].ToString());
            doc.PatNum         = PIn.PInt(document[4].ToString());
            doc.FileName       = PIn.PString(document[5].ToString());
            doc.ImgType        = (ImageType)PIn.PInt(document[6].ToString());
            doc.IsFlipped      = PIn.PBool(document[7].ToString());
            doc.DegreesRotated = PIn.PShort(document[8].ToString());
            doc.ToothNumbers   = PIn.PString(document[9].ToString());
            doc.Note           = PIn.PString(document[10].ToString());
            doc.SigIsTopaz     = PIn.PBool(document[11].ToString());
            doc.Signature      = PIn.PString(document[12].ToString());
            doc.CropX          = PIn.PInt(document[13].ToString());
            doc.CropY          = PIn.PInt(document[14].ToString());
            doc.CropW          = PIn.PInt(document[15].ToString());
            doc.CropH          = PIn.PInt(document[16].ToString());
            doc.WindowingMin   = PIn.PInt(document[17].ToString());
            doc.WindowingMax   = PIn.PInt(document[18].ToString());
            doc.MountItemNum   = PIn.PInt(document[19].ToString());
            return(doc);
        }
 public static Appointment[] TableToObjects(DataTable table)
 {
     Appointment[] list = new Appointment[table.Rows.Count];
     for (int i = 0; i < table.Rows.Count; i++)
     {
         list[i]               = new Appointment();
         list[i].AptNum        = PIn.PInt(table.Rows[i][0].ToString());
         list[i].PatNum        = PIn.PInt(table.Rows[i][1].ToString());
         list[i].AptStatus     = (ApptStatus)PIn.PInt(table.Rows[i][2].ToString());
         list[i].Pattern       = PIn.PString(table.Rows[i][3].ToString());
         list[i].Confirmed     = PIn.PInt(table.Rows[i][4].ToString());
         list[i].AddTime       = PIn.PInt(table.Rows[i][5].ToString());
         list[i].Op            = PIn.PInt(table.Rows[i][6].ToString());
         list[i].Note          = PIn.PString(table.Rows[i][7].ToString());
         list[i].ProvNum       = PIn.PInt(table.Rows[i][8].ToString());
         list[i].ProvHyg       = PIn.PInt(table.Rows[i][9].ToString());
         list[i].AptDateTime   = PIn.PDateT(table.Rows[i][10].ToString());
         list[i].NextAptNum    = PIn.PInt(table.Rows[i][11].ToString());
         list[i].UnschedStatus = PIn.PInt(table.Rows[i][12].ToString());
         //list[i].Lab            =PIn.PInt(table.Rows[i][13].ToString());
         list[i].IsNewPatient    = PIn.PBool(table.Rows[i][14].ToString());
         list[i].ProcDescript    = PIn.PString(table.Rows[i][15].ToString());
         list[i].Assistant       = PIn.PInt(table.Rows[i][16].ToString());
         list[i].InstructorNum   = PIn.PInt(table.Rows[i][17].ToString());
         list[i].SchoolClassNum  = PIn.PInt(table.Rows[i][18].ToString());
         list[i].SchoolCourseNum = PIn.PInt(table.Rows[i][19].ToString());
         list[i].GradePoint      = PIn.PFloat(table.Rows[i][20].ToString());
         list[i].ClinicNum       = PIn.PInt(table.Rows[i][21].ToString());
         list[i].IsHygiene       = PIn.PBool(table.Rows[i][22].ToString());
     }
     return(list);
 }
Beispiel #4
0
        ///<summary></summary>
        public static void FillLists(DataSet ds)
        {
            DataTable table = ds.Tables[0];

            Listt = new CovCat[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                Listt[i]                = new CovCat();
                Listt[i].CovCatNum      = PIn.PInt(table.Rows[i][0].ToString());
                Listt[i].Description    = PIn.PString(table.Rows[i][1].ToString());
                Listt[i].DefaultPercent = PIn.PInt(table.Rows[i][2].ToString());
                Listt[i].CovOrder       = PIn.PInt(table.Rows[i][3].ToString());
                Listt[i].IsHidden       = PIn.PBool(table.Rows[i][4].ToString());
                Listt[i].EbenefitCat    = (EbenefitCategory)PIn.PInt(table.Rows[i][5].ToString());
            }
            table     = ds.Tables[1];
            ListShort = new CovCat[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                ListShort[i]                = new CovCat();
                ListShort[i].CovCatNum      = PIn.PInt(table.Rows[i][0].ToString());
                ListShort[i].Description    = PIn.PString(table.Rows[i][1].ToString());
                ListShort[i].DefaultPercent = PIn.PInt(table.Rows[i][2].ToString());
                ListShort[i].CovOrder       = PIn.PInt(table.Rows[i][3].ToString());
                ListShort[i].IsHidden       = PIn.PBool(table.Rows[i][4].ToString());
                ListShort[i].EbenefitCat    = (EbenefitCategory)PIn.PInt(table.Rows[i][5].ToString());
            }
        }
Beispiel #5
0
        ///<summary>Backs up the database to the same directory as the original just in case the user did not have sense enough to do a backup first.</summary>
        public static int MakeABackup()
        {
            //only used in two places: upgrading version, and upgrading mysql version.
            //Both places check first to make sure user is using mysql.
            //we have to be careful to throw an exception if the backup is failing.
            DataConnection dcon    = new DataConnection();
            string         command = "SELECT database()";
            DataTable      table   = dcon.GetTable(command);
            string         oldDb   = PIn.PString(table.Rows[0][0].ToString());
            string         newDb   = oldDb + "backup_" + DateTime.Today.ToString("MM_dd_yyyy");

            command = "SHOW DATABASES";
            table   = dcon.GetTable(command);
            string[] databases = new string[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                databases[i] = table.Rows[i][0].ToString();
            }
            if (Contains(databases, newDb))            //if the new database name already exists
            //find a unique one
            {
                int    uniqueID      = 1;
                string originalNewDb = newDb;
                do
                {
                    newDb = originalNewDb + "_" + uniqueID.ToString();
                    uniqueID++;
                }while(Contains(databases, newDb));
            }
            command = "CREATE DATABASE " + newDb + " CHARACTER SET utf8";
            dcon.NonQ(command);
            command = "SHOW TABLES";
            table   = dcon.GetTable(command);
            string[] tableName = new string[table.Rows.Count];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                tableName[i] = table.Rows[i][0].ToString();
            }
            //switch to using the new database
            DataConnection newDcon = new DataConnection(newDb);

            for (int i = 0; i < tableName.Length; i++)
            {
                command = "SHOW CREATE TABLE " + oldDb + "." + tableName[i];
                table   = newDcon.GetTable(command);
                command = table.Rows[0][1].ToString();
                newDcon.NonQ(command);                //this has to be run using connection with new database
                command = "INSERT INTO " + newDb + "." + tableName[i]
                          + " SELECT * FROM " + oldDb + "." + tableName[i];
                newDcon.NonQ(command);
            }
            return(0);
        }
Beispiel #6
0
        ///<summary></summary>
        public static void FillHList(DataTable table)
        {
            HList = new Hashtable();
            Pref pref;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                pref             = new Pref();
                pref.PrefName    = PIn.PString(table.Rows[i][0].ToString());
                pref.ValueString = PIn.PString(table.Rows[i][1].ToString());
                HList.Add(pref.PrefName, pref);
            }
        }
Beispiel #7
0
        ///<summary>Converts the given datarow into a mount object.</summary>
        public static Mount Fill(DataRow mountRow)
        {
            Mount mount = new Mount();

            mount.MountNum    = PIn.PInt(mountRow["MountNum"].ToString());
            mount.PatNum      = PIn.PInt(mountRow["PatNum"].ToString());
            mount.DocCategory = PIn.PInt(mountRow["DocCategory"].ToString());
            mount.DateCreated = PIn.PDate(mountRow["DateCreated"].ToString());
            mount.Description = PIn.PString(mountRow["Description"].ToString());
            mount.Note        = PIn.PString(mountRow["Note"].ToString());
            mount.ImgType     = (ImageType)PIn.PInt(mountRow["ImgType"].ToString());
            mount.Width       = PIn.PInt(mountRow["Width"].ToString());
            mount.Height      = PIn.PInt(mountRow["Height"].ToString());
            return(mount);
        }
Beispiel #8
0
        ///<summary></summary>
        public static Userod GetUser(int userNum)
        {
            Userod user = null;

            for (int i = 0; i < RawData.Rows.Count; i++)
            {
                if (RawData.Rows[i]["UserNum"].ToString() != userNum.ToString())
                {
                    continue;
                }
                user              = new Userod();
                user.UserNum      = PIn.PInt(RawData.Rows[i][0].ToString());
                user.UserName     = PIn.PString(RawData.Rows[i][1].ToString());
                user.Password     = PIn.PString(RawData.Rows[i][2].ToString());
                user.UserGroupNum = PIn.PInt(RawData.Rows[i][3].ToString());
                user.EmployeeNum  = PIn.PInt(RawData.Rows[i][4].ToString());
            }
            return(user);
        }
Beispiel #9
0
        ///<summary>Gets a list of all MountDefs when program first opens.  Also refreshes MountItemDefs and attaches all items to the appropriate mounts.</summary>
        public static void Refresh()
        {
            MountItemDefs.Refresh();
            string    command = "SELECT * FROM mountdef ORDER BY ItemOrder";
            DataTable table   = General2.GetTable(command);

            Listt = new List <MountDef>();
            MountDef mount;

            for (int i = 0; i < table.Rows.Count; i++)
            {
                mount              = new MountDef();
                mount.MountDefNum  = PIn.PInt(table.Rows[i][0].ToString());
                mount.Description  = PIn.PString(table.Rows[i][1].ToString());
                mount.ItemOrder    = PIn.PInt(table.Rows[i][2].ToString());
                mount.IsRadiograph = PIn.PBool(table.Rows[i][3].ToString());
                mount.Width        = PIn.PInt(table.Rows[i][4].ToString());
                mount.Height       = PIn.PInt(table.Rows[i][5].ToString());
                Listt.Add(mount);
            }
        }
Beispiel #10
0
        ///<summary>This is used by FormImageViewer to get a list of paths based on supplied list of DocNums. The reason is that later we will allow sharing of documents, so the paths may not be in the current patient folder.</summary>
        public static ArrayList GetPaths(ArrayList docNums)
        {
            if (docNums.Count == 0)
            {
                return(new ArrayList());
            }
            string command = "SELECT document.DocNum,document.FileName,patient.ImageFolder "
                             + "FROM document "
                             + "LEFT JOIN patient ON patient.PatNum=document.PatNum "
                             + "WHERE document.DocNum = '" + docNums[0].ToString() + "'";

            for (int i = 1; i < docNums.Count; i++)
            {
                command += " OR document.DocNum = '" + docNums[i].ToString() + "'";
            }
            //remember, they will not be in the correct order.
            DataTable table = General2.GetTable(command);
            Hashtable hList = new Hashtable();          //key=docNum, value=path

            //one row for each document, but in the wrong order
            for (int i = 0; i < table.Rows.Count; i++)
            {
                //We do not need to check if A to Z folders are being used here, because
                //thumbnails are not visible from the chart module when A to Z are disabled,
                //making it impossible to launch the form image viewer (the only place this
                //function is called from.
                hList.Add(PIn.PInt(table.Rows[i][0].ToString()),
                          ODFileUtils.CombinePaths(new string[] { FileStoreSettings.GetPreferredImagePath,
                                                                  PIn.PString(table.Rows[i][2].ToString()).Substring(0, 1).ToUpper(),
                                                                  PIn.PString(table.Rows[i][2].ToString()),
                                                                  PIn.PString(table.Rows[i][1].ToString()), }));
            }
            ArrayList retVal = new ArrayList();

            for (int i = 0; i < docNums.Count; i++)
            {
                retVal.Add((string)hList[(int)docNums[i]]);
            }
            return(retVal);
        }
Beispiel #11
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);
        }
Beispiel #12
0
        ///<summary>Inserts a new document into db, creates a filename based on Cur.DocNum, and then updates the db with this filename.  Also attaches the document to the current patient.</summary>
        public static int Insert(Document doc, string patLF, int patNum)
        {
            if (PrefB.RandomKeys)
            {
                doc.DocNum = MiscDataB.GetKey("document", "DocNum");
            }
            string command = "INSERT INTO document (";

            if (PrefB.RandomKeys)
            {
                command += "DocNum,";
            }
            command += "Description,DateCreated,DocCategory,WithPat,FileName,ImgType,"
                       + "IsFlipped,DegreesRotated,ToothNumbers,Note,SigIsTopaz,Signature,CropX,CropY,CropW,CropH,"
                       + "WindowingMin,WindowingMax) VALUES(";
            if (PrefB.RandomKeys)
            {
                command += "'" + POut.PInt(doc.DocNum) + "', ";
            }
            command +=
                "'" + POut.PString(doc.Description) + "', "
                + POut.PDate(doc.DateCreated) + ", "
                + "'" + POut.PInt(doc.DocCategory) + "', "
                + "'" + POut.PInt(doc.WithPat) + "', "
                + "'" + POut.PString(doc.FileName) + "', "           //this may simply be the extension at this point, or it may be the full filename.
                + "'" + POut.PInt((int)doc.ImgType) + "', "
                + "'" + POut.PBool(doc.IsFlipped) + "', "
                + "'" + POut.PInt(doc.DegreesRotated) + "', "
                + "'" + POut.PString(doc.ToothNumbers) + "', "
                + "'" + POut.PString(doc.Note) + "', "
                + "'" + POut.PBool(doc.SigIsTopaz) + "', "
                + "'" + POut.PString(doc.Signature) + "',"
                + "'" + POut.PInt(doc.CropX) + "',"
                + "'" + POut.PInt(doc.CropY) + "',"
                + "'" + POut.PInt(doc.CropW) + "',"
                + "'" + POut.PInt(doc.CropH) + "',"
                + "'" + POut.PInt(doc.WindowingMin) + "',"
                + "'" + POut.PInt(doc.WindowingMax) + "')";

            /*+"'"+POut.PDate  (LastAltered)+"', "//will later be used in backups
             +"'"+POut.PBool  (IsDeleted)+"')";//ditto*/
            //MessageBox.Show(cmd.CommandText);
            DataConnection dcon = new DataConnection();

            if (PrefB.RandomKeys)
            {
                dcon.NonQ(command);
            }
            else
            {
                dcon.NonQ(command, true);
                doc.DocNum = dcon.InsertID;
            }
            //If the current filename is just an extension, then assign it a unique name.
            if (doc.FileName == Path.GetExtension(doc.FileName))
            {
                string extension = doc.FileName;
                doc.FileName = "";
                string s = patLF;              //pat.LName+pat.FName;
                for (int i = 0; i < s.Length; i++)
                {
                    if (Char.IsLetter(s, i))
                    {
                        doc.FileName += s.Substring(i, 1);
                    }
                }
                doc.FileName += doc.DocNum.ToString() + extension;            //ensures unique name
                //there is still a slight chance that someone manually added a file with this name, so quick fix:
                command = "SELECT FileName FROM document WHERE WithPat=" + POut.PInt(doc.WithPat);
                DataTable table     = dcon.GetTable(command);
                string[]  usedNames = new string[table.Rows.Count];
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    usedNames[i] = PIn.PString(table.Rows[i][0].ToString());
                }
                while (IsFileNameInList(doc.FileName, usedNames))
                {
                    doc.FileName = "x" + doc.FileName;
                }

                /*Document[] docList=GetAllWithPat(doc.WithPat);
                 * while(IsFileNameInList(doc.FileName,docList)) {
                 *      doc.FileName="x"+doc.FileName;
                 * }*/
                Update(doc);
            }
            DocAttach docAttach = new DocAttach();

            docAttach.DocNum = doc.DocNum;
            docAttach.PatNum = patNum;
            DocAttachB.Insert(docAttach);
            return(doc.DocNum);
        }