예제 #1
0
        /// <summary>
        /// 计算税率
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gvProSoldOut_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            try
            {
                DataRow row     = gvProSoldOut.GetDataRow(e.RowHandle);
                string  taxCode = row[gcTaxCode.FieldName] != null ? row[gcTaxCode.FieldName].ToString() : string.Empty;
                if (e.Column.Name == "gcTotalMoney")
                {
                    int   num               = row[gcCount.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalCount.FieldName].ToString()) ? int.Parse(row[gcTotalCount.FieldName].ToString()) : 1;
                    float totalFee          = e.Value != null && e.Value.ToString() != string.Empty ? float.Parse(e.Value.ToString()) : 0;
                    float taxFee            = row[gcTaxFee.FieldName] != null && !string.IsNullOrEmpty(row[gcTaxFee.FieldName].ToString()) ? float.Parse(row[gcTaxFee.FieldName].ToString()) : 0;
                    float tax               = row[gcTax.FieldName] != null && !string.IsNullOrEmpty(row[gcTax.FieldName].ToString()) ? float.Parse(row[gcTax.FieldName].ToString()) : 0;
                    float price             = row[gcPrice.FieldName] != null && !string.IsNullOrEmpty(row[gcPrice.FieldName].ToString()) ? float.Parse(row[gcPrice.FieldName].ToString()) : 0;
                    float feeNotContainsTax = row[gcFeeNotContainsTax.FieldName] != null && !string.IsNullOrEmpty(row[gcFeeNotContainsTax.FieldName].ToString()) ? float.Parse(row[gcFeeNotContainsTax.FieldName].ToString()) : 0;

                    if (totalFee == 0)
                    {
                        taxFee            = 0;
                        price             = 0;
                        feeNotContainsTax = 0;
                    }
                    else
                    {
                        taxFee            = inoutHelper.CaculateTaxFee(taxCode, tax, taxFee, totalFee);
                        feeNotContainsTax = totalFee - taxFee;
                        price             = totalFee / num;
                    }

                    gvProSoldOut.BeginUpdate();
                    row[gcCount.FieldName]             = num;
                    row[gcTotalMoney.FieldName]        = totalFee;
                    row[gcTaxFee.FieldName]            = taxFee;
                    row[gcPrice.FieldName]             = price;
                    row[gcFeeNotContainsTax.FieldName] = feeNotContainsTax;
                    gvProSoldOut.EndUpdate();
                    //textEditTotalFee.Text = GetNeedToPay().ToString();
                }
                else if (e.Column.Name == "gcTax")
                {
                    int   num               = row[gcTotalCount.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalCount.FieldName].ToString()) ? int.Parse(row[gcTotalCount.FieldName].ToString()) : 1;
                    float totalFee          = row[gcTotalMoney.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalMoney.FieldName].ToString()) ? int.Parse(row[gcTotalMoney.FieldName].ToString()) : 0;
                    float taxFee            = row[gcTaxFee.FieldName] != null && !string.IsNullOrEmpty(row[gcTaxFee.FieldName].ToString()) ? float.Parse(row[gcTaxFee.FieldName].ToString()) : 0;
                    float tax               = e.Value != null && e.Value.ToString() != string.Empty ? float.Parse(e.Value.ToString()) : 0;
                    float price             = row[gcPrice.FieldName] != null && !string.IsNullOrEmpty(row[gcPrice.FieldName].ToString()) ? float.Parse(row[gcPrice.FieldName].ToString()) : 0;
                    float feeNotContainsTax = row[gcFeeNotContainsTax.FieldName] != null && !string.IsNullOrEmpty(row[gcFeeNotContainsTax.FieldName].ToString()) ? float.Parse(row[gcFeeNotContainsTax.FieldName].ToString()) : 0;

                    tax               = tax / 100;
                    taxFee            = inoutHelper.CaculateTaxFee(taxCode, tax, taxFee, totalFee);
                    feeNotContainsTax = totalFee - taxFee;

                    gvProSoldOut.BeginUpdate();
                    row[gcTax.FieldName]               = tax;
                    row[gcCount.FieldName]             = num;
                    row[gcTotalMoney.FieldName]        = totalFee;
                    row[gcTaxFee.FieldName]            = taxFee;
                    row[gcPrice.FieldName]             = price;
                    row[gcFeeNotContainsTax.FieldName] = feeNotContainsTax;
                    gvProSoldOut.EndUpdate();
                    //textEditTotalFee.Text = GetNeedToPay().ToString();
                }
                else if (e.Column.Name == "gcCount")
                {
                    int   num               = e.Value != null && e.Value.ToString() != string.Empty ? int.Parse(e.Value.ToString()) : 1;
                    float totalFee          = row[gcTotalMoney.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalMoney.FieldName].ToString()) ? int.Parse(row[gcTotalMoney.FieldName].ToString()) : 0;
                    float taxFee            = row[gcTaxFee.FieldName] != null && !string.IsNullOrEmpty(row[gcTaxFee.FieldName].ToString()) ? float.Parse(row[gcTaxFee.FieldName].ToString()) : 0;
                    float tax               = row[gcTax.FieldName] != null && !string.IsNullOrEmpty(row[gcTax.FieldName].ToString()) ? float.Parse(row[gcTax.FieldName].ToString()) : 0;
                    float price             = row[gcPrice.FieldName] != null && !string.IsNullOrEmpty(row[gcPrice.FieldName].ToString()) ? float.Parse(row[gcPrice.FieldName].ToString()) : 0;
                    float feeNotContainsTax = row[gcFeeNotContainsTax.FieldName] != null && !string.IsNullOrEmpty(row[gcFeeNotContainsTax.FieldName].ToString()) ? float.Parse(row[gcFeeNotContainsTax.FieldName].ToString()) : 0;

                    totalFee          = price * num;
                    taxFee            = inoutHelper.CaculateTaxFee(taxCode, tax, taxFee, totalFee);
                    feeNotContainsTax = totalFee - taxFee;

                    gvProSoldOut.BeginUpdate();
                    row[gcCount.FieldName]             = num;
                    row[gcTotalMoney.FieldName]        = totalFee;
                    row[gcTaxFee.FieldName]            = taxFee;
                    row[gcPrice.FieldName]             = price;
                    row[gcFeeNotContainsTax.FieldName] = feeNotContainsTax;
                    gvProSoldOut.EndUpdate();
                }
                else if (e.Column.Name == "gcPrice")
                {
                    int   num               = row[gcTotalCount.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalCount.FieldName].ToString()) ? int.Parse(row[gcTotalCount.FieldName].ToString()) : 1;
                    float totalFee          = row[gcTotalMoney.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalMoney.FieldName].ToString()) ? int.Parse(row[gcTotalMoney.FieldName].ToString()) : 0;
                    float taxFee            = row[gcTaxFee.FieldName] != null && !string.IsNullOrEmpty(row[gcTaxFee.FieldName].ToString()) ? float.Parse(row[gcTaxFee.FieldName].ToString()) : 0;
                    float tax               = row[gcTax.FieldName] != null && !string.IsNullOrEmpty(row[gcTax.FieldName].ToString()) ? float.Parse(row[gcTax.FieldName].ToString()) : 0;
                    float price             = e.Value != null && e.Value.ToString() != string.Empty ? float.Parse(e.Value.ToString()) : 0;;
                    float feeNotContainsTax = row[gcFeeNotContainsTax.FieldName] != null && !string.IsNullOrEmpty(row[gcFeeNotContainsTax.FieldName].ToString()) ? float.Parse(row[gcFeeNotContainsTax.FieldName].ToString()) : 0;

                    totalFee          = price * num;
                    taxFee            = inoutHelper.CaculateTaxFee(taxCode, tax, taxFee, totalFee);
                    feeNotContainsTax = totalFee - taxFee;

                    gvProSoldOut.BeginUpdate();
                    row[gcCount.FieldName]             = num;
                    row[gcTotalMoney.FieldName]        = totalFee;
                    row[gcTaxFee.FieldName]            = taxFee;
                    row[gcPrice.FieldName]             = price;
                    row[gcFeeNotContainsTax.FieldName] = feeNotContainsTax;
                    gvProSoldOut.EndUpdate();
                }
                else if (e.Column.Name == "gcFeeNotContainsTax")
                {
                    int   num               = row[gcCount.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalCount.FieldName].ToString()) ? int.Parse(row[gcTotalCount.FieldName].ToString()) : 1;
                    float totalFee          = row[gcTotalMoney.FieldName] != null && !string.IsNullOrEmpty(row[gcTotalMoney.FieldName].ToString()) ? int.Parse(row[gcTotalMoney.FieldName].ToString()) : 0;
                    float taxFee            = row[gcTaxFee.FieldName] != null && !string.IsNullOrEmpty(row[gcTaxFee.FieldName].ToString()) ? float.Parse(row[gcTaxFee.FieldName].ToString()) : 0;
                    float tax               = row[gcTax.FieldName] != null && !string.IsNullOrEmpty(row[gcTax.FieldName].ToString()) ? float.Parse(row[gcTax.FieldName].ToString()) : 0;
                    float price             = row[gcPrice.FieldName] != null && !string.IsNullOrEmpty(row[gcPrice.FieldName].ToString()) ? float.Parse(row[gcPrice.FieldName].ToString()) : 0;
                    float feeNotContainsTax = e.Value != null && e.Value.ToString() != string.Empty ? float.Parse(e.Value.ToString()) : 0;;

                    /*如果税率为0,则含税金额=不含税金额*/
                    if (tax == 0)
                    {
                        totalFee = feeNotContainsTax;
                    }
                    else
                    {
                        Tax t = InOutHelper.alltaxList.Find(c => c.TaxCode == taxCode);
                        if (t != null)
                        {
                            if (t.Formula == 1)
                            {
                                totalFee = feeNotContainsTax * (1 + tax);
                            }
                            else if (t.Formula == 2)
                            {
                                totalFee = feeNotContainsTax / (1 - tax);
                            }
                        }
                        else
                        {
                            totalFee = feeNotContainsTax / (1 - tax);
                        }
                    }
                    /*税额=含税金额-不含税金额*/
                    taxFee = totalFee - feeNotContainsTax;
                    /*单价=含税金额/数量*/
                    price = totalFee / num;

                    gvProSoldOut.BeginUpdate();
                    row[gcTotalCount.FieldName]        = num;
                    row[gcTotalMoney.FieldName]        = totalFee;
                    row[gcTaxFee.FieldName]            = taxFee;
                    row[gcPrice.FieldName]             = price;
                    row[gcFeeNotContainsTax.FieldName] = feeNotContainsTax;
                    gvProSoldOut.EndUpdate();
                }

                //展示总金额
                GetTaxAndFee();
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, Constants.SYSTEM_PROMPT, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }