Beispiel #1
0
        ///<summary>Inserts one OrthoChartTabLink into the database.  Provides option to use the existing priKey.</summary>
        public static long Insert(OrthoChartTabLink orthoChartTabLink, bool useExistingPK)
        {
            if (!useExistingPK && PrefC.RandomKeys)
            {
                orthoChartTabLink.OrthoChartTabLinkNum = ReplicationServers.GetKey("orthocharttablink", "OrthoChartTabLinkNum");
            }
            string command = "INSERT INTO orthocharttablink (";

            if (useExistingPK || PrefC.RandomKeys)
            {
                command += "OrthoChartTabLinkNum,";
            }
            command += "ItemOrder,OrthoChartTabNum,DisplayFieldNum,ColumnWidthOverride) VALUES(";
            if (useExistingPK || PrefC.RandomKeys)
            {
                command += POut.Long(orthoChartTabLink.OrthoChartTabLinkNum) + ",";
            }
            command +=
                POut.Int(orthoChartTabLink.ItemOrder) + ","
                + POut.Long(orthoChartTabLink.OrthoChartTabNum) + ","
                + POut.Long(orthoChartTabLink.DisplayFieldNum) + ","
                + POut.Int(orthoChartTabLink.ColumnWidthOverride) + ")";
            if (useExistingPK || PrefC.RandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                orthoChartTabLink.OrthoChartTabLinkNum = Db.NonQ(command, true, "OrthoChartTabLinkNum", "orthoChartTabLink");
            }
            return(orthoChartTabLink.OrthoChartTabLinkNum);
        }
Beispiel #2
0
        ///<summary>Inserts one OrthoChartTabLink into the database.  Provides option to use the existing priKey.  Doesn't use the cache.</summary>
        public static long InsertNoCache(OrthoChartTabLink orthoChartTabLink, bool useExistingPK)
        {
            bool   isRandomKeys = Prefs.GetBoolNoCache(PrefName.RandomPrimaryKeys);
            string command      = "INSERT INTO orthocharttablink (";

            if (!useExistingPK && isRandomKeys)
            {
                orthoChartTabLink.OrthoChartTabLinkNum = ReplicationServers.GetKeyNoCache("orthocharttablink", "OrthoChartTabLinkNum");
            }
            if (isRandomKeys || useExistingPK)
            {
                command += "OrthoChartTabLinkNum,";
            }
            command += "ItemOrder,OrthoChartTabNum,DisplayFieldNum,ColumnWidthOverride) VALUES(";
            if (isRandomKeys || useExistingPK)
            {
                command += POut.Long(orthoChartTabLink.OrthoChartTabLinkNum) + ",";
            }
            command +=
                POut.Int(orthoChartTabLink.ItemOrder) + ","
                + POut.Long(orthoChartTabLink.OrthoChartTabNum) + ","
                + POut.Long(orthoChartTabLink.DisplayFieldNum) + ","
                + POut.Int(orthoChartTabLink.ColumnWidthOverride) + ")";
            if (useExistingPK || isRandomKeys)
            {
                Db.NonQ(command);
            }
            else
            {
                orthoChartTabLink.OrthoChartTabLinkNum = Db.NonQ(command, true, "OrthoChartTabLinkNum", "orthoChartTabLink");
            }
            return(orthoChartTabLink.OrthoChartTabLinkNum);
        }
        private void gridMain_CellDoubleClick(object sender, ODGridClickEventArgs e)
        {
            DisplayField df = (DisplayField)gridMain.ListGridRows[e.Row].Tag;
            //OrthoChartTabFields orthoChartTabFields=GetSelectedFields();
            long orthoChartTabNum     = _listOrthoChartTabs[comboOrthoChartTabs.SelectedIndex].OrthoChartTabNum;
            OrthoChartTabLink linkCur = _listOrthoChartTabLinks.FirstOrDefault(x => x.OrthoChartTabNum == orthoChartTabNum &&
                                                                               x.DisplayFieldNum == df.DisplayFieldNum);
            bool isAddingNewLink = false;

            if (linkCur == null)           //Avoid thrown exception in FormDisplayFieldOrthoEdit_Load(...) when adding a new link and then attempting to edit it.
            {
                isAddingNewLink = true;
                linkCur         = new OrthoChartTabLink()
                {
                    OrthoChartTabNum = orthoChartTabNum,
                    //ItemOrder will be set when FormDisplayFieldsOrthoChart closes/syncs.
                    DisplayFieldNum     = df.DisplayFieldNum,
                    ColumnWidthOverride = 0,
                };
            }
            FormDisplayFieldOrthoEdit form = new FormDisplayFieldOrthoEdit(df, GetAllFields(), linkCur);

            form.ShowDialog();
            if (form.DialogResult != DialogResult.OK)
            {
                return;
            }
            if (isAddingNewLink)             //Do not add new link to list if user clicks cancel because we want to act like nothing happened
            {
                _listOrthoChartTabLinks.Add(linkCur);
            }
            FillGrids();
            changed = true;
        }
 ///<summary>Inserts one OrthoChartTabLink into the database.  Returns the new priKey.</summary>
 public static long Insert(OrthoChartTabLink orthoChartTabLink)
 {
     if (DataConnection.DBtype == DatabaseType.Oracle)
     {
         orthoChartTabLink.OrthoChartTabLinkNum = DbHelper.GetNextOracleKey("orthocharttablink", "OrthoChartTabLinkNum");
         int loopcount = 0;
         while (loopcount < 100)
         {
             try {
                 return(Insert(orthoChartTabLink, true));
             }
             catch (Oracle.ManagedDataAccess.Client.OracleException ex) {
                 if (ex.Number == 1 && ex.Message.ToLower().Contains("unique constraint") && ex.Message.ToLower().Contains("violated"))
                 {
                     orthoChartTabLink.OrthoChartTabLinkNum++;
                     loopcount++;
                 }
                 else
                 {
                     throw ex;
                 }
             }
         }
         throw new ApplicationException("Insert failed.  Could not generate primary key.");
     }
     else
     {
         return(Insert(orthoChartTabLink, false));
     }
 }
        ///<summary>Updates one OrthoChartTabLink in the database.</summary>
        public static void Update(OrthoChartTabLink orthoChartTabLink)
        {
            string command = "UPDATE orthocharttablink SET "
                             + "ItemOrder           =  " + POut.Int(orthoChartTabLink.ItemOrder) + ", "
                             + "OrthoChartTabNum    =  " + POut.Long(orthoChartTabLink.OrthoChartTabNum) + ", "
                             + "DisplayFieldNum     =  " + POut.Long(orthoChartTabLink.DisplayFieldNum) + " "
                             + "WHERE OrthoChartTabLinkNum = " + POut.Long(orthoChartTabLink.OrthoChartTabLinkNum);

            Db.NonQ(command);
        }
 public FormDisplayFieldOrthoEdit(DisplayField fieldCur, List <DisplayField> listAllFields, OrthoChartTabLink tabLinkCur = null)
 {
     _fieldCur      = fieldCur;
     _listAllFields = listAllFields;
     _tabLinkCur    = tabLinkCur;
     //
     // Required for Windows Form Designer support
     //
     InitializeComponent();
     Lan.F(this);
 }
 ///<summary>Inserts one OrthoChartTabLink into the database.  Returns the new priKey.  Doesn't use the cache.</summary>
 public static long InsertNoCache(OrthoChartTabLink orthoChartTabLink)
 {
     if (DataConnection.DBtype == DatabaseType.MySql)
     {
         return(InsertNoCache(orthoChartTabLink, false));
     }
     else
     {
         if (DataConnection.DBtype == DatabaseType.Oracle)
         {
             orthoChartTabLink.OrthoChartTabLinkNum = DbHelper.GetNextOracleKey("orthocharttablink", "OrthoChartTabLinkNum");                  //Cacheless method
         }
         return(InsertNoCache(orthoChartTabLink, true));
     }
 }
        ///<summary>Converts a DataTable to a list of objects.</summary>
        public static List <OrthoChartTabLink> TableToList(DataTable table)
        {
            List <OrthoChartTabLink> retVal = new List <OrthoChartTabLink>();
            OrthoChartTabLink        orthoChartTabLink;

            foreach (DataRow row in table.Rows)
            {
                orthoChartTabLink = new OrthoChartTabLink();
                orthoChartTabLink.OrthoChartTabLinkNum = PIn.Long(row["OrthoChartTabLinkNum"].ToString());
                orthoChartTabLink.ItemOrder            = PIn.Int(row["ItemOrder"].ToString());
                orthoChartTabLink.OrthoChartTabNum     = PIn.Long(row["OrthoChartTabNum"].ToString());
                orthoChartTabLink.DisplayFieldNum      = PIn.Long(row["DisplayFieldNum"].ToString());
                retVal.Add(orthoChartTabLink);
            }
            return(retVal);
        }
 ///<summary>Returns true if Update(OrthoChartTabLink,OrthoChartTabLink) would make changes to the database.
 ///Does not make any changes to the database and can be called before remoting role is checked.</summary>
 public static bool UpdateComparison(OrthoChartTabLink orthoChartTabLink, OrthoChartTabLink oldOrthoChartTabLink)
 {
     if (orthoChartTabLink.ItemOrder != oldOrthoChartTabLink.ItemOrder)
     {
         return(true);
     }
     if (orthoChartTabLink.OrthoChartTabNum != oldOrthoChartTabLink.OrthoChartTabNum)
     {
         return(true);
     }
     if (orthoChartTabLink.DisplayFieldNum != oldOrthoChartTabLink.DisplayFieldNum)
     {
         return(true);
     }
     return(false);
 }
Beispiel #10
0
        ///<summary>Updates one OrthoChartTabLink in the database.  Uses an old object to compare to, and only alters changed fields.  This prevents collisions and concurrency problems in heavily used tables.  Returns true if an update occurred.</summary>
        public static bool Update(OrthoChartTabLink orthoChartTabLink, OrthoChartTabLink oldOrthoChartTabLink)
        {
            string command = "";

            if (orthoChartTabLink.ItemOrder != oldOrthoChartTabLink.ItemOrder)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ItemOrder = " + POut.Int(orthoChartTabLink.ItemOrder) + "";
            }
            if (orthoChartTabLink.OrthoChartTabNum != oldOrthoChartTabLink.OrthoChartTabNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "OrthoChartTabNum = " + POut.Long(orthoChartTabLink.OrthoChartTabNum) + "";
            }
            if (orthoChartTabLink.DisplayFieldNum != oldOrthoChartTabLink.DisplayFieldNum)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "DisplayFieldNum = " + POut.Long(orthoChartTabLink.DisplayFieldNum) + "";
            }
            if (orthoChartTabLink.ColumnWidthOverride != oldOrthoChartTabLink.ColumnWidthOverride)
            {
                if (command != "")
                {
                    command += ",";
                }
                command += "ColumnWidthOverride = " + POut.Int(orthoChartTabLink.ColumnWidthOverride) + "";
            }
            if (command == "")
            {
                return(false);
            }
            command = "UPDATE orthocharttablink SET " + command
                      + " WHERE OrthoChartTabLinkNum = " + POut.Long(orthoChartTabLink.OrthoChartTabLinkNum);
            Db.NonQ(command);
            return(true);
        }
        private void FillGrids()
        {
            labelCategory.Text = _listOrthoChartTabs[0].TabName;          //Placed here so that Up/Down buttons will affect the label text.
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            GridColumn col;

            col = new GridColumn(Lan.g("FormDisplayFields", "Description"), 200);
            gridMain.ListGridColumns.Add(col);
            col = new GridColumn(Lan.g("FormDisplayFields", "Width"), 80);
            gridMain.ListGridColumns.Add(col);
            gridMain.ListGridRows.Clear();
            OrthoChartTabFields      orthoChartTabFields = GetSelectedFields();
            List <OrthoChartTabLink> listLinks           = _listOrthoChartTabLinks.FindAll(x => x.OrthoChartTabNum == orthoChartTabFields.OrthoChartTab.OrthoChartTabNum);

            _listAvailableFields = GetAllFields();
            for (int i = 0; i < orthoChartTabFields.ListDisplayFields.Count; i++)
            {
                DisplayField df = orthoChartTabFields.ListDisplayFields[i];
                _listAvailableFields.Remove(df);
                GridRow row = new GridRow();
                row.Tag = df;
                string description = df.Description;
                if (!string.IsNullOrEmpty(df.DescriptionOverride))
                {
                    description += " (" + df.DescriptionOverride + ")";
                }
                row.Cells.Add(description);
                int columnWidth        = df.ColumnWidth;
                OrthoChartTabLink link = listLinks.FirstOrDefault(x => x.DisplayFieldNum == df.DisplayFieldNum);
                if (link != null && link.ColumnWidthOverride > 0)
                {
                    columnWidth = link.ColumnWidthOverride;
                }
                row.Cells.Add(POut.Int(columnWidth));
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
            listAvailable.Items.Clear();
            for (int i = 0; i < _listAvailableFields.Count; i++)
            {
                listAvailable.Items.Add(_listAvailableFields[i].Description);
            }
        }
Beispiel #12
0
 ///<summary>Inserts one OrthoChartTabLink into the database.  Returns the new priKey.</summary>
 public static long Insert(OrthoChartTabLink orthoChartTabLink)
 {
     return(Insert(orthoChartTabLink, false));
 }
Beispiel #13
0
        private void butOK_Click(object sender, EventArgs e)
        {
            OrthoChartTabFields orphanedTab = _listTabDisplayFields.Find(x => x.OrthoChartTab == null);

            //No need to do anything if nothing changed and there are no 'orphaned' display fields to delete.
            if (!changed && (orphanedTab != null && orphanedTab.ListDisplayFields.All(x => x.DisplayFieldNum == 0)))
            {
                DialogResult = DialogResult.OK;
                return;
            }
            //Get all fields associated to a tab in order to sync with the database later.
            List <DisplayField> listAllFields = GetAllFields(false);

            if (listAllFields.Count(x => x.InternalName == "Signature") > 1)
            {
                MessageBox.Show(Lan.g(this, "Only one display field can be a signature field.  Fields that have the signature field checkbox checked:") + " "
                                + string.Join(", ", listAllFields.FindAll(x => x.InternalName == "Signature").Select(x => x.Description)));
                return;
            }
            //Ensure all new displayfields have a primary key so that tab links can be created below.  Update existing displayfields.
            foreach (DisplayField df in listAllFields)
            {
                if (df.DisplayFieldNum == 0)               //New displayfield
                {
                    DisplayFields.Insert(df);
                }
                else                  //Existing displayfield.
                {
                    DisplayFields.Update(df);
                }
            }
            DataValid.SetInvalid(InvalidType.DisplayFields);
            //Remove tab links which no longer exist.  Update tab link item order for tab links which still belong to the same tab.
            List <OrthoChartTabLink> listOrthoChartTabLinks = OrthoChartTabLinks.GetDeepCopy();

            for (int i = listOrthoChartTabLinks.Count - 1; i >= 0; i--)
            {
                OrthoChartTabLink   orthoChartTabLink   = listOrthoChartTabLinks[i];
                OrthoChartTabFields orthoChartTabFields = _listTabDisplayFields.FirstOrDefault(
                    x => x.OrthoChartTab != null && x.OrthoChartTab.OrthoChartTabNum == orthoChartTabLink.OrthoChartTabNum);
                if (orthoChartTabFields == null)
                {
                    continue;                    //The tab was hidden and we are going to leave the tab links alone.
                }
                DisplayField df = orthoChartTabFields.ListDisplayFields.FirstOrDefault(x => x.DisplayFieldNum == orthoChartTabLink.DisplayFieldNum);
                if (df == null)               //The tab link no longer exists (was removed).
                {
                    listOrthoChartTabLinks.RemoveAt(i);
                }
                else                  //The tab link still exists.  Update the link with any changes.
                {
                    orthoChartTabLink.ItemOrder = orthoChartTabFields.ListDisplayFields.IndexOf(df);
                }
            }
            //Add new tab links which were just created.
            foreach (OrthoChartTabFields orthoChartTabFields in _listTabDisplayFields)
            {
                //Skip "orphaned" fields that just show in the available fields list.
                if (orthoChartTabFields.OrthoChartTab == null)
                {
                    continue;
                }
                foreach (DisplayField df in orthoChartTabFields.ListDisplayFields)
                {
                    OrthoChartTabLink orthoChartTabLink = listOrthoChartTabLinks.FirstOrDefault(
                        x => x.OrthoChartTabNum == orthoChartTabFields.OrthoChartTab.OrthoChartTabNum && x.DisplayFieldNum == df.DisplayFieldNum);
                    if (orthoChartTabLink != null)
                    {
                        continue;
                    }
                    orthoChartTabLink                  = new OrthoChartTabLink();
                    orthoChartTabLink.ItemOrder        = orthoChartTabFields.ListDisplayFields.IndexOf(df);
                    orthoChartTabLink.OrthoChartTabNum = orthoChartTabFields.OrthoChartTab.OrthoChartTabNum;
                    orthoChartTabLink.DisplayFieldNum  = df.DisplayFieldNum;
                    listOrthoChartTabLinks.Add(orthoChartTabLink);
                }
            }
            //Delete any display fields that have a valid PK and are in the "orphaned" list.
            //This is fine to do because the field will show back up in the available list of display fields if a patient is still using the field.
            //This is because we link the ortho chart display fields by their name instead of by their PK.
            if (orphanedTab != null)           //An orphaned list actually exists.
            //Look for any display fields that have a valid PK (this means the user removed this field from every tab and we need to delete it).
            {
                List <DisplayField> listFieldsToDelete = orphanedTab.ListDisplayFields.FindAll(x => x.DisplayFieldNum != 0);
                listFieldsToDelete.ForEach(x => DisplayFields.Delete(x.DisplayFieldNum));
            }
            OrthoChartTabLinks.Sync(listOrthoChartTabLinks, OrthoChartTabLinks.GetDeepCopy());
            DataValid.SetInvalid(InvalidType.OrthoChartTabs);
            DialogResult = DialogResult.OK;
        }