private void dgvGifts_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex > -1)
     {
         if (e.ColumnIndex == dgvGifts.Columns["ColModify"].Index)//修改
         {
             using (var mForm = new 添加礼品种类())
             {
                 mForm.mId = Convert.ToInt64(dgvGifts.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value);
                 mForm.ShowDialog();
                 btnFind_Click(sender, new EventArgs());
             }
         }
         if (e.ColumnIndex == dgvGifts.Columns["ColDel"].Index)//删除
         {
             if (MessageBox.Show("确认删除该礼品?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
             {
                 int ret = new T_GiftsTableAdapter().MyDelete(Convert.ToInt64(dgvGifts.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                 if (ret > 0)
                 {
                     MessageBox.Show("删除成功");
                     btnFind_Click(sender, new EventArgs());
                     return;
                 }
                 else
                 {
                     MessageBox.Show("删除失败");
                     return;
                 }
             }
         }
     }
 }
 private void 添加礼品种类_Load(object sender, EventArgs e)
 {
     if (mId > -1)
     {
         var mTable = new T_GiftsTableAdapter().GetDataById(mId);
         if (mTable.Rows.Count > 0)
         {
             销售管理.DAL.DataSetGifts.T_GiftsRow mRow = (销售管理.DAL.DataSetGifts.T_GiftsRow)mTable.Rows[0];
             txtGiftName.Text = mRow.GiftName;
             txtPrice.Text    = mRow.Price.ToString();
             txtStockNum.Text = mRow.StockNum.ToString();
             this.Text        = "修改礼品信息";
             btnAdd.Text      = "保存";
         }
     }
 }
Beispiel #3
0
        private void cmbGifts_SelectedIndexChanged(object sender, EventArgs e)
        {
            //if (isLoading == true) return;
            var mTable = new T_GiftsTableAdapter().GetDataById(Convert.ToInt64(cmbGifts.SelectedValue));

            if (mTable.Rows.Count > 0)
            {
                var mRow = (销售管理.DAL.DataSetGifts.T_GiftsRow)mTable.Rows[0];
                txtGiftPrice.Text = mRow.Price.ToString();
                txtStockNum.Text  = mRow.StockNum.ToString();
            }
            else
            {
                txtGiftPrice.Text = "0";
                txtStockNum.Text  = "0";
            }
        }
Beispiel #4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (cmbUsers.Text == string.Empty)
            {
                toolTip1.Show("请选择领用人!", cmbUsers, 0, cmbUsers.Height, 2000);
                return;
            }
            if (CBoxUser.Text == string.Empty)
            {
                toolTip1.Show("请选择使用人!", CBoxUser, 0, CBoxUser.Height, 2000);
                return;
            }
            if (cmbCustomers.Text == string.Empty)
            {
                toolTip1.Show("请选择客户名称!", cmbCustomers, 0, cmbCustomers.Height, 2000);
                return;
            }
            if (cmbGifts.Text == string.Empty)
            {
                toolTip1.Show("请选择礼品名称!", cmbGifts, 0, cmbGifts.Height, 2000);
                return;
            }
            if (txtCurrentNum.Text == string.Empty)
            {
                toolTip1.Show("请输入领用用量!", txtCurrentNum, 0, txtCurrentNum.Height, 2000);
                return;
            }
            long mNewGiftId = Convert.ToInt64(cmbGifts.SelectedValue);

            if (mId == -1 || mNewGiftId != mOldGiftId)//新增
            {
                if (Convert.ToDecimal(txtCurrentNum.Text) > Convert.ToDecimal(txtStockNum.Text))
                {
                    toolTip1.Show("领用数量不得大于库存数量!", txtCurrentNum, 0, txtCurrentNum.Height, 2000);
                    return;
                }
            }
            else
            {//修改
                if ((Convert.ToDecimal(txtCurrentNum.Text) - mOldNum) > Convert.ToDecimal(txtStockNum.Text))
                {
                    toolTip1.Show("领用数量不得大于库存数量!", txtCurrentNum, 0, txtCurrentNum.Height, 2000);
                    return;
                }
            }

            string    operRight  = "";
            DataTable mTempTable = new T_UsersTableAdapter().GetDataById(Convert.ToInt64(cmbUsers.SelectedValue));

            销售管理.DAL.DataSetUsers.T_UsersRow mRow;
            if (mTempTable.Rows.Count > 0)
            {
                mRow      = (销售管理.DAL.DataSetUsers.T_UsersRow)mTempTable.Rows[0];
                operRight = mRow.OperRight;
            }
            //if (Convert.ToDecimal(txtSum.Text) - mOldSum > Convert.ToDecimal(txtMaxSum.Text) && operRight != "领导" && operRight != "融通创投" && operRight != "金融卡事业部" && operRight != "财务")
            //{
            //    toolTip1.Show("领用礼品金额不能超过最大允许金额!", txtMaxSum, 0, txtMaxSum.Height, 2000);
            //    return;
            //}


            //修改时间:2016/8/8 修改内容:添加销售角色剩余额度判断
            #region
            if (operRight == "销售" && Convert.ToDecimal(txtMaxSum.Text) - Convert.ToDecimal(txtSum.Text) < -5000)
            {
                MessageBox.Show("剩余额度已超5000元,礼品出库申请提交失败!", "超额提醒");
                return;
            }
            #endregion



            try
            {
                decimal mCurrentNum = Convert.ToDecimal(txtCurrentNum.Text);
                txtCurrentNum_TextChanged(sender, e);
                decimal mSum = Convert.ToDecimal(txtSum.Text);


                using (SqlConnection mConn = new SqlConnection(Common.CommonClass.SqlConnStr))
                {
                    mConn.Open();
                    using (SqlTransaction mTrans = mConn.BeginTransaction())
                    {
                        try
                        {
                            if (mId < 0)
                            {//插入
                                var adapter = new T_GiftStockOutTableAdapter();
                                adapter.Connection  = mConn;
                                adapter.Transaction = mTrans;
                                int ret = 0;
                                ret = adapter.Insert(dtpDataDate.Value.Date.ToString(), Convert.ToInt64(cmbUsers.SelectedValue), Convert.ToInt64(cmbCustomers.SelectedValue), Convert.ToInt64(cmbGifts.SelectedValue), cmbGifts.Text, mCurrentNum, Convert.ToDecimal(txtGiftPrice.Text), mSum, "已提交等待领导审核", null, null, Classes.PubClass.UserId, Convert.ToInt64(CBoxUser.SelectedValue));
                                //if (ret > 0)
                                //{
                                //    var adapter1 = new T_GiftsTableAdapter();
                                //    adapter1.Connection = mConn;
                                //    adapter1.Transaction = mTrans;

                                //    ret = adapter1.AddStockNum(-mCurrentNum, Convert.ToInt64(cmbGifts.SelectedValue));
                                if (ret > 0)
                                {
                                    mTrans.Commit();
                                    MessageBox.Show("插入成功");
                                    btnSave.Enabled = false;
                                    return;
                                }
                                else
                                {
                                    mTrans.Rollback();
                                    MessageBox.Show("插入失败:2");
                                    return;
                                }

                                //}
                                //else
                                //{
                                //    mTrans.Rollback();
                                //    MessageBox.Show("插入失败:1");
                                //    return;
                                //}
                            }
                            else
                            {//修改
                                //先修改记录信息
                                var adapter = new T_GiftStockOutTableAdapter();
                                adapter.Connection  = mConn;
                                adapter.Transaction = mTrans;

                                int ret = 0;
                                ret = adapter.UpdateById(dtpDataDate.Value.Date, Convert.ToInt64(cmbUsers.SelectedValue), Convert.ToInt64(cmbCustomers.SelectedValue), Convert.ToInt64(cmbGifts.SelectedValue), cmbGifts.Text.ToString(), mCurrentNum, Convert.ToDecimal(txtGiftPrice.Text), mSum, Classes.PubClass.UserId, Convert.ToInt64(CBoxUser.SelectedValue), mId);

                                if (ret > 0)
                                {
                                    if (hasStockOut == true)
                                    {
                                        if (mCurrentNum != mOldNum || mOldGiftId != mNewGiftId)
                                        {
                                            var adapter1 = new T_GiftsTableAdapter();
                                            adapter1.Connection  = mConn;
                                            adapter1.Transaction = mTrans;

                                            ret = adapter1.AddStockNum(mOldNum, mOldGiftId);
                                            if (ret > 0)
                                            {
                                                ret = adapter1.AddStockNum(-mCurrentNum, mNewGiftId);
                                                if (ret < 1)
                                                {
                                                    mTrans.Rollback();
                                                    MessageBox.Show("修改数量失败:2");
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                mTrans.Rollback();
                                                MessageBox.Show("修改数量失败:1");
                                                return;
                                            }
                                        }
                                    }
                                    mTrans.Commit();
                                    MessageBox.Show("保存成功!");
                                    btnSave.Enabled = false;
                                }
                                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;
            }
        }
Beispiel #5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtNum.Text.Trim() == "")
                {
                    toolTip1.Show("请输入入库数量!", txtNum, 0, txtNum.Height, 2000);
                    return;
                }
                if (dgvGifts.SelectedRows.Count < 1)
                {
                    MessageBox.Show("请选择要入库的礼品!");
                    return;
                }
                long    giftId;
                Decimal giftPrice, giftOldNum, giftCurrentNum;
                string  giftName;

                giftId     = Convert.ToInt64(dgvGifts.SelectedRows[0].Cells["idDataGridViewTextBoxColumn"].Value);
                giftPrice  = Convert.ToDecimal(dgvGifts.SelectedRows[0].Cells["priceDataGridViewTextBoxColumn"].Value);
                giftOldNum = Convert.ToDecimal(dgvGifts.SelectedRows[0].Cells["stockNumDataGridViewTextBoxColumn"].Value);
                giftName   = dgvGifts.SelectedRows[0].Cells["giftNameDataGridViewTextBoxColumn"].Value.ToString();

                giftCurrentNum = Convert.ToDecimal(txtNum.Text);

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

                            ret = adapter.Insert(giftId, giftName, giftPrice, giftOldNum, giftCurrentNum, giftOldNum + giftCurrentNum, Classes.PubClass.UserId);
                            if (ret > 0)
                            {
                                var adapter1 = new T_GiftsTableAdapter();
                                adapter1.Connection  = mConn;
                                adapter1.Transaction = mTrans;

                                ret = adapter1.AddStockNum(giftCurrentNum, giftId);
                                if (ret > 0)
                                {
                                    mTrans.Commit();
                                    MessageBox.Show("添加库存成功");
                                    btnAdd.Enabled      = false;
                                    dgvGifts.DataSource = adapter1.GetData();
                                }
                            }
                            else
                            {
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                            return;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Beispiel #6
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;
                }
            }
        }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (txtGiftName.Text.Trim() == string.Empty)
     {
         toolTip1.Show("礼品名称不能为空!", txtGiftName, 0, txtGiftName.Height, 2000);
         return;
     }
     if (txtPrice.Text.Trim() == string.Empty)
     {
         toolTip1.Show("单价不能为空!", txtPrice, 0, txtPrice.Height, 2000);
         return;
     }
     if (txtStockNum.Text.Trim() == string.Empty)
     {
         toolTip1.Show("库存数量不能为空!", txtStockNum, 0, txtStockNum.Height, 2000);
         return;
     }
     try
     {
         var adapter = new T_GiftsTableAdapter();
         if (mId < 0)
         {
             var mTable = adapter.GetDataByGiftName(txtGiftName.Text.Trim());
             if (mTable.Rows.Count > 0)
             {
                 toolTip1.Show("礼品名称已存在!", txtGiftName, 0, txtGiftName.Height, 2000);
                 return;
             }
             int ret = 0;
             ret = adapter.Insert(txtGiftName.Text.Trim(), Convert.ToDecimal(txtPrice.Text), Convert.ToDecimal(txtStockNum.Text));
             if (ret > 0)
             {
                 MessageBox.Show("插入成功!");
                 btnAdd.Enabled = false;
                 return;
             }
             else
             {
                 MessageBox.Show("插入失败!");
                 return;
             }
         }
         else
         {
             int ret = 0;
             ret = adapter.UpdateById(txtGiftName.Text.Trim(), Convert.ToDecimal(txtPrice.Text), Convert.ToDecimal(txtStockNum.Text), mId);
             if (ret > 0)
             {
                 MessageBox.Show("修改成功!");
                 btnAdd.Enabled = false;
                 return;
             }
             else
             {
                 MessageBox.Show("修改失败");
                 return;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }