private void 开票查看销售明细_Load(object sender, EventArgs e)
        {
            if (mInvoiceId < 0 || mSubId < 0)
            {
                MessageBox.Show("没有销售明细ID和子项ID");
                return;
            }
            //显示开票详细
            var mdtInvoiceDetails = new T_InvoiceOutStockTableAdapter().GetDataByInvoiceIdAndSubId(mInvoiceId, mSubId);

            if (mdtInvoiceDetails.Rows.Count > 0)
            {
                foreach (销售管理.DAL.DataSetInvoiceOutStock.T_InvoiceOutStockRow mRow in mdtInvoiceDetails.Rows)
                {
                    int mIndex = dgvInvoiceDetails.Rows.Add();

                    dgvInvoiceDetails["ColSaleDetailsId", mIndex].Value = mRow.SaleDetailsId;
                    //dgvInvoiceDetails["ColProductName", mIndex].Value = mRow.pr;
                    dgvInvoiceDetails["ColPrice", mIndex].Value    = mRow.Price;
                    dgvInvoiceDetails["ColAmount", mIndex].Value   = mRow.Amount;
                    dgvInvoiceDetails["ColSumMoney", mIndex].Value = mRow.SumMoney;

                    //dgvInvoiceDetails["ColSaleDate", mIndex].Value = mRow["SaleDate"];
                    //dgvInvoiceDetails["ColStockOutNo", mIndex].Value = mRow["StockOutNo"];
                }
                //dgvInvoiceDetails.SelectedRows[0].Selected = false;
            }
            dgvInvoiceDetails.ClearSelection();
            //显示销售明细
            string mSql;

            mSql = "SELECT a.Id, c.UserName,e.companyname customername, a.SaleDate, d.name as ProductName, a.Price, a.Amount,isnull(f.hasInvoice,0) hasInvoice,isnull(g.Invoicing,0) Invoicing,a.amount - isnull(f.hasinvoice,0) - isnull(g.invoicing,0) caninvoice, a.SumMoney,a.stockoutno FROM dbo.T_SaleDetails a left join T_Users c on a.UserName = c.Id left join T_Products d on a.productName = d.id left join t_customers e on a.customername = e.id left join (select saledetailsid,isnull(sum(amount),0) hasInvoice from t_invoiceoutstock a left join t_invoice b on a.invoiceid = b.id where b.status = '财务已开票' group by saledetailsid) f on a. id = f.saledetailsid left join (select saledetailsid,isnull(sum(amount),0) Invoicing from t_invoiceoutstock a left join t_invoice b on a.invoiceid = b.id where b.status like '%等待%' group by saledetailsid) g on g.saledetailsid = a.id where ascii(a.CustomerName) < 123 and  a.id in (select SaleDetailsId from t_InvoiceOutStock where invoiceId = " + mInvoiceId.ToString() + " and subid=" + mSubId.ToString() + ")";
            SqlConnection  conn    = new SqlConnection(global::Common.CommonClass.SqlConnStr);
            SqlDataAdapter adapter = new SqlDataAdapter(mSql, conn);
            DataTable      mTable  = new DataTable();

            try
            {
                adapter.Fill(mTable);
                dgvCustomerSaleDetails.DataSource = mTable;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
            dgvCustomerSaleDetails.ClearSelection();
        }
Exemple #2
0
        private void 申请开票_Load(object sender, EventArgs e)
        {
            //获取销售名单
            cmbUserName.DisplayMember = "UserName";
            cmbUserName.ValueMember   = "id";
            cmbUserName.DataSource    = new T_UsersTableAdapter().GetSalers();

            if (!Common.AuthenticateRight.AuthOperation(110402) && !CommonClass.SttUser.blSuperUser)
            {
                cmbUserName.SelectedValue = Classes.PubClass.UserId;//cmbUserName.fin (Classes.PubClass.UserName);
                cmbUserName.Enabled       = false;
            }

            if (mId > -1)
            {
                var table = new T_InvoiceQTableAdapter().GetDataById(mId);
                if (table.Rows.Count > 0)
                {
                    var row = (销售管理.DAL.DataSetInvoice.T_InvoiceQRow)table.Rows[0];
                    cmbUserName.SelectedIndex     = cmbUserName.FindStringExact(row.UserName);
                    cmbCustomerName.SelectedIndex = cmbCustomerName.FindStringExact(row.CustomerName);
                    string InvoiceContent = row.InvoiceContent;
                    //string[] contents = InvoiceContent.Split(new string[]{"!#!"},StringSplitOptions.None);
                    string[] contents = System.Text.RegularExpressions.Regex.Split(InvoiceContent, "!#!");
                    for (int i = 0; i < contents.Length - 3; i += 4)
                    {
                        Control control;
                        control      = groupBox1.Controls.Find("txtName" + (mCount).ToString(), false)[0];
                        control.Text = contents[i];
                        control      = groupBox1.Controls.Find("txtPrice" + (mCount).ToString(), false)[0];
                        control.Text = contents[i + 1];
                        control      = groupBox1.Controls.Find("txtNum" + (mCount).ToString(), false)[0];
                        control.Text = contents[i + 2];
                        control      = groupBox1.Controls.Find("txtSum" + (mCount).ToString(), false)[0];
                        control.Text = contents[i + 3];
                        //加载mInvoiceDetails
                        DataTable mSelected = new DataTable();
                        //添加标头
                        mSelected.Columns.Add("SaleDetailsId");
                        mSelected.Columns.Add("ProductName");
                        mSelected.Columns.Add("Price");
                        mSelected.Columns.Add("Amount");
                        mSelected.Columns.Add("SumMoney");
                        mSelected.Columns.Add("StockOutNo");
                        mSelected.Columns.Add("SaleDate");
                        //添加数据
                        var mdtInvoiceDetails = new T_InvoiceOutStockTableAdapter().GetDataByInvoiceIdAndSubId(mId, mCount);
                        if (mdtInvoiceDetails.Rows.Count > 0)
                        {
                            foreach (销售管理.DAL.DataSetInvoiceOutStock.T_InvoiceOutStockRow mRow in mdtInvoiceDetails.Rows)
                            {
                                mSelected.Rows.Add(mRow.SaleDetailsId, "", mRow.Price, mRow.Amount, mRow.SumMoney, "", "");
                            }
                        }
                        mInvoiceDatails[mCount] = mSelected;

                        if (i < contents.Length - 7)
                        {
                            linkLabel1_LinkClicked(sender, new LinkLabelLinkClickedEventArgs(new LinkLabel.Link(), MouseButtons.Left));
                        }
                    }
                    if (isModify == false)
                    {
                        foreach (Control control in groupBox1.Controls)
                        {
                            if (control.GetType() == typeof(LinkLabel))
                            {
                                control.Enabled = false;
                            }
                        }
                    }
                    dtpInvioceDate.Value = row.InvoiceDate;
                    cmbInvoiceType.Text  = row.InvoiceType;
                    txtInvoiceNo.Text    = row.InvoiceNo;
                    txtMoney.Text        = row.InvoiceMoney.ToString("0.00");
                    txtStatus.Text       = row.Status;
                    labStatus.Visible    = true;
                    txtStatus.Visible    = true;

                    btnPrint.Visible = true;
                    if (txtStatus.Text.Contains("不通过") == true && isModify == true)
                    {
                        btnSave.Enabled  = true;
                        btnDetails1.Text = "选择";
                    }
                    else
                    {
                        btnSave.Enabled  = false;
                        btnDetails1.Text = "查看";
                    }
                }
            }
        }
Exemple #3
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);
            }
        }