Exemple #1
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            dataTable.Columns.Add("Number", typeof(int));
            dataTable.Columns.Add("RotationID", typeof(Guid));
            dataTable.Columns.Add("RotationName", typeof(string));
            dataTable.Columns.Add("OperationName", typeof(string));
            dataTable.Columns.Add("TubesBatchName", typeof(string));
            dataTable.Columns.Add("TubesBatchID", typeof(string));
            dataTable.Columns.Add("State", typeof(string));
            dataTable.Columns.Add("PCRTestResult", typeof(string));
            dataTable.Columns.Add("Color", typeof(string));
            dataTable.Columns.Add("logTitle", typeof(string)).DefaultValue = "查看日志";
            dataGrid_view.ItemsSource = dataTable.DefaultView;

            UserInfoController userInfoController = new UserInfoController();
            RoleInfo           userRole           = userInfoController.GetRoleByUserName(SessionInfo.LoginName);
            ExperimentsInfo    experimentInfo     = new WanTai.Controller.HistoryQuery.ExperimentsController().GetExperimentById(experimentId);

            if (SessionInfo.LoginName == experimentInfo.LoginName || (userRole != null && userRole.RoleLevel > 1))
            {
                btnImportPCRResult.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                btnImportPCRResult.Visibility = System.Windows.Visibility.Hidden;
            }

            this.ExperimentName_label.Content = experimentName;
            initDataGrid();
        }
        private void dataGrid_view_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            DataGridCellInfo Cell = ((System.Windows.Controls.DataGrid)(e.Source)).CurrentCell;

            if (Cell.Column.Header.ToString() == "检测结果")
            {
                if (dataTable.Rows[dataGrid_view.SelectedIndex]["PCRTestItemID"] != null && dataTable.Rows[dataGrid_view.SelectedIndex]["PCRTestItemID"] != DBNull.Value)
                {
                    UserInfoController userInfoController = new UserInfoController();
                    RoleInfo           userRole           = userInfoController.GetRoleByUserName(SessionInfo.LoginName);
                    ExperimentsInfo    experimentInfo     = new WanTai.Controller.HistoryQuery.ExperimentsController().GetExperimentById(experimentId);
                    if (SessionInfo.LoginName == experimentInfo.LoginName || (userRole != null && userRole.RoleLevel > 1))
                    {
                        EditPCRTestResult editPCRResult = new EditPCRTestResult();
                        editPCRResult.SetCurrentData(dataTable.Rows[dataGrid_view.SelectedIndex]);
                        editPCRResult.ExperimentID = experimentId;
                        bool dialogResult = (bool)editPCRResult.ShowDialog();
                        if (dialogResult)
                        {
                            loadDataGrid();
                        }
                    }
                    else
                    {
                        ViewPCRTestResult viewPCRResult = new ViewPCRTestResult();
                        viewPCRResult.SetCurrentData(dataTable.Rows[dataGrid_view.SelectedIndex]);
                        viewPCRResult.ShowDialog();
                    }
                }
            }
            else
            {
                return;
            }
        }
        public int GetTotalCount(string experimentName, LogInfoLevelEnum logLevel)
        {
            int count = 0;

            try
            {
                string connectionString = WanTai.Common.Configuration.GetConnectionString();
                ///todo: add control,each role user only can see the specific experiments
                string commandText = "SELECT count(LogID) FROM LogInfo left join ExperimentsInfo on LogInfo.ExperimentID = ExperimentsInfo.ExperimentID";
                commandText = commandText + " WHERE LogInfo.LogLevel = " + (int)logLevel;
                if (!string.IsNullOrEmpty(experimentName))
                {
                    commandText = commandText + " AND ExperimentsInfo.ExperimentName like '%" + experimentName + "%'";
                }
                UserInfoController userInfoController = new UserInfoController();
                RoleInfo           userRole           = userInfoController.GetRoleByUserName(SessionInfo.LoginName);
                if (userInfoController.GetAuthorize(AccessAuthority.LogInfo) == AccessAuthority.All)
                {
                    commandText = commandText + @" AND (LogInfo.LoginName IS NULL or LogInfo.LoginName in 
                    (SELECT LoginName FROM UserInfo u left join roleinfo r on r.RoleName=u.RoleName WHERE r.RoleLevel<=" + userRole.RoleLevel + " ))";
                }
                else
                {
                    commandText = commandText + " AND LogInfo.LoginName='" + SessionInfo.LoginName + "'";
                }
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    using (SqlCommand cmd = new SqlCommand(commandText, conn))
                    {
                        using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
                        {
                            if (reader.Read())
                            {
                                count = (int)reader.GetValue(0);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string errorMessage = e.Message + System.Environment.NewLine + e.StackTrace;
                LogInfoController.AddLogInfo(LogInfoLevelEnum.Error, errorMessage, SessionInfo.LoginName, this.GetType().ToString() + "->GetTotalCount", SessionInfo.ExperimentID);
                throw;
            }

            return(count);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            UserInfoController userInfoController = new UserInfoController();
            RoleInfo           userRole           = userInfoController.GetRoleByUserName(SessionInfo.LoginName);
            ExperimentsInfo    experimentInfo     = new WanTai.Controller.HistoryQuery.ExperimentsController().GetExperimentById(pCRTestResultDataGridUserControl.ExperimentId);

            if (SessionInfo.LoginName == experimentInfo.LoginName || (userRole != null && userRole.RoleLevel > 1))
            {
                deleteRotationPCRTest_button.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                deleteRotationPCRTest_button.Visibility = System.Windows.Visibility.Hidden;
            }
        }
        private void initDataGrid()
        {
            getTotalPageNumber();
            if (current_PageNumber > totalPageNumber)
            {
                current_PageNumber = 1;
            }

            currentPage_textBox.Text = current_PageNumber.ToString();

            int startIndex = (current_PageNumber - 1) * PageSetting.RowNumberInEachPage + 1;
            List <ExperimentsInfo> experimentsList    = controller.GetNextExperiments(experimentName_textBox.Text, experimentDate_datePicker.Text, userName_textBox.Text, startIndex, PageSetting.RowNumberInEachPage, sortColumn, sortDirection);
            UserInfoController     userInfoController = new UserInfoController();
            RoleInfo userRole = userInfoController.GetRoleByUserName(SessionInfo.LoginName);

            foreach (ExperimentsInfo experiment in experimentsList)
            {
                System.Data.DataRow dRow = dataTable.NewRow();
                dRow["Number"]         = startIndex;
                dRow["ExperimentID"]   = experiment.ExperimentID;
                dRow["ExperimentName"] = experiment.ExperimentName;
                dRow["StartTime"]      = experiment.StartTime;
                dRow["EndTime"]        = experiment.EndTime.ToString();
                dRow["LoginName"]      = experiment.LoginName;
                dRow["Remark"]         = experiment.Remark;
                dRow["State"]          = controller.ConvertEnumStatusToText((ExperimentStatus)experiment.State);
                if (startIndex % 2 == 0)
                {
                    dRow["Color"] = WindowCustomizer.alternativeColor;
                }
                else
                {
                    dRow["Color"] = WindowCustomizer.defaultColor;
                }

                if (SessionInfo.LoginName == experiment.LoginName || userRole.RoleLevel > 1)
                {
                    dRow["CanDelete"] = Visibility.Visible.ToString();
                }
                else
                {
                    dRow["CanDelete"] = Visibility.Hidden.ToString();
                }
                dataTable.Rows.Add(dRow);
                startIndex++;
            }
        }
        public void GetNextLogs(string experimentName, int startRowIndex, int rowNumber, LogInfoLevelEnum logLevel, DataTable dataTable, System.Windows.Media.Color alternativeColor, System.Windows.Media.Color defaultColor)
        {
            try
            {
                string connectionString = WanTai.Common.Configuration.GetConnectionString();
                ///todo: add control,each role user only can see the specific experiments
                string commandText = "SELECT * FROM ( SELECT ROW_NUMBER() OVER (ORDER BY CreaterTime desc) AS [ROW_NUMBER], [t0].*, ExperimentsInfo.ExperimentName"
                                     + " FROM [dbo].[LogInfo] AS [t0] left join ExperimentsInfo on [t0].ExperimentID = ExperimentsInfo.ExperimentID "
                                     + " WHERE [t0].LogLevel= " + (int)logLevel + " {0}) AS [t1] WHERE [t1].[ROW_NUMBER] BETWEEN @startIndex AND @endIndex"
                                     + " ORDER BY [ROW_NUMBER]";
                StringBuilder sbWhere = new StringBuilder();
                if (!string.IsNullOrEmpty(experimentName))
                {
                    sbWhere.Append(" AND ExperimentsInfo.ExperimentName like '%" + experimentName + "%'");
                }

                UserInfoController userInfoController = new UserInfoController();
                RoleInfo           userRole           = userInfoController.GetRoleByUserName(SessionInfo.LoginName);
                if (userInfoController.GetAuthorize(AccessAuthority.LogInfo) == AccessAuthority.All)
                {
                    sbWhere.Append(@" AND ([t0].LoginName IS NULL or [t0].LoginName in 
                    (SELECT LoginName FROM UserInfo u left join roleinfo r on r.RoleName=u.RoleName WHERE r.RoleLevel<=" + userRole.RoleLevel + " ))");
                }
                else
                {
                    sbWhere.Append(" AND [t0].LoginName='" + SessionInfo.LoginName + "'");
                }
                commandText = String.Format(commandText, sbWhere.ToString());

                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    using (SqlCommand cmd = new SqlCommand(commandText, conn))
                    {
                        cmd.Parameters.AddWithValue("@startIndex", startRowIndex);
                        cmd.Parameters.AddWithValue("@endIndex", startRowIndex + rowNumber - 1);

                        using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default))
                        {
                            while (reader.Read())
                            {
                                System.Data.DataRow dRow = dataTable.NewRow();
                                dRow["Number"]         = startRowIndex;
                                dRow["LogContent"]     = reader["LogContent"];
                                dRow["Module"]         = reader["Module"];
                                dRow["CreaterTime"]    = reader["CreaterTime"].ToString();
                                dRow["LoginName"]      = reader["LoginName"];
                                dRow["ExperimentName"] = reader["ExperimentName"];
                                if (startRowIndex % 2 == 0)
                                {
                                    dRow["Color"] = alternativeColor;
                                }
                                else
                                {
                                    dRow["Color"] = defaultColor;
                                }

                                dataTable.Rows.Add(dRow);
                                startRowIndex++;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                string errorMessage = e.Message + System.Environment.NewLine + e.StackTrace;
                LogInfoController.AddLogInfo(LogInfoLevelEnum.Error, errorMessage, SessionInfo.LoginName, this.GetType().ToString() + "->GetNextLogs", SessionInfo.ExperimentID);
                throw;
            }
        }