예제 #1
0
        private void grdViewStock_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (((e.ColumnIndex == 6) || (e.ColumnIndex == 7)) && (e.RowIndex != -1))
                {
                    int             rowIndex = e.RowIndex;
                    DataGridViewRow row      = grdViewStock.Rows[rowIndex];

                    if (e.ColumnIndex == 6)
                    {
                        lblStkId.Text = Convert.ToString(row.Cells[0].Value);

                        if (lblStkId.Text != "0")
                        {
                            var InvObj = _repository.GetAllStocksById(Convert.ToInt32(row.Cells[0].Value));
                            txtDescription.Text            = InvObj.Description;
                            txtNumberCount.Text            = Convert.ToString(InvObj.NumberCount);
                            cmbInventoryType.SelectedValue = InvObj.InventoryTypeId;
                            cmbInventory.SelectedValue     = InvObj.InventoryId;
                            dtpProcessDate.Value           = InvObj.ProcessDate;
                            txtPrice.Text       = string.Format("{0:#,##0}", double.Parse(Convert.ToString(InvObj.Price)));
                            txtDescription.Text = InvObj.Description;
                            lblNoInStock.Text   = Convert.ToString(_repository.GetNumberInStock(Convert.ToInt32(cmbInventory.SelectedValue)));
                        }
                        else
                        {
                            tempStk                        = row.DataBoundItem as Stock;
                            txtDescription.Text            = tempStk.Description;
                            txtNumberCount.Text            = Convert.ToString(tempStk.NumberCount);
                            cmbInventoryType.SelectedValue = tempStk.InventoryTypeId;
                            cmbInventory.SelectedValue     = tempStk.InventoryId;
                            dtpProcessDate.Value           = tempStk.ProcessDate;
                            txtPrice.Text                  = string.Format("{0:#,##0}", double.Parse(Convert.ToString(tempStk.Price)));
                        }
                        btnAdd.Text = "Update";
                    }

                    if (e.ColumnIndex == 7)
                    {
                        if (PreDeleteConfirmation() == System.Windows.Forms.DialogResult.Yes)
                        {
                            var StockId = Convert.ToInt32(row.Cells[0].Value);

                            foreach (DataGridViewRow rr in grdViewStock.Rows)
                            {
                                if (rr == row)
                                {
                                    grdViewStock.Rows.RemoveAt(rr.Index);
                                    break;
                                }
                            }
                            grdViewStock.Refresh();

                            if (StockId != 0)
                            {
                                _repository.DeleteStock(StockId);
                                MessageBox.Show("Stock Deleted Successfully", "Deleted...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                ClearAll();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }