Exemplo n.º 1
0
 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
 {
     using (var mForm = new 礼品出库申请())
     {
         mForm.ShowDialog();
         btnSearch_Click(sender, e);
     }
 }
Exemplo n.º 2
0
        private void dgvGiftStockOut_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == dgvGiftStockOut.Rows.Count - 1)
            {
                return;
            }
            if (e.RowIndex > -1)
            {
                try
                {
                    if (e.ColumnIndex == dgvGiftStockOut.Columns["ColModify"].Index)//修改
                    {
                        using (var mForm = new 礼品出库申请())
                        {
                            mForm.mId = Convert.ToInt64(dgvGiftStockOut.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value);
                            if (dgvGiftStockOut.Rows[e.RowIndex].Cells["HasStockOut"].Value.ToString() == "已出库")
                            {
                                mForm.hasStockOut = true;
                            }
                            mForm.ShowDialog();
                            btnSearch_Click(sender, new EventArgs());
                        }
                    }
                    if (e.ColumnIndex == dgvGiftStockOut.Columns["ColDel"].Index)//删除
                    {
                        if (MessageBox.Show("确认要删除该条记录吗?", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            using (SqlConnection mConn = new SqlConnection(Common.CommonClass.SqlConnStr))
                            {
                                mConn.Open();
                                using (SqlTransaction mTrans = mConn.BeginTransaction())
                                {
                                    try
                                    {
                                        var adapter = new T_GiftStockOutTableAdapter();
                                        adapter.Connection  = mConn;
                                        adapter.Transaction = mTrans;

                                        //删除该条记录
                                        int ret = 0;
                                        ret = adapter.UpdateStatus("已删除", Classes.PubClass.UserId, Convert.ToInt64(dgvGiftStockOut.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value)); // 状态改为已删除
                                        if (ret > 0)
                                        {
                                            if (dgvGiftStockOut.Rows[e.RowIndex].Cells["HasStockOut"].Value.ToString() == "已出库")
                                            {
                                                //如果已出库,则礼品退回库存
                                                var adapter1 = new T_GiftsTableAdapter();
                                                adapter1.Connection  = mConn;
                                                adapter1.Transaction = mTrans;

                                                ret = adapter1.AddStockNum(Convert.ToDecimal(dgvGiftStockOut.Rows[e.RowIndex].Cells["giftNumDataGridViewTextBoxColumn"].Value), Convert.ToInt64(dgvGiftStockOut.Rows[e.RowIndex].Cells["giftIdDataGridViewTextBoxColumn"].Value)); //礼品退回库存
                                            }

                                            if (ret > 0)
                                            {
                                                mTrans.Commit();
                                                MessageBox.Show("删除成功!");
                                                mConn.Close();
                                                btnSearch_Click(sender, new EventArgs());
                                                return;
                                            }
                                            else
                                            {
                                                mTrans.Rollback();
                                                MessageBox.Show("删除失败:2");
                                                return;
                                            }
                                        }
                                        else
                                        {
                                            mTrans.Rollback();
                                            MessageBox.Show("删除失败:1");
                                            return;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        mTrans.Rollback();
                                        MessageBox.Show(ex.Message);
                                    }
                                }
                            }
                        }
                    }
                    if (e.ColumnIndex == dgvGiftStockOut.Columns["ColStockOut"].Index)//出库
                    {
                        if (dgvGiftStockOut.Rows[e.RowIndex].Cells["HasStockOut"].Value.ToString() != "未出库" || dgvGiftStockOut.Rows[e.RowIndex].Cells["Status"].Value.ToString() != "审核已通过")
                        {
                            return;
                        }
                        if (MessageBox.Show("是否确认出库?", "警告", MessageBoxButtons.YesNo) == DialogResult.Yes)//出库时修改库存
                        {
                            try
                            {
                                using (SqlConnection mConn = new SqlConnection(Common.CommonClass.SqlConnStr))
                                {
                                    mConn.Open();
                                    using (SqlTransaction mTrans = mConn.BeginTransaction())
                                    {
                                        try
                                        {
                                            int ret     = 0;
                                            var adapter = new T_GiftStockOutTableAdapter();
                                            adapter.Connection  = mConn;
                                            adapter.Transaction = mTrans;
                                            ret = adapter.StockOut(Convert.ToInt64(dgvGiftStockOut.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                                            if (ret > 0)
                                            {
                                                var adapter1 = new T_GiftsTableAdapter();
                                                adapter1.Connection  = mConn;
                                                adapter1.Transaction = mTrans;
                                                decimal mCurrentNum = Convert.ToDecimal(dgvGiftStockOut.Rows[e.RowIndex].Cells["giftNumDataGridViewTextBoxColumn"].Value);
                                                long    mGiftId     = Convert.ToInt64(dgvGiftStockOut.Rows[e.RowIndex].Cells["giftIdDataGridViewTextBoxColumn"].Value);
                                                ret = adapter1.AddStockNum(-mCurrentNum, mGiftId);
                                                if (ret > 0)
                                                {
                                                    mTrans.Commit();
                                                    MessageBox.Show("出库成功!");
                                                    mConn.Close();
                                                    btnSearch_Click(sender, new EventArgs());
                                                    return;
                                                }
                                                else
                                                {
                                                    mTrans.Rollback();
                                                    MessageBox.Show("出库失败:2");
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                mTrans.Rollback();
                                                MessageBox.Show("出库失败:1");
                                                return;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            mTrans.Rollback();
                                            MessageBox.Show(ex.Message);
                                            return;
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message);
                                return;
                            }
                        }
                    }
                    if (e.ColumnIndex == dgvGiftStockOut.Columns["ColBack"].Index)//退回
                    {
                        if (dgvGiftStockOut.Rows[e.RowIndex].Cells["HasStockOut"].Value.ToString() != "已出库")
                        {
                            MessageBox.Show("礼品出库后才能退回!");
                            return;
                        }
                        using (var mForm = new 输入礼品退回数量())
                        {
                            mForm.mCurrent = Convert.ToDecimal(dgvGiftStockOut.Rows[e.RowIndex].Cells["giftNumDataGridViewTextBoxColumn"].Value);
                            if (mForm.ShowDialog() == DialogResult.OK)
                            {
                                decimal mBackNum = mForm.mBackNum;

                                using (SqlConnection mConn = new SqlConnection(Common.CommonClass.SqlConnStr))
                                {
                                    mConn.Open();
                                    using (SqlTransaction mTrans = mConn.BeginTransaction())
                                    {
                                        try
                                        {
                                            var adapter = new T_GiftStockOutTableAdapter();
                                            adapter.Connection  = mConn;
                                            adapter.Transaction = mTrans;

                                            int ret = 0;
                                            ret = adapter.BackStock(mBackNum, Convert.ToInt64(dgvGiftStockOut.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                                            if (ret > 0)
                                            {
                                                var adapter1 = new T_GiftsTableAdapter();
                                                adapter1.Connection  = mConn;
                                                adapter1.Transaction = mTrans;

                                                ret = adapter1.AddStockNum(mBackNum, Convert.ToInt64(dgvGiftStockOut.Rows[e.RowIndex].Cells["giftIdDataGridViewTextBoxColumn"].Value));
                                                if (ret > 0)
                                                {
                                                    mTrans.Commit();
                                                    MessageBox.Show("礼品退回成功");
                                                    mConn.Close();
                                                    btnSearch_Click(sender, new EventArgs());
                                                    return;
                                                }
                                                else
                                                {
                                                    mTrans.Rollback();
                                                    MessageBox.Show("礼品退回失败:2");
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                mTrans.Rollback();
                                                MessageBox.Show("礼品退回失败:1");
                                                return;
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            mTrans.Rollback();
                                            MessageBox.Show(ex.Message);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    return;
                }
            }
        }