Example #1
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            var existFrm = GetForm(frmWarehouseInName);

            if (existFrm != null)
            {
                existFrm.Close();
            }
            FrmWarehouseIn frm = new FrmWarehouseIn();

            frm.MdiParent = this.MdiParent;
            frm.Show();
        }
Example #2
0
        private void gridWarehouse_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int id = Convert.ToInt32(gridWarehouse.Rows[e.RowIndex].Cells[0].Value);

            if (e.ColumnIndex == gridWarehouse.Columns.Count - 1)
            {
                if (MessageBox.Show("确定要删除此数据?", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    var items = entities.WarehouseInItem.Where(item => item.WarehouseIn_Id == id).ToList();

                    try
                    {
                        using (TransactionScope scope = new TransactionScope())
                        {
                            foreach (var item in items)
                            {
                                var product = entities.Product.Find(item.Product_Id);

                                product.StockQuantity = product.StockQuantity - item.Quantity;
                                entities.Save <Product>(product);
                            }
                            entities.Delete <WarehouseIn>(id);
                            scope.Complete();
                        }
                    }
                    catch (Exception exp)
                    {
                        MessageBox.Show("数据删除失败!", "提示");
                        LogHelper.WriteLog(LogType.Error, exp, this.GetType());
                    }
                    DataBind();
                }
            }
            else if (e.ColumnIndex == gridWarehouse.Columns.Count - 2)
            {
                var existFrm = GetForm(frmWarehouseInName);
                if (existFrm != null)
                {
                    existFrm.Close();
                }
                FrmWarehouseIn frm = new FrmWarehouseIn();
                frm.MdiParent     = this.MdiParent;
                frm.WarehouseInId = id;
                frm.Show();
            }
        }