private void FormatDataGrid()
{
DataGridTableStyle ts=new DataGridTableStyle();
ts.MappingName=this.tbltmpmon;
ts.AlternatingBackColor=Color.LightGray;
ts.AllowSorting=true;
ts.ReadOnly=true;
ts.RowHeadersVisible=true;
int cols=this.ds.Tables[tblMonth].Columns.Count;
for (int i=0;i<cols;i++)
{
if (this.ds.Tables[tblMonth].Columns[i].ColumnName.Equals("PRD_NO"))
{
DataGridTextBoxColumn cs=new DataGridTextBoxColumn();
cs.MappingName=this.ds.Tables[tblMonth].Columns[i].ColumnName;
cs.HeaderText="材料代号";
cs.Width=80;
cs.NullText=string.Empty;
cs.Alignment=System.Windows.Forms.HorizontalAlignment.Left;
ts.GridColumnStyles.Add(cs);
}
else if (this.ds.Tables[tblMonth].Columns[i].ColumnName.Equals("PRD_NAME"))
{
DataGridTextBoxColumn cs=new DataGridTextBoxColumn();
cs.MappingName=this.ds.Tables[tblMonth].Columns[i].ColumnName;
cs.HeaderText="材料品名规格";
cs.Width=180;
cs.NullText=string.Empty;
cs.Alignment=System.Windows.Forms.HorizontalAlignment.Left;
ts.GridColumnStyles.Add(cs);
}
else if (this.ds.Tables[tblMonth].Columns[i].ColumnName.Equals("UT"))
{
DataGridTextBoxColumn cs=new DataGridTextBoxColumn();
cs.MappingName=this.ds.Tables[tblMonth].Columns[i].ColumnName;
cs.HeaderText="单位";
cs.Width=50;
cs.NullText=string.Empty;
cs.Alignment=System.Windows.Forms.HorizontalAlignment.Left;
ts.GridColumnStyles.Add(cs);
}
else if (this.ds.Tables[tblMonth].Columns[i].ColumnName.Equals("QTY_ST"))
{
DataGridTextBoxColumn cs=new DataGridTextBoxColumn();
cs.MappingName=this.ds.Tables[tblMonth].Columns[i].ColumnName;
cs.HeaderText="期初库存";
cs.Width=75;
cs.NullText=string.Empty;
cs.Alignment=System.Windows.Forms.HorizontalAlignment.Right;
ts.GridColumnStyles.Add(cs);
}
else
{
DataGridTextBoxColumn cs=new DataGridTextBoxColumn();
this.str=this.ds.Tables[tblMonth].Columns[i].ColumnName.ToString();
switch (this.str.Substring(4,1))
{
case "P":
cs.HeaderText=this.str.Substring(0,2)+"年"+
this.str.Substring(2,2)+"月在途";
break;
case "E":
cs.HeaderText=this.str.Substring(0,2)+"年"+
this.str.Substring(2,2)+"月未领";
break;
case "B":
cs.HeaderText=this.str.Substring(0,2)+"年"+
this.str.Substring(2,2)+"月结存";
break;
default:
cs.HeaderText=this.ds.Tables[tblMonth].Columns[i].ColumnName;
break;
}
cs.MappingName=this.ds.Tables[tblMonth].Columns[i].ColumnName;
// cs.HeaderText=this.ds.Tables[tblMonth].Columns[i].ColumnName;
cs.Width=100;
cs.NullText=string.Empty;
cs.Alignment=System.Windows.Forms.HorizontalAlignment.Right;
ts.GridColumnStyles.Add(cs);
}
}
this.dgPlan.TableStyles.Clear();
this.dgPlan.TableStyles.Add(ts);
}