Hello,
I am optimizing the code of crud gridview program and i intended to shorter duplicated code into
global variable and function. Below is a part of the result of optimized code but i am not really for sure whether it will cause problem or the writing way is correct or wrong because i am not really familiar with c# before i usually write javascript.
===============================================
private DataTable dt = new DataTable();
protected void InitGridView(DataTable dt)
{
dt.Columns.Add("ID");
dt.Columns.Add("UserId");
dt.Columns.Add("UserName");
dt.Columns.Add("Date");
dt.Columns.Add("StartHour");
dt.Columns.Add("StartMin");
dt.Columns.Add("EndHour");
dt.Columns.Add("EndMin");
dt.Columns.Add("Category");
dt.Columns.Add("LunchBreak");
dt.Columns.Add("NightBreak");
dt.Columns.Add("Hours");
dt.Columns.Add("DateBelong");
dt.Columns.Add("TapTime");
dt.Columns.Add("OtaCategory");
dt.Columns.Add("Reason");
}
private string date = "";
private float totalHours = 0;
protected void txtDateFooter_SelectedDateChanged(object sender, SelectedDateChangedEventArgs e)
{
date = e.NewDate.Value.ToString("yyyy/MM/dd");
}
/// <summary>
/// 顯示時欄位初始值
/// </summary>
/// <param name="versionField">欄位集合</param>
public override void SetField(Ede.Uof.WKF.Design.VersionField versionField)
{
FieldOptional fieldOptional = versionField as FieldOptional;
if (fieldOptional != null)
{
//若有擴充屬性,可以用該屬性存取
// fieldOptional.ExtensionSetting
//DataTable dt = new DataTable();
if (!IsPostBack)
{
if (String.IsNullOrEmpty(fieldOptional.FieldValue))
{
InitGridView(dt);
dt.Rows.Add(dt.NewRow());
Grid1.DataSource = dt;
Grid1.DataBind();
Grid1.Rows[0].Cells.Clear();
Grid1.Rows[0].Cells.Add(new TableCell());
Grid1.Rows[0].Cells[0].ColumnSpan = dt.Columns.Count;
Grid1.Rows[0].Cells[0].Text = "尚無資料";
Grid1.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
}
else
{
TextBox1.Text = fieldOptional.FieldValue;
BindGrid();
======================================================
hope to know more about experience of c# developers, thanks!!