private void grid_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == grid.Columns["gridcol_product"].Index)
            {
                DataGridViewComboBoxCell dgvcc = new DataGridViewComboBoxCell();
                DataGridViewCell         dgvc  = new DataGridViewComboBoxExCell();
                dgvcc.AutoComplete  = true;
                dgvcc.DataSource    = DataSupport.RunDataSet(String.Format("SELECT * FROM productuoms where product = '{0}'", grid.Rows[e.RowIndex].Cells["gridcol_product"].Value)).Tables[0];
                dgvcc.DisplayMember = "uom";
                dgvcc.ValueMember   = "uom";
                dgvc = dgvcc;
                grid.Rows[e.RowIndex].Cells["gridcol_uom"] = dgvc;

                dgvcc = new DataGridViewComboBoxCell();
                dgvc  = new DataGridViewComboBoxExCell();
                dgvcc.AutoComplete  = true;
                dgvcc.DataSource    = DataSupport.RunDataSet(String.Format("SELECT * FROM productuoms where product = '{0}'", grid.Rows[e.RowIndex].Cells["gridcol_product"].Value)).Tables[0];
                dgvcc.DisplayMember = "uom";
                dgvcc.ValueMember   = "uom";
                dgvc = dgvcc;
                grid.Rows[e.RowIndex].Cells["gridcol_whatuom"] = dgvc;
            }
            else if (e.ColumnIndex == grid.Columns["gridcol_uom"].Index)
            {
                if (grid.Rows[e.RowIndex].Cells["gridcol_uom"].Value == null)
                {
                    return;
                }

                ComboBox c = new ComboBox();

                DataGridViewComboBoxCell dgvcc = new DataGridViewComboBoxCell();
                DataGridViewCell         dgvc  = new DataGridViewComboBoxExCell();
                dgvcc.AutoComplete  = true;
                dgvcc.DataSource    = DataSupport.RunDataSet(String.Format("SELECT DISTINCT lot_no FROM LocationProductsLedger where product = '{0}' and uom = '{1}'", grid.Rows[e.RowIndex].Cells["gridcol_product"].Value, grid.Rows[e.RowIndex].Cells["gridcol_uom"].Value)).Tables[0];
                dgvcc.DisplayMember = "lot_no";
                dgvcc.ValueMember   = "lot_no";
                dgvc = dgvcc;
                grid.Rows[e.RowIndex].Cells["gridcol_lotno"] = dgvc;
            }
            else if (e.ColumnIndex == grid.Columns["gridcol_lotno"].Index)
            {
                if (grid.Rows[e.RowIndex].Cells["gridcol_uom"].Value == null)
                {
                    return;
                }

                DataGridViewComboBoxCell dgvcc = new DataGridViewComboBoxCell();
                DataGridViewCell         dgvc  = new DataGridViewComboBoxExCell();
                dgvcc.AutoComplete  = true;
                dgvcc.DataSource    = DataSupport.RunDataSet(String.Format("SELECT DISTINCT expiry FROM LocationProductsLedger where product = '{0}' and uom = '{1}' and lot_no = '{2}'", grid.Rows[e.RowIndex].Cells["gridcol_product"].Value, grid.Rows[e.RowIndex].Cells["gridcol_uom"].Value, grid.Rows[e.RowIndex].Cells["gridcol_lotno"].Value)).Tables[0];
                dgvcc.DisplayMember = "expiry";
                dgvcc.ValueMember   = "expiry";
                dgvc = dgvcc;
                grid.Rows[e.RowIndex].Cells["gridcol_expiry"] = dgvc;
            }
        }
Example #2
0
        private List <CadresRecord> GetInsertList()
        {
            //儲存時,社長與副社長資料,儲存於社團Record
            List <CadresRecord>       InsertList = new List <CadresRecord>();
            Dictionary <string, bool> Dic        = new Dictionary <string, bool>();

            Dic.Add("社長", false);
            Dic.Add("副社長", false);
            foreach (DataGridViewRow row in dataGridViewX1.Rows)
            {
                if (row.IsNewRow)
                {
                    continue;
                }

                DataGridViewTextBoxCell    cell_0 = (DataGridViewTextBoxCell)row.Cells[Column1.Index];
                DataGridViewComboBoxExCell cell_1 = (DataGridViewComboBoxExCell)row.Cells[Column2.Index];
                if ("" + cell_0.Value == "社長") //社長
                {
                    Dic["社長"] = true;
                    //在Cell-1內所選的學生是誰?
                    if (StudentDic.ContainsKey("" + cell_1.Value))
                    {
                        StudentRecord sr = StudentDic["" + cell_1.Value];
                        ClubPrimary.President = sr.ID;
                    }
                    else
                    {
                        ClubPrimary.President = string.Empty;
                    }
                }
                else if ("" + cell_0.Value == "副社長") //副社長
                {
                    Dic["副社長"] = true;
                    if (StudentDic.ContainsKey("" + cell_1.Value))
                    {
                        StudentRecord sr = StudentDic["" + cell_1.Value];
                        ClubPrimary.VicePresident = sr.ID;
                    }
                    else
                    {
                        ClubPrimary.VicePresident = string.Empty;
                    }
                }
                else //其他Row
                {
                    if (StudentDic.ContainsKey("" + cell_1.Value))
                    {
                        StudentRecord sr = StudentDic["" + cell_1.Value];
                        CadresRecord  cr = new CadresRecord();
                        cr.CadreName    = "" + cell_0.Value;
                        cr.RefStudentID = sr.ID;
                        cr.RefClubID    = ClubPrimary.UID;
                        InsertList.Add(cr);
                    }
                }
            }

            if (!Dic["社長"])
            {
                ClubPrimary.President = string.Empty;
            }
            if (!Dic["副社長"])
            {
                ClubPrimary.VicePresident = string.Empty;
            }

            return(InsertList);
        }