Exemplo n.º 1
0
        private DataTable GetInsertTable(string selectQuery, DeviceUpdateInfo updateInfo)
        {
            var tmpTable = controlParser.ReturnInsertTable(selectQuery);
            var row      = tmpTable.Rows[0];

            //Add Add'l info
            row[HistoricalDevicesCols.ChangeType] = updateInfo.ChangeType;
            row[HistoricalDevicesCols.Notes]      = updateInfo.Note;
            row[HistoricalDevicesCols.ActionUser] = NetworkInfo.LocalDomainUser;
            row[HistoricalDevicesCols.DeviceGuid] = currentViewDevice.Guid;
            return(tmpTable);
        }
Exemplo n.º 2
0
        private void UpdateDevice(DeviceUpdateInfo UpdateInfo)
        {
            SetEditMode(false);
            int    affectedRows = 0;
            string selectQuery  = Queries.SelectDeviceByGuid(currentViewDevice.Guid);
            string insertQuery  = Queries.SelectEmptyHistoricalTable;

            using (var trans = DBFactory.GetDatabase().StartTransaction())
                using (var conn = trans.Connection)
                {
                    try
                    {
                        affectedRows += DBFactory.GetDatabase().UpdateTable(selectQuery, GetUpdateTable(selectQuery), trans);
                        affectedRows += DBFactory.GetDatabase().UpdateTable(insertQuery, GetInsertTable(insertQuery, UpdateInfo), trans);

                        if (affectedRows == 2)
                        {
                            trans.Commit();
                            RefreshData();
                            StatusPrompt("Update successful!", Color.Green);
                        }
                        else
                        {
                            trans.Rollback();
                            RefreshData();
                            OtherFunctions.Message("Unsuccessful! The number of affected rows was not what was expected.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, "Unexpected Result", this);
                        }
                    }
                    catch (Exception ex)
                    {
                        trans.Rollback();
                        if (ErrorHandling.ErrHandle(ex, System.Reflection.MethodBase.GetCurrentMethod()))
                        {
                            RefreshData();
                        }
                    }
                }
        }