Пример #1
0
        /// <summary>
        /// 刷新DataGridView
        /// </summary>
        /// <param name="stockGoodsGroup">数据集</param>
        void RefreshDataGridView(List <View_S_Stock> stockGoodsGroup)
        {
            ClearForm();

            DataTable dtResult    = GeneralFunction.ConvertToDataTable(stockGoodsGroup);
            DataTable dtStorageID = m_serverStorageInfo.GetStorageIDAndPersonnel(BasicInfo.LoginID);

            m_dtSource = dtResult.Clone();

            if (dtResult.Rows.Count != 0 &&
                dtStorageID != null &&
                dtStorageID.Rows.Count > 0)
            {
                for (int i = 0; i < dtStorageID.Rows.Count; i++)
                {
                    try
                    {
                        DataRow[] dr = dtResult.Select("库房代码 = '" + dtStorageID.Rows[i]["StorageID"] + "'");

                        if (dr.Length > 0)
                        {
                            for (int a = 0; a <= dr.Length - 1; a++)
                            {
                                m_dtSource.ImportRow(dr[a]);
                            }
                        }
                    }
                    catch (Exception exce)
                    {
                        if (!exce.Message.Contains("未找到"))
                        {
                            MessageDialog.ShowErrorMessage(exce.Message);
                            return;
                        }
                    }
                }

                dataGridView1.DataSource = m_dtSource;
            }
            else
            {
                dataGridView1.DataSource = dtResult;
            }

            dataGridView1.Columns["实际单价"].Visible = false;
            dataGridView1.Columns["实际金额"].Visible = false;

            this.dataGridView1.ColumnWidthChanged -= new System.Windows.Forms.DataGridViewColumnEventHandler(
                this.dataGridView1_ColumnWidthChanged);

            ColumnWidthControl.SetDataGridView(labelTitle.Text, dataGridView1);

            this.dataGridView1.ColumnWidthChanged += new System.Windows.Forms.DataGridViewColumnEventHandler(
                this.dataGridView1_ColumnWidthChanged);

            if (!numFactUnitPrice.Visible)
            {
                dataGridView1.Columns["实际单价"].Visible = false;
                dataGridView1.Columns["实际金额"].Visible = false;
            }

            if (dataGridView1.Rows.Count > 0)
            {
                dataGridView1.Columns["序号"].Visible   = false;
                dataGridView1.Columns["单位ID"].Visible = false;
            }
        }