1

我一直很难找到一个以适当方式展示教室的考勤表。我的数据库中有一个出勤表,我可以很容易地使用来自一个教室的数据来显示它,但它的显示方式看起来就像您直接在数据库中浏览到出勤表时的样子。

通过展示我的工作可能更容易解释:

我有以下课程:

实际的课堂课程或课程:

public class Course
{
    public int CourseID { get; set; }
    public string Title { get; set; }
    public int AttendanceDate { get; set;}
    public virtual ICollection<Enrollment> Enrollments { get; set; } // allows Students to be enrolled in a Course
    etc. . .
}

我的学生们:

public class Student
{
    public int StudentID { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Enrollment> Enrollments { get; set; } // allows Student to be enrolled in a Course
    etc. . .
}

将学生与课程联系起来的实体:

public class Enrollment
{
    public int EnrollmentID { get; set; }
    public int CourseID { get; set; }
    public int StudentID { get; set; }
    public virtual Course Course { get; set; }
    public virtual Student Student { get; set; }
}

出勤数据:

public class Attendance
{
    public int AttendanceID { get; set; }
    public int CourseID { get; set; }
    public int StudentID { get; set; }
    public int AttendanceDay { get; set; }  // used to set how many days people are supposed to attend this Course (each course has a different length, some are 10 day courses, some are 3, etc.)
    public bool Present { get; set; }  // absent or present (set to absent by default)
    public virtual Course Course { get; set; }
    public virtual Student Student { get; set; }
}

我的项目流程让教师创建课程供学生注册。当学生注册课程时,所有必要的出勤数据都会以默认值(每天都缺席)输入到出勤数据库表中:

for (int i = 0; i < course.AttendingDays; i++)
{
    Attendance newAttendance = new Attendance
    {
        CourseID = course.CourseID,
        StudentID = thisStudent.StudentID,
        AttendanceDay = i + 1,
        Present = false
    };
    db.Attendance.Add(newAttendance);
    db.Save();
}

所以我有一个包含一堆考勤数据的数据库表,我无法让它在屏幕上正确显示,排序类似于:

第一天出勤 | 2 | 3 | 4 | 5 |

学生 1 缺席 缺席 缺席 缺席 缺席

Student2 缺席 缺席 缺席 缺席

Student3 缺席 缺席 缺席 缺席

希望你能读到。. . 我认为这是一个非常标准的考勤表布局。

我尝试使用 Group By 对数据进行排序:

var model = from s in db.Attendance
                             where s.CourseID == 4
                             group s.AttendanceDay by s.StudentID into t
                             select new
                             {
                                 StudentID = t.Key,
                                 Days = t.OrderBy(x => x)
                             };
        return View(model);

它返回一个匿名类型的 IEnumerable(如果我理解正确的话),但我似乎无法让这些数据做任何事情。如果我使用“更简单”的表生成器(并且不要尝试按 AttendanceDay 编号分组),我得到的出勤表数据就好了,但它的排序就像您查看出勤的实际数据库表时一样,不是很如果您希望教师阅读和编辑信息,这很有用。

我想我需要一个合适的 ViewModel 来调整匿名类型格式的 IEnumerable 中的传入考勤数据,然后是一个适当显示该 ViewModel 的视图。. . 但我不确定我将如何处理该过程。

任何帮助,将不胜感激。谢谢你。

更新:

我开始认为我需要利用“交叉表报告”/“数据透视”并使用如下内容:http ://linqlib.codeplex.com/wikipage?title=Pivot&referringTitle=Home

任何指针?

更新 2:

使用以下接受的答案几乎完全解决了,这是我当前的控制器:

        // Generates list of Attendances specifically for current Course
        var attendanceItems = db.Attendance.Where(s => s.CourseID == id);
        List<Attendance> attendanceItemsList = attendanceItems.ToList();
        // End of generating list of Attendances


        // CURRENT PROBLEM AREA - INCOMPLETE
        var student = attendanceItemsList.Select(a => a.Student).Distinct()/*.OrderBy(a => a)*/;  // This works for adding one student, Cannot use OrderBy in its current state - how can I properly order by name?  (right now it will order by id I believe)
        List<Student> StudentList = student.ToList();;

        //
        // Generates list of AttendingDays specifically for current Course
        Course course = db.Courses.FirstOrDefault(p => p.CourseID == id);
        List<int> attDayList = new List<int>();
        for (int i = 0; i < course.AttendingDays; i++)
        {
            attDayList.Add(i + 1);
        };
        // End of generating list of AttendingDays

        AttendanceReportViewModel model = new AttendanceReportViewModel
        {
            AttendanceDays = attDayList,
            Students = StudentList,
            Attendances = attendanceItemsList,
        };
        return View(model);
4

2 回答 2

3

我认为您应该考虑创建一个包含天数列表、学生列表和出勤条目列表的 ViewModel,然后简单地遍历学生并在其中遍历出勤天数,然后显示每个人的出勤记录。

所以 ViewModel 看起来像这样:


public class AttendanceReportViewModel
{
    public List<int> AttendanceDays { get; set; }
    public List<Student> Students { get; set; }
    public List<Attendance> Attendances { get; set; }

    public string IsPresent(Student student, int attendanceDay)
    {
         return Attendances.Single(a => a.StudentID == student.ID && a.AttendanceDay == attendanceDay).Present ? "present" : "absent";
    }
}

确保按照您希望它们出现的方式对所有项目进行排序,但这是简单的 OrderBy 东西。还要确保只加载相关课程的出勤率,并将任何课程数据添加到要显示的视图模型中。

然后在您的视图中像这样迭代:


<table>
    <thead>
        <tr>
            <th>Attendance Day</th>
            @foreach (var attendanceDay in Model.AttendanceDays)
            {
                <th>@attendanceDay</th>
            }
        </tr>
    <thead>
    <tbody>
        @foreach (var student in Model.Students)
        {
            <tr>
                <td>@student.Name</td>
                @foreach (var attendanceDay in Model.AttendanceDays)
                {
                    <td>@Model.IsPresent(student, attendanceDay)</td>
                }
            </tr>
        }
    </tbody>
}

刚刚为你整理了这个,所以甚至不确定我的确切代码是否可以编译,但我希望它能给你一个好的起点。显然,应该对表格应用一些样式等。

编辑1:

要将数据加载到视图模型中,您只需在控制器中执行此操作(从技术上讲,最终这应该在存储库中,甚至可能是服务层)


var viewModel = new AttendanceReportViewModel();

viewModel.AttendanceDays = db.Attendance.Select(a => a.AttendanceDay).Distinct().OrderBy(a => a)
...

我还应该注意到,当然您也可以只将出勤数据加载到视图模型中,然后根据这些数据在 ViewModel 中生成 AttendanceDays 和 Students 属性。我暂时避免了这种情况,因为您很可能也需要学生数据。

编辑 2

对于学生来说,您希望所有学生都参加课程几乎是一样的,但是由于您已经预先初始化了所有天的出勤数据,您可以这样做:


var viewModel = new AttendanceReportViewModel();

viewModel.AttendanceDays = db.Attendance.Select(a => a.AttendanceDay).Distinct().OrderBy(a => a);
viewModel.Students = db.Attendance.Select(a => a.Student).Distinct().OrderBy(s => s.Name);

或者,您可以像这样从 Enrollment 表中加载此信息:


viewModel.Students = db.Enrollment.Where(e => e.CourseID == courseID).Select(e => e.Student).OrderBy(s => s.Name);

请注意,我假设注册表上的课程和学生 ID 之间存在唯一约束,并且该 courseID 是您生成出勤报告的内容。此外,您的 Enrollment 表中有 Course 映射到上面的 Student,我认为这是不正确的。

于 2012-05-16T02:05:14.850 回答
0
        CREATE PROCEDURE [dbo].[SP_S_GetDaywise_EmpTotalDuties_AttendanceRegister]
        (
        @Month int=null,
        @Year int=null,
        @SCode bigint=null
        )
        AS
            /**Creating TempAllAttendance**/
            CREATE TABLE #TempAllAttendance
            (RecId bigint IDENTITY(1,1),EmpCode BIGINT,Duties FLOAT,AttDay INT, DESIGNATION NVARCHAR(250))
            /**Creating TempAllAttendance**/
            
            /**Creating SumAttendance**/
            CREATE TABLE #SumAttendance
            (Total FLOAT)
            /**Creating SumAttendance**/
            
            
            DECLARE @TotalDuties FLOAT=null
            
         BEGIN
            
            
            
            SET @TotalDuties=(SELECT SUM(ISNULL(Duties, 0)) AS Total FROM tbl_Attendance WHERE ([Month] = @Month) AND ([Year] = @Year) AND (SCode = @SCode))        
            
            INSERT INTO #SumAttendance
            (Total)VALUES(@TotalDuties)
            
            INSERT INTO #TempAllAttendance(EmpCode,Duties,AttDay,DESIGNATION)
            (
                SELECT EmpCode, SUM(ISNULL(Duty1, 0)) AS Duties, DAY(AttendanceDate) AS AttDay,DESIGNATION
                FROM  tbl_Attendance
                WHERE ([Month] = @Month) AND ([Year] = @Year) AND (SCode = @Code)
                GROUP BY EmpCode, AttendanceDate,DESIGNATION 
                
            )   
            /**This is used to get date wise & Swise Total duty When Records Not Saved In tbl_SiteWiseEmployee_TotalAttendance**/
            /**This is used to get date wise & Sise Total duty When Records Saved In tbl_SiteWiseEmployee_TotalAttendance**/
        
       
            /**This is used to get date wise & Swise Total duty**/
                SELECT * FROM #TempAllAttendance
            /**This is used to get date wise & Sitewise Total duty**/
            /**This is used to get date wise Total  duty**/
            SELECT EmpCode,SUM(ISNULL(Duties, 0)) AS Duties,AttDay,DESIGNATION FROM #TempAllAttendance
            GROUP BY EmpCode, AttDay,EmpCode,DESIGNATION
            /**This is used to get Employee SumAttendance**/
            SELECT SUM(Duties) AS Duties,DAY(AttendanceDate) AS AttDay FROM tbl_Attendance
            WHERE (SiteCode = @SCode) AND ([Month] = @Month) AND ([Year] = @Year)  GROUP BY AttendanceDate
            
            /**This is used to get Employee SumAttendance**/
            SELECT * FROM #SumAttendance
            /**This is used to get date wise & Sitewise Total duty AS P**/
                --SELECT RecId,EmpCode,'P' AS Duties,AttDay FROM #TempAllAttendance
                
            SELECT EmpCode,'P' AS Duties,AttDay FROM #TempAllAttendance
            GROUP BY EmpCode, AttDay
            /**This is used to get date wise & Swise Total duty  AS P**/
            
            DROP TABLE #SumAttendance
            DROP TABLE #TempAllAttendance
        END 
    
    
    
    
        private void STotalEmployeeAttendenceReportAsDuty()
        {
            #region  For Displaying page Header region
            lblMonthId.Value = Request.QueryString["Month"];
            lblMonthName.Value = Request.QueryString["MonthName"];
            lblYear.Value = Request.QueryString["year"];
            lblSCode.Value = Request.QueryString["SCode"];
            lblgvSName.Value = Request.QueryString["SName"];
            lblMonth.InnerText = lblMonthName.Value;
            lblYears.InnerText = lblYear.Value;
            lblSName.InnerText = lblgvSiName.Value + "-" + lblSCode.Value;
            #endregion
    
            #region Get SWise Employee Detail
            siAttndncPL.SiteCode = lblSiteCode.Value;
            sAttndncPL.Month = lblMonthId.Value;
            siAttndncPL.Year = lblYear.Value;
            DataTable EmpDt = siteAttndncBL.GetEmployeeNameWithTotalDutiesBySit(siteAttndncPL);
            #endregion
    
            #region Making TempTable.
            DataTable dt = new DataTable();
            DataColumn dc = new DataColumn();
            dc.ColumnName = "EmpCode";
            dt.Columns.Add(dc);
            dc = new DataColumn();
            dc.ColumnName = "EmpName";
            dt.Columns.Add(dc);
            dc = new DataColumn();
            dc.ColumnName = "Designation";
            dt.Columns.Add(dc);
            /**Some Table**/
            DataTable dtdayDuties = new DataTable();
            DataTable dtEmpDayDuties = new DataTable();
            DataTable dtEmpDutiesAsP = new DataTable();
            DataTable dtSumDuty = new DataTable();
            /**Some Region**/
            #endregion
    
            #region Get No Of Days In Month..
            int DaysCount = DateTime.DaysInMonth(Convert.ToInt32(Request.QueryString["Year"]), Convert.ToInt32(Request.QueryString["Month"]));
            #endregion
    
            #region This will dispaly date value on grid header
            for (int i = 1; i <= 9; i++)
            {
                dc = new DataColumn();
                dc.ColumnName = "0" + i.ToString();
                dt.Columns.Add(dc);
            }
            for (int i = 10; i <= DaysCount; i++)
            {
                dc = new DataColumn();
                dc.ColumnName = i.ToString();
                dt.Columns.Add(dc);
            }
            dc = new DataColumn();
            dc.ColumnName = "Total";
            dt.Columns.Add(dc);
            #endregion
    
            #region   /*Adding Site Name Row in Grid View*/
            for (int j = 0; j < EmpDt.Rows.Count + 1; j++)
            {
                DataRow dtrow = dt.NewRow();
                if (j < EmpDt.Rows.Count)
                {
                    dtrow[0] = EmpDt.Rows[j][0];/**this Row Cells EmpCode**/
                    string EmpCode = EmpDt.Rows[j][0].ToString();
                    // lblEmpCode = EmpDt.Rows[j][0].ToString();
                    dtrow[1] = EmpDt.Rows[j][1];/**this Row Cells EmpName**/
                    dtrow[2] = EmpDt.Rows[j][2];/**this Row Cells DESsgName**/
                    dtrow[DaysCount + 3] = EmpDt.Rows[j][3];/**this Row Cells Duties **/
    
    
                    #region Get EmployeeWise Total Duties.
                    siteAttndncPL.SiteCode = lblSiteCode.Value;
                    siteAttndncPL.Month = lblMonthId.Value;
                    siteAttndncPL.Year = lblYear.Value;
                    DataSet ds = siteAttndncBL.GetEmployeeDayWiseAttendenceBySCode_WOPHD(siteAttndncPL);
                    dtEmpDutiesAsP = ds.Tables["tbl_GetEmpTotalAttendanceOfDayAsP"];/*getting Site Duties as P*/
                    dtEmpDayDuties = ds.Tables["tbl_GetEmpTotalAttendanceOfDay"];
                    dtdayDuties = ds.Tables["tbl_SumOfAllEmpDayWiseDuties"];
                    dtSumDuty = ds.Tables["tbl_TotalSumOfAllEmpAttendance"];
                    TotalSumDuties = Convert.ToDouble(dtSumDuty.Rows[0]["Total"].ToString());
                    #endregion
                }
                if (j == EmpDt.Rows.Count)
                {
                    #region Count Total Duties.
                    dtrow[2] = "Total Duties";
                    dtrow[DaysCount + 3] = TotalSumDuties;/**Sum Of All Main Attendance**/
                    #endregion
                }
                dt.Rows.Add(dtrow);
            }
            #endregion
    
            /**Fill Day Wise Attendance In Gridview**/
            #region Day Wise Attendance fill In Gridview..
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (i < dt.Rows.Count - 1)
                {
                    for (int j = 3; j < dt.Columns.Count; j++)
                    {
                        foreach (DataRow dtrows in dtEmpDayDuties.Rows)
                        {
                            /*Matching Emp Code*/
                            if (dt.Rows[i][0].ToString() == dtrows[0].ToString())
                            {
                                /*Matching Emp Category */
                                if (dt.Rows[i][2].ToString() == dtrows[3].ToString())
                                {
                                    TextBox txtDuty = new TextBox();
                                    txtDuty.Text = dt.Columns[j].ColumnName.ToString();
                                    txtDuty.Text = dtrows[2].ToString();
                                    /*Matching Date*/
                                    if (Convert.ToString(j - 2) == dtrows[2].ToString())
                                    {
                                        dt.Rows[i][j] = dtrows[1].ToString(); /*Filling  Days wise duty*/
                                    }
                                }
                                /*Matching Emp Category */
                            }
                        }
                    }
                }
                if (i == dt.Rows.Count - 1)
                {
                    for (int j = 3; j < dt.Columns.Count; j++)
                    {
                        foreach (DataRow dtrows in dtdayDuties.Rows)
                        {
                            TextBox txtDuty = new TextBox();
                            txtDuty.Text = dt.Columns[j].ColumnName.ToString();
                            txtDuty.Text = dtrows[1].ToString();
                            if (Convert.ToString(j - 2) == dtrows[1].ToString())
                            {
                                dt.Rows[i][j] = dtrows[0].ToString();
    
                            }
                        }
                    }
                }
            }
    
    
    
            #endregion
            /**Fill Day Wise Attendance In Gridview**/
    
            #region Binding Grid
            grdSWiseEmpAttendance.DataSource = dt;
            grdSWiseEmpAttendance.DataBind();
            #endregion Binding Grid
            ViewState["tbldata"] = dt;/*used For Saving Employee Monthly Attendance*/
            Session["reportdata"] = dt;/*used For Printing Employee Monthly Attendance*/
            lblNoOfEmp.InnerText = (grdSWiseEmpAttendance.Rows.Count - 1).ToString();
    
    
        }
    
        void Page_Init(object obj, EventArgs e)
        {
            int days = DateTime.DaysInMonth(Convert.ToInt32(Request.QueryString["Year"]), Convert.ToInt32(Request.QueryString["Month"]));
            int dtinc = 0;
            for (int rowcnt = 0; rowcnt < days + 4; rowcnt++)
            {
                if (rowcnt == 0)
                {
                    BoundField nameColumn = new BoundField();
                    nameColumn.DataField = "EmpCode";
                    nameColumn.HeaderText = "EmpCode";
                    grdSiteWiseEmpAttendance.Columns.Add(nameColumn);
    
                }
    
                else if (rowcnt == 1)
                {
                    BoundField nameColumn = new BoundField();
                    nameColumn.DataField = "EmpName";
                    nameColumn.HeaderText = "EmpName";
                    grdSiteWiseEmpAttendance.Columns.Add(nameColumn);
    
                }
                else if (rowcnt == 2)
                {
                    BoundField nameColumn = new BoundField();
                    nameColumn.DataField = "DESIGNATION";
                    nameColumn.HeaderText = "DESIGNATION";
                    grdSiteWiseEmpAttendance.Columns.Add(nameColumn);
    
                }
                else if (rowcnt == days + 3)
                {
                    BoundField nameColumn = new BoundField();
                    nameColumn.DataField = "Total";
                    nameColumn.HeaderText = "Total";
                    grdSiteWiseEmpAttendance.Columns.Add(nameColumn);
                    nameColumn.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
                }
                else
                {
                    dtinc = dtinc + 1;
                    string formet = "00";
                    TemplateField bfield = new TemplateField();
                    /**Initalize the DataField value**/
                    bfield.HeaderTemplate = new GridViewTemplate2(ListItemType.Header, Convert.ToString(dtinc.ToString(formet)));
                    /**Initialize the HeaderText field value**/
                    bfield.ItemTemplate = new GridViewTemplate2(ListItemType.Item, Convert.ToString(dtinc.ToString(formet)));
                    /**Add the newly created bound field to the GridView**/
                    grdSEmpAttendance.Columns.Add(bfield);
                }
            }
        }
        
    
    
    <div class="row">
                                                        <div class="col-lg-12">
                                                            <div class="table-responsive">
                                                                <asp:GridView ID="grdSiEmpAttendance" CssClass="table table-small-font table-bordered table-striped" Font-Size="Smaller" EmptyDataRowStyle-ForeColor="#cc0000" HeaderStyle-Font-Size="10" HeaderStyle-Font-Names="Arial" HeaderStyle-Font-Italic="true" runat="server" AutoGenerateColumns="false"
                                                                    BackColor="#f0f5f5" HeaderStyle-ForeColor="#990000">
    
                                                                    <Columns>
                                                                    </Columns>
                                                                    <HeaderStyle HorizontalAlign="Justify" VerticalAlign="Top"
                                                                        Font-Bold="true" />
                                                                    <RowStyle Font-Size="Small" Height="1" ForeColor="#000000" Font-Italic="true" />
                                                                </asp:GridView>
                                                            </div>
                                                        </div>
    
                                                    </div>








using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI;

public class GridViewTemplate2 : ITemplate
{
    /**A variable to hold the type of ListItemType**/
         ListItemType _templateType;

    /**A variable to hold the column name**/
         string _columnName;

    /**Constructor where we define the template type and column Name**/
         public GridViewTemplate2(ListItemType type, string colname)
    {

        _templateType = type; /*Stores the template type*/
         _columnName = colname;/*Stores the column name*/
    }

    void ITemplate.InstantiateIn(System.Web.UI.Control container)
    {
        switch (_templateType)
        {
            #region For Use TemplateFields.

            case ListItemType.Header:
                /*Create a New Label control and add it to the container*/
                Label lbl = new Label();/*Allocates the new label object*/
                
                lbl.Text = _columnName;/*Assigns the name of the column in the lable*/
                lbl.Font.Name = "Calibri";
               
                //lbl.CssClass = "form-label";
                //lbl.Font.Bold = true;
                container.Controls.Add(lbl);/*Adds the New created label control to the container*/
               
                break;

            case ListItemType.Item:
                /**Creates a New Text box Control And Add It to the container**/
                TextBox tb1 = new TextBox();/*Allocates the new text box object*/
                tb1.DataBinding += new EventHandler(tb1_DataBinding);/*Attaches the data binding event*/
                tb1.CssClass = "vertical-text";
                string bxid = "txt" + _columnName;
                tb1.ID = bxid.Trim().ToString();
                tb1.Width = new Unit(35, UnitType.Pixel);
                tb1.Height = new Unit(15, UnitType.Pixel);
                //tb1.Style.Add("font-size", "8pt;");
                tb1.Font.Name = "Calibri";
               
                tb1.Columns = 3; /**Creates a column with size 4**/
                container.Controls.Add(tb1);/**Adds the New created textbox to the container**/
                break;

            case ListItemType.EditItem:
              

                break;

            case ListItemType.Footer:
                CheckBox chkColumn = new CheckBox();
                chkColumn.ID = "Chk" + _columnName;
                container.Controls.Add(chkColumn);
                break;

            #endregion
        }
    }

    /// <summary>
    /// This is the event, which will be raised when the binding happens.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// 
    void tb1_DataBinding(object sender, EventArgs e)
    {
        #region For Use DataBinding Fields..
        TextBox txtdata = (TextBox)sender;
        GridViewRow container = (GridViewRow)txtdata.NamingContainer;
        object dataValue = DataBinder.Eval(container.DataItem, _columnName);
        if (dataValue != DBNull.Value)
        {
            if (dataValue.ToString().Trim() == "0".ToString() || dataValue.ToString().Trim()=="")
            {

                txtdata.Text = "";
                //txtdata.BackColor = System.Drawing.Color.BlanchedAlmond;
                //txtdata.ReadOnly = true;
                txtdata.Width = 35;
                txtdata.Height = 25;
                txtdata.CssClass = "form-control input-sm m-bot15";
                txtdata.Font.Size = 8;
            }

            if (dataValue.ToString().Trim() == "777" || dataValue.ToString().Trim() == "L")
            {

                txtdata.Text = "L";
                txtdata.BackColor = System.Drawing.Color.SandyBrown;
                //txtdata.ReadOnly = true;
                txtdata.Width = 35;
                txtdata.Height = 25;
                txtdata.CssClass = "form-control input-sm m-bot15";
                txtdata.Font.Size = 7;
            }
            

            if (dataValue.ToString().Trim() == "888" || dataValue.ToString().Trim() == "WO")
            {

                txtdata.Text = "WO";
                txtdata.BackColor = System.Drawing.Color.LightGreen;
                //txtdata.ReadOnly = true;
                txtdata.Width = 36;
                txtdata.Height = 25;
                txtdata.CssClass = "form-control input-sm m-bot15";
                txtdata.Font.Size = 7;
            }
   

            if (dataValue.ToString().Trim() == "999" || dataValue.ToString().Trim() == "PH")
            {

                txtdata.Text = "PH";
                txtdata.BackColor = System.Drawing.Color.Cornsilk;
                //txtdata.ReadOnly = true;
                txtdata.Width = 35;
                txtdata.Height = 25;
                txtdata.CssClass = "form-control input-sm m-bot15";
                txtdata.Font.Size = 7;
            }
   
            if (dataValue.ToString().Trim() == "1111" || dataValue.ToString().Trim() == "CL")
            {

                txtdata.Text = "CL";
                txtdata.BackColor = System.Drawing.Color.Bisque;
                //txtdata.ReadOnly = true;
                txtdata.Width = 35;
                txtdata.Height = 25;
                txtdata.CssClass = "form-control input-sm m-bot15";
                txtdata.Font.Size = 7;
            }
   
      

           
            if ((dataValue.ToString().Trim() != "1111") && (dataValue.ToString().Trim() != "CL") && (dataValue.ToString().Trim() != "2997") && (dataValue.ToString().Trim() != "HD") && (dataValue.ToString().Trim() != "777") && (dataValue.ToString().Trim() != "L") && (dataValue.ToString().Trim() != "888") && (dataValue.ToString().Trim() != "W/O")  (dataValue.ToString().Trim() != "") && (dataValue.ToString().Trim() != "1")&& 
            {

                txtdata.ReadOnly = false;
                txtdata.BackColor = System.Drawing.Color.LightGoldenrodYellow;
                txtdata.Text = dataValue.ToString();
                txtdata.Width = 35;
                txtdata.Height = 25;
                txtdata.CssClass = "form-control input-sm m-bot15";
                txtdata.Font.Size = 7;
                txtdata.Font.Bold = true;
            }
            if ((dataValue.ToString().Trim() != "1111") && (dataValue.ToString().Trim() != "CL") && (dataValue.ToString().Trim() != "2997") && (dataValue.ToString().Trim() != "HD") && (dataValue.ToString().Trim() != "777") && (dataValue.ToString().Trim() != "L") && (dataValue.ToString().Trim() != "888") && (dataValue.ToString().Trim() != "WO") && (dataValue.ToString().Trim() != "1776") && (dataValue.ToString().Trim() != "") && (dataValue.ToString().Trim() != "3000") && (dataValue.ToString().Trim() != "T") && (dataValue.ToString().Trim() != "1000") && 
            {

                txtdata.ReadOnly = false;
                txtdata.Text = dataValue.ToString();
                txtdata.Width = 35;
                txtdata.Height = 25;
                txtdata.CssClass = "form-control input-sm m-bot15";
                txtdata.Font.Size = 7;
                txtdata.Font.Bold = true;
            }
           
            //else
            //{
            //    txtdata.ReadOnly = false;
            //    txtdata.Text = dataValue.ToString();
            //    txtdata.Width = 35;
            //    txtdata.Height = 25;
            //    txtdata.CssClass = "form-control input-sm m-bot15";
            //    txtdata.Font.Size = 8;
            //    txtdata.Font.Bold = true;
            //}


        }
        else
        {
            txtdata.Text ="";
            txtdata.Width = 35;
            txtdata.Height = 25;
            txtdata.CssClass = "form-control input-sm m-bot15";
            txtdata.Font.Size = 8;
            txtdata.Font.Bold = true;
        }
        #endregion
    }

}
于 2021-03-19T06:01:15.890 回答