Exemplo n.º 1
0
        public void SetStatus(DataGridView dgv)
        {
            DataTable tempTable = dgv.DataSource as DataTable;

            if (tempTable == null && tempTable.Rows.Count == 0)
            {
                return;
            }

            if (!tempTable.Columns.Contains("物料状态"))
            {
                tempTable.Columns.Add("物料状态");
            }

            ThreadPool.QueueUserWorkItem((WaitCallback) delegate
            {
                try
                {
                    using (DepotManagementDataContext ctx = CommentParameter.DepotDataContext)
                    {
                        foreach (DataRow dr in tempTable.Rows)
                        {
                            if (dr["物料状态"] == null || GlobalObject.GeneralFunction.IsNullOrEmpty(dr["物料状态"].ToString()))
                            {
                                dr["物料状态"] = ctx.Fun_get_Business_WarehouseOutPut_WholeMachineRequisition_GoodsStatus(dr["业务编号"].ToString());
                            }
                        }
                    }

                    if (!dgv.InvokeRequired)
                    {
                        return;
                    }

                    dgv.BeginInvoke((MethodInvoker) delegate
                    {
                        dgv.DataSource = tempTable;

                        foreach (DataGridViewRow dgvr in dgv.Rows)
                        {
                            switch (dgvr.Cells["物料状态"].Value.ToString())
                            {
                            case "待发料":
                                dgvr.DefaultCellStyle.BackColor = Color.Yellow;
                                break;

                            case "缺料":
                                dgvr.DefaultCellStyle.BackColor = Color.Red;
                                break;

                            case "正常":
                                dgvr.DefaultCellStyle.BackColor = Color.White;
                                break;

                            default:
                                break;
                            }
                        }
                    });
                }
                catch (Exception)
                {
                    throw;
                }
            });
        }