private void dgvInvoice_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         if (e.ColumnIndex == dgvInvoice.Columns["ColAudit"].Index)
         {
             if (DialogResult.Yes == MessageBox.Show("确认审核通过?", "提示", MessageBoxButtons.YesNo))
             {
                 int ret = new T_InvoiceTableAdapter().UpdateBusinessAudit(Classes.PubClass.UserId, "商务已审核等待财务审核", Convert.ToInt64(dgvInvoice.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                 if (ret > 0)
                 {
                     MessageBox.Show("提交成功");
                     dgvInvoice.Rows.RemoveAt(e.RowIndex);
                 }
                 else
                 {
                     MessageBox.Show("提交失败");
                 }
             }
         }
         if (e.ColumnIndex == dgvInvoice.Columns["ColAudit1"].Index)
         {
             if (DialogResult.Yes == MessageBox.Show("确认审核不通过?", "提示", MessageBoxButtons.YesNo))
             {
                 int ret = new T_InvoiceTableAdapter().UpdateBusinessAudit(Classes.PubClass.UserId, "商务审核不通过", Convert.ToInt64(dgvInvoice.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                 if (ret > 0)
                 {
                     MessageBox.Show("提交成功");
                     dgvInvoice.Rows.RemoveAt(e.RowIndex);
                 }
                 else
                 {
                     MessageBox.Show("提交失败");
                 }
             }
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            Decimal Money, MaxMoney;

            try
            {
                if (cmbUserName.SelectedIndex == -1)
                {
                    toolTip1.Show("请选择销售人员", cmbUserName, 0, cmbUserName.Height, 2000);
                    return;
                }
                if (cmbCustomerName.SelectedIndex == -1)
                {
                    toolTip1.Show("请选择客户名称", cmbCustomerName, 0, cmbCustomerName.Height, 2000);
                    return;
                }
                if (Decimal.TryParse(txtMoney.Text, out Money) == false)
                {
                    toolTip1.Show("金额必须输入数字", txtMoney, 0, txtMoney.Height, 2000);
                    return;
                }
                //组InvoiceContent
                string InvoiceContent = string.Empty;
                for (int i = 1; i <= mCount; i++)
                {
                    Control control;
                    //名称
                    control = groupBox1.Controls.Find("txtName" + i.ToString(), false)[0];
                    if (control.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请输入开票名称" + i.ToString());
                        return;
                    }
                    InvoiceContent += control.Text.Trim() + "!#!";

                    //单价
                    control = groupBox1.Controls.Find("txtPrice" + i.ToString(), false)[0];
                    if (control.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请选择出库单" + i.ToString());
                        return;
                    }
                    InvoiceContent += control.Text.Trim() + "!#!";

                    //数量
                    control = groupBox1.Controls.Find("txtNum" + i.ToString(), false)[0];
                    if (control.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请选择出库单" + i.ToString());
                        return;
                    }
                    InvoiceContent += control.Text.Trim() + "!#!";

                    //金额
                    control = groupBox1.Controls.Find("txtSum" + i.ToString(), false)[0];
                    if (control.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("请选择出库单" + i.ToString());
                        return;
                    }
                    InvoiceContent += control.Text.Trim() + "!#!";
                }
                InvoiceContent = InvoiceContent.TrimEnd("!#!".ToCharArray()); //去除最后的分隔符

                //MaxMoney = Decimal.Parse(txtMaxMoney.Text);//最大可开金额
                //if (MaxMoney < Money)
                //{
                //    toolTip1.Show("金额不能大于最大可开金额", txtMoney, 0, txtMoney.Height, 2000);
                //    return;
                //}

                T_InvoiceTableAdapter adapter = new T_InvoiceTableAdapter();
                int  ret       = 0;
                long InvoiceId = 0;
                //if (mId == -1)
                //{

                using (var mConn = new SqlConnection(Common.CommonClass.SqlConnStr))
                {
                    mConn.Open();
                    using (var mTrans = mConn.BeginTransaction())
                    {
                        try
                        {
                            adapter.Connection  = mConn;
                            adapter.Transaction = mTrans;
                            InvoiceId           = (long)adapter.MyInsert(Convert.ToInt64(cmbUserName.SelectedValue), Convert.ToInt64(cmbCustomerName.SelectedValue), InvoiceContent, dtpInvioceDate.Value.Date, cmbInvoiceType.Text, Money, null, null, null, null, "已提交等待商务审核");
                            if (InvoiceId > 0)
                            {
                                T_InvoiceOutStockTableAdapter adInvoiceOutStock = new T_InvoiceOutStockTableAdapter();
                                adInvoiceOutStock.Connection  = mConn;
                                adInvoiceOutStock.Transaction = mTrans;
                                decimal canInvoice = 0;
                                T_InvoiceNumTableAdapter inAdapter = new T_InvoiceNumTableAdapter();
                                inAdapter.Connection  = mConn;
                                inAdapter.Transaction = mTrans;
                                for (int i = 1; i <= mCount; i++)                           //开票条目
                                {
                                    for (int m = 0; m < mInvoiceDatails[i].Rows.Count; m++) // 每个条目下的开票出库详细
                                    {
                                        //获取销售销售记录的当前最大可开票数量
                                        canInvoice = 0;
                                        canInvoice = Convert.ToDecimal(inAdapter.GetCanInvoiceNum(Convert.ToInt64(mInvoiceDatails[i].Rows[m]["SaleDetailsId"])));
                                        if (canInvoice < Convert.ToDecimal(mInvoiceDatails[i].Rows[m]["Amount"]))
                                        {
                                            mTrans.Rollback();
                                            MessageBox.Show("开票内容" + i.ToString() + "中的第" + (m + 1).ToString() + "条记录超过可开票数量");
                                            return;
                                        }
                                        ret = adInvoiceOutStock.Insert(InvoiceId, i, Convert.ToInt64(mInvoiceDatails[i].Rows[m]["SaleDetailsId"]), Convert.ToDecimal(mInvoiceDatails[i].Rows[m]["Price"]), Convert.ToDecimal(mInvoiceDatails[i].Rows[m]["Amount"]), Convert.ToDecimal(mInvoiceDatails[i].Rows[m]["SumMoney"]));
                                        if (ret < 1)
                                        {
                                            mTrans.Rollback();
                                            MessageBox.Show("提交失败");
                                        }
                                    }
                                }
                                mTrans.Commit();
                                MessageBox.Show("提交成功");
                                btnSave.Enabled = false;
                            }
                            else
                            {
                                mTrans.Rollback();
                                MessageBox.Show("提交失败");
                            }
                        }

                        catch (Exception ex)
                        {
                            mTrans.Rollback();
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #3
0
        private void dgvInvoice_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == dgvInvoice.Columns["ColAudit"].Index)
                {
                    using (var mForm = new 开票审核_输入发票号())
                    {
                        if (DialogResult.OK == mForm.ShowDialog())
                        {
                            string InvoiceNo = mForm.txtInvoiceNo.Text.Trim();
                            int    ret       = new T_InvoiceTableAdapter().UpdateFinanceAudit("财务已开票", Classes.PubClass.UserId, InvoiceNo, Convert.ToInt64(dgvInvoice.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                            if (ret > 0)
                            {
                                MessageBox.Show("提交成功");
                                dgvInvoice.Rows.RemoveAt(e.RowIndex);
                            }
                            else
                            {
                                MessageBox.Show("提交失败");
                            }
                        }
                    }
                }
                if (e.ColumnIndex == dgvInvoice.Columns["ColAudit1"].Index)
                {
                    if (DialogResult.Yes == MessageBox.Show("确认审核不通过?", "提示", MessageBoxButtons.YesNo))
                    {
                        int ret = new T_InvoiceTableAdapter().UpdateFinanceAudit("财务审核不通过", Classes.PubClass.UserId, null, Convert.ToInt64(dgvInvoice.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                        if (ret > 0)
                        {
                            MessageBox.Show("提交成功");
                            dgvInvoice.Rows.RemoveAt(e.RowIndex);
                        }
                        else
                        {
                            MessageBox.Show("提交失败");
                        }
                    }
                }
                if (e.ColumnIndex == dgvInvoice.Columns["ColModify"].Index)
                {
                    using (var mForm = new 开票审核_输入发票号())
                    {
                        if (DialogResult.OK == mForm.ShowDialog())
                        {
                            int ret = new T_InvoiceTableAdapter().UpdateInvoiceNo(mForm.txtInvoiceNo.Text.Trim(), Convert.ToInt64(dgvInvoice.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                            if (ret > 0)
                            {
                                MessageBox.Show("提交成功");
                            }
                            else
                            {
                                MessageBox.Show("提交失败");
                            }
                        }
                    }
                }
                if (e.ColumnIndex == ColCancel.Index)
                {
                    if (MessageBox.Show("确定作废吗?", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        int ret = new T_InvoiceTableAdapter().UpdateFinanceAudit("发票作废", Classes.PubClass.UserId, dgvInvoice.Rows[e.RowIndex].Cells[invoiceNoDataGridViewTextBoxColumn.Index].Value.ToString(), Convert.ToInt64(dgvInvoice.Rows[e.RowIndex].Cells["idDataGridViewTextBoxColumn"].Value));
                        if (ret > 0)
                        {
                            MessageBox.Show("提交成功");
                            btnSerch.PerformClick();
                            //dgvInvoice.Rows.RemoveAt(e.RowIndex);
                        }
                        else
                        {
                            MessageBox.Show("提交失败");
                        }
                    }
                }
                //if (e.ColumnIndex == dgvInvoice.Columns["ColCombine"].Index && Classes.PubClass.UserStatus == "正常")
                //{
                //    string mCompanyName = "651984618945316891318";
                //    int mCount = 0;
                //    foreach (DataGridViewRow mRow in dgvInvoice.Rows)
                //    {
                //        if (Convert.ToBoolean(mRow.Cells["ColPrint"].Value) == true)
                //        {
                //            mCompanyName = mRow.Cells["customerNameDataGridViewTextBoxColumn"].Value.ToString();
                //            mCount++;
                //        }

                //    }
                //    if (mCount >= 20)
                //    {
                //        MessageBox.Show("选中的个数不能超过20个");
                //        return;
                //    }
                //    if (mCompanyName != "651984618945316891318" && Convert.ToString(dgvInvoice.Rows[e.RowIndex].Cells["customerNameDataGridViewTextBoxColumn"].Value) != mCompanyName)
                //    {
                //        DataGridViewCheckBoxCell mCell = dgvInvoice[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
                //        mCell.EditingCellFormattedValue = false;
                //        mCell.EditingCellValueChanged = true;
                //        mCell.Value = mCell.FormattedValue;
                //        MessageBox.Show("与已选择的公司名称不一致");
                //    }
                //    else
                //    {
                //        DataGridViewCheckBoxCell mCell = dgvInvoice[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
                //        mCell.EditingCellFormattedValue = bool.Parse(mCell.EditedFormattedValue.ToString());
                //        mCell.EditingCellValueChanged = true;
                //        mCell.Value = mCell.FormattedValue;
                //    }
                //}
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }