using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CK.SCP.Common; using CK.SCP.Controller; using CK.SCP.Models.Enums; using CK.SCP.Models.ScpEntity; using CK.SCP.Utils; using FineUI; using System.Drawing; namespace SCP.Views.锦州锦恒.SupplierData { public partial class SCP_INVOICE_EDIT : PageBase { protected void Page_Load(object sender, EventArgs e) { IsRoleRight(); if (!IsPostBack) { TranslatorAgents(Toolbar2); TranslatorAgent(Grid1); TranslatorAgents(FormRow_1); TranslatorAgents(FormRow_2); TranslatorAgents(FormRow_3); TranslatorAgents(FormRow_4); BindData(); //GetInvoice(); SetRoleRule(); } } public void IsRoleRight() { //if (!CurrentUser.RoleList.Contains("供应商")) //{ // Alert.Show("当前用户角色不能操作该模块!"); // return; //} //if (CurrentUser.VenderList == null || CurrentUser.VenderList.Count == 0) //{ // Alert.Show("当前用户未选择地点!"); // return; //} } private void SetRoleRule() { //IsPriceVisible(Grid1, "合同价格"); //IsPriceVisible(Grid1, "合同差额"); IsPriceVisible(Grid1, "要货日期"); } public decimal ToDecimal(decimal num, int scale) { decimal tempOdds = Math.Round(num, scale); //if (tempOdds > num) //{ // num = (decimal)((double)(tempOdds - (decimal)Math.Pow(10, -scale))); //} //else //{ // num = (decimal)((double)tempOdds); //} //return num; return tempOdds; } private void Search(Action> p_list) { string id = GetQueryValue("ID"); V_TB_INVOICE_DETAIL _tb = new V_TB_INVOICE_DETAIL(); _tb.InvcBillNum = id; SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_DETAIL_List(_tb, (ret) => { if (ret.State == ReturnStatus.Succeed) { p_list(ret.Result); } }); } public void BindData() { Search(ret => { Grid1.RecordCount = ret.Count(); var list = SortAndPage(ret, Grid1); //Grid1.DataSource =SCP_RECIVECE_CONTROLLER.Get_V_TB_INVOICE_LIST(list.ToList()); List temp = SCP_RECIVECE_CONTROLLER.Get_V_TB_INVOICE_LIST(list.ToList()); temp = SCP_CONTRACT_CONTROLLER.GET_CONTRACT_PRICE_LIST(temp); //decimal htjgSum = 0;//合同总价 //decimal htceSum = 0;//合同差额 //foreach (V_TB_INVOICE_DETAIL rec in temp) //{ // rec.Qty = ToDecimal(rec.Qty, 2); // rec.CanQty = ToDecimal(rec.CanQty, 2); // htjgSum += rec.Qty * (rec.ContractPrice == null ? 0 : Convert.ToDecimal(rec.ContractPrice));//开票数量*合同价格 // htceSum += rec.Qty * (rec.BlancePrice == null ? 0 : Convert.ToDecimal(rec.BlancePrice));//开票数量*合同差额 //} //txtContractPrice1.Text = htjgSum.ToString(); //txtBlancePrice1.Text = htceSum.ToString(); GetInvoice(); Grid1.DataSource = temp; Grid1.DataBind(); }); } private void GetInvoice() { string id = GetQueryValue("ID"); string vendid = ""; if (CurrentUser.VenderList != null && CurrentUser.VenderList.Count > 0) { vendid = CurrentUser.VenderList[0]; } SCP_INVOICE_CONTROLLER.Get_V_TB_INVOICE_List(new V_TB_INVOICE { InvcBillNum = id, VendId = vendid }, (ret) => { if (ret.State == ReturnStatus.Succeed) { var _ls = ret.Result.ToList(); if (_ls != null && _ls.Count > 0) { var _Model = _ls[0]; Session["Invoice"] = _Model; txtState.Text = _Model.State_DESC; txtBillNo.Text = _Model.InvcBillNum; txtBillTime.Text = Convert.ToDateTime(_Model.CreateTime).ToString("yyyy-MM-dd"); txtSupplierName.Text = _Model.VendName; txtInvoiceNumber.Text = _Model.InvoiceNum; txtExpressNumber.Text = _Model.ExpressNum; dpUpdateTime.SelectedDate = _Model.UpdateTime; txtTax.SelectedValue = _Model.Tax != null ? _Model.Tax.Value.ToString() : "0"; txtTaxAmount.Text = _Model.TaxAmount != null ? _Model.TaxAmount.Value.ToString() : "0"; txtDiscountPrice1.Text = _Model.DiscountPrice != null ? _Model.DiscountPrice.ToString() : string.Empty; txtBlancePrice1.Text = _Model.BlancePrice != null ? _Model.BlancePrice.ToString() : string.Empty; txtAmount.Text = _Model.Amount.ToString(); txtTotal.Text = _Model.Total != null ? _Model.Total.ToString() : string.Empty; txtExtend1.Text = _Model.Extend1 != null ? _Model.Extend1.ToString() : string.Empty; txtExtend2.Text = _Model.Extend2 != null ? _Model.Extend2.ToString() : string.Empty; txtRealTotal.Text = _Model.RealTotal != null ? _Model.RealTotal.ToString() : string.Empty; txtMemo.Text = _Model.Remark; if (_Model.State == (int)InvoiceState.New || _Model.State == (int)InvoiceState.CheckFail) { this.btnOK.Hidden = false; this.btnApply.Hidden = false; this.btnReject.Hidden = false; } if (_Model.State == (int)InvoiceState.Reject) { this.btnReject.Hidden = true; this.btnOK.Hidden = false; } if (_Model.State == (int)InvoiceState.Apply) { this.btnOK.Hidden = true; this.btnApply.Hidden = true;//提交申请 this.btnReject.Hidden = true;//发票作废 this.btnMail.Hidden = true;//寄出发票 } if (_Model.State == (int)InvoiceState.Mail) { this.btnOK.Hidden = true;//确定修改 this.btnApply.Hidden = true;//提交申请 this.btnReject.Hidden = true;//发票作废 this.btnMail.Hidden = true;//寄出发票 txtInvoiceNumber.Readonly = true; txtInvoiceNumber.Required = false; txtExpressNumber.Readonly = true; txtExpressNumber.Required = false; txtDiscountPrice1.Readonly = true; txtDiscountPrice1.Required = false; txtDiscountPrice1.Enabled = false; txtBlancePrice1.Readonly = true; txtBlancePrice1.Required = false; txtBlancePrice1.Enabled = false; txtExtend1.Readonly = true; txtExtend1.Required = false; txtExtend1.Enabled = false; txtExtend2.Readonly = true; txtExtend2.Required = false; txtExtend2.Enabled = false; txtTax.Enabled = false; Label1.Enabled = false; } if (_Model.State == (int)InvoiceState.FinanceFail || _Model.State == (int)InvoiceState.CheckSuccess) { txtInvoiceNumber.Readonly = false; txtInvoiceNumber.Required = true; txtExpressNumber.Readonly = false; txtDiscountPrice1.Readonly = false; txtDiscountPrice1.Required = true; txtDiscountPrice1.Enabled = true; txtExtend1.Readonly = false; txtExtend1.Required = true; txtExtend1.Enabled = true; txtExtend2.Readonly = false; txtExtend2.Required = false; txtExtend2.Enabled = true; txtBlancePrice1.Readonly = false; txtBlancePrice1.Required = false; this.btnMail.Hidden = false; this.btnReject.Hidden = false; this.btnOK.Hidden = false; txtInvoiceNumber.Enabled = true; txtExpressNumber.Enabled = true; dpUpdateTime.Enabled = true; } if (_Model.State == (int)InvoiceState.CheckSuccess) { this.btnOK.Hidden = true; txtMemo.Enabled = false; for (int i = 0, count = Grid1.Rows.Count; i < count; i++) { object[] rowDataKeys = Grid1.DataKeys[i]; GridRow row = Grid1.Rows[i]; var txtPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtPrice"); var txtQty = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty"); var txtLineMemo = (System.Web.UI.WebControls.TextBox)row.FindControl("txtLineMemo"); txtPrice.ReadOnly = true; txtPrice.Enabled = false; txtQty.ReadOnly = true; txtQty.Enabled = false; txtLineMemo.ReadOnly = true; txtLineMemo.Enabled = false; } } } } }); } protected void btnOK_Click(object sender, EventArgs e) { var _invoice = Session["Invoice"] as V_TB_INVOICE; string InvoiceNumber = MyWebString.GetString(this.txtInvoiceNumber.Text.Trim()); string Memo = MyWebString.GetString(this.txtMemo.Text.Trim()); string ExpressNumber = MyWebString.GetString(this.txtExpressNumber.Text.Trim()); string DiscountPrice1 = MyWebString.GetString(this.txtDiscountPrice1.Text.Trim());//折扣 string BlancePrice1 = MyWebString.GetString(this.txtBlancePrice1.Text.Trim());//税额调整 string Extend1 = MyWebString.GetString(this.txtExtend1.Text.Trim());//实际发票税前金额 string Extend2 = MyWebString.GetString(this.txtExtend2.Text.Trim());//实际发票税额 //if (_invoice.State != (int)InvoiceState.New && // _invoice.State != (int)InvoiceState.CheckFail) //{ // Alert.Show(_invoice.InvcBillNum + " 不允许修改,只有状态为 " + "新建" + " 或 " + // "采购退回" + " 才能修改"); // return; //} if (!string.IsNullOrEmpty(txtTax.SelectedValue)) { _invoice.Tax = decimal.Parse(txtTax.SelectedValue); } _invoice.InvoiceNum = InvoiceNumber; _invoice.Remark = Memo; _invoice.ExpressNum = ExpressNumber; //_invoice.UpdateTime = dpUpdateTime.SelectedDate.Value; //_invoice.State = (int)InvoiceState.Apply; if (string.IsNullOrEmpty(Extend1)) { _invoice.Extend1 = 0; } if (string.IsNullOrEmpty(Extend2)) { _invoice.Extend2 = 0; } if (string.IsNullOrEmpty(DiscountPrice1)) { _invoice.DiscountPrice = 0; } if (string.IsNullOrEmpty(BlancePrice1)) { _invoice.BlancePrice = 0; } if (_invoice.State == (int)InvoiceState.CheckSuccess) { if (dpUpdateTime.SelectedDate == null) { Alert.Show("发票时间必须填写,时间为纸质发票开票时间"); return; } else { _invoice.UpdateTime = dpUpdateTime.SelectedDate.Value; } } decimal c1; decimal b1; decimal d1; decimal e1; if (decimal.TryParse(DiscountPrice1, out c1)) { _invoice.DiscountPrice = c1; } if (decimal.TryParse(Extend1, out d1)) { _invoice.Extend1 = d1; } if (decimal.TryParse(Extend2, out e1)) { _invoice.Extend2 = e1; } if (decimal.TryParse(BlancePrice1, out b1)) { _invoice.BlancePrice = b1; } List _ls = new List(); if (this.txtQty.ReadOnly == false) { for (int i = 0, count = Grid1.Rows.Count; i < count; i++) { object[] rowDataKeys = Grid1.DataKeys[i]; GridRow row = Grid1.Rows[i]; V_TB_INVOICE_DETAIL _entity = new V_TB_INVOICE_DETAIL(); _entity.UID = ConvertHelper.To(rowDataKeys[0]); _entity.InvcBillNum = rowDataKeys[1] as string; _entity.Qty = ConvertHelper.To(rowDataKeys[2]); _entity.CanQty = ConvertHelper.To(rowDataKeys[3]); _entity.State = ConvertHelper.To(rowDataKeys[4]); var txtQty = (System.Web.UI.WebControls.TextBox)row.FindControl("txtQty"); var txtPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtPrice"); var txtLineMemo = (System.Web.UI.WebControls.TextBox)row.FindControl("txtLineMemo"); //var txtContractPrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtContractPrice"); //var txtBlancePrice = (System.Web.UI.WebControls.TextBox)row.FindControl("txtBlancePrice"); decimal QtyNew = 0; try { if (txtQty.Text.Trim() != "") { QtyNew = Convert.ToDecimal(txtQty.Text.Trim()); } } catch { Alert.Show("开票数量输入不正确"); return; } if (QtyNew > _entity.CanQty + _entity.Qty) { Alert.Show("开票数量不能大于可用开数票"); return; } decimal PriceNew = 0; try { if (txtPrice.Text.Trim() != "") { PriceNew = Convert.ToDecimal(txtPrice.Text.Trim()); } } catch { Alert.Show("单价输入不正确"); return; } _entity.Remark = txtLineMemo.Text; _entity.Price = PriceNew; _entity.Qty = QtyNew; _ls.Add(_entity); } } if (_ls.Count > 0) { var ret = SCP_INVOICE_CONTROLLER.SAVE_TB_INVOICE_APPLY(_invoice, _ls); if (ret.State == ReturnStatus.Succeed) { Alert.Show("发票明细修改成功!"); BindData(); } } else { Alert.Show("更改记录数为零"); } } private void SET_INVOICE_STATE(string p_msg, InvoiceState p_state) { if (Session["Invoice"] != null) { var _Invoice = Session["Invoice"] as V_TB_INVOICE; string InvoiceNumber = MyWebString.GetString(this.txtInvoiceNumber.Text.Trim());//金税票号 string ExpressNumber = MyWebString.GetString(this.txtExpressNumber.Text.Trim());//快递单号 string Extend1 = MyWebString.GetString(this.txtExtend1.Text.Trim());//折扣价格 string Extend2 = MyWebString.GetString(this.txtExtend2.Text.Trim());//折扣价格 string DiscountPrice1 = MyWebString.GetString(this.txtDiscountPrice1.Text.Trim());//折扣价格 string BlancePrice1 = MyWebString.GetString(this.txtBlancePrice1.Text.Trim());//合同差额 _Invoice.InvoiceNum = InvoiceNumber; _Invoice.ExpressNum = ExpressNumber; _Invoice.UpdateTime = dpUpdateTime.SelectedDate; if (string.IsNullOrEmpty(Extend1)) { _Invoice.Extend1 = 0; } if (string.IsNullOrEmpty(Extend2)) { _Invoice.Extend2 = 0; } if (string.IsNullOrEmpty(DiscountPrice1)) { _Invoice.DiscountPrice = 0; } if (string.IsNullOrEmpty(BlancePrice1)) { _Invoice.BlancePrice = 0; } decimal c1; decimal b1; decimal d1; decimal e1; if (decimal.TryParse(Extend1, out d1)) { _Invoice.Extend1 = d1; } else { _Invoice.Extend1 = 0; } if (decimal.TryParse(Extend2, out e1)) { _Invoice.Extend2 = e1; } else { _Invoice.Extend2 = 0; } if (decimal.TryParse(DiscountPrice1, out c1)) { _Invoice.DiscountPrice = c1; } else { _Invoice.ContractPrice = 0; } if (decimal.TryParse(BlancePrice1, out b1)) { _Invoice.BlancePrice = b1; } else { _Invoice.BlancePrice = 0; } if (p_state == InvoiceState.Mail) { if (string.IsNullOrEmpty(InvoiceNumber)) { Alert.Show("请填写金税票号!"); return; } if (string.IsNullOrEmpty(ExpressNumber)) { Alert.Show("请填写快递单号!"); return; } if (dpUpdateTime.SelectedDate == null) { Alert.Show("发票时间必须填写,时间为纸质发票开票时间"); return; } if (_Invoice.Extend1 == 0) { Alert.Show("发票实际税前金额(纸质发票税前金额)必须填写!"); return; } if (_Invoice.Extend2 == 0) { Alert.Show("发票实际税额(纸质发票税额)必须填写!"); return; } } var ret = SCP_INVOICE_CONTROLLER.SAVE_TB_INVOICE_STATE(_Invoice, p_state, CurrentUser.ChineseName); if (ret.State == ReturnStatus.Succeed) { Alert.Show(p_msg); BindData(); // GetInvoice(); } else { Alert.Show(ret.Message); } } } protected void btnApply_Click(object sender, EventArgs e) { SET_INVOICE_STATE("发票申请成功!", InvoiceState.Apply); } protected void btnMail_Click(object sender, EventArgs e) { SET_INVOICE_STATE("发票已经寄出!", InvoiceState.Mail); } protected void btnReject_Click(object sender, EventArgs e) { SET_INVOICE_STATE("发票已经作废!", InvoiceState.Reject); } protected void Window1_OnClose(object sender, WindowCloseEventArgs e) { //string id = GetQueryValue("ID"); //TB_INVOICE model = InvoiceController.GetDataByBillInvoiceBillNum(id); //InvoiceController.UpdateDataRemark(e.CloseArgument, model); } protected void btnRed_Click(object sender, EventArgs e) { string id = GetQueryValue("ID"); V_TB_INVOICE _tb = new V_TB_INVOICE(); _tb.InvcBillNum = id; var ret = SCP_INVOICE_CONTROLLER.Add_New_Red_Invoice(_tb); if (ret.State == ReturnStatus.Succeed) { BindData(); // GetInvoice(); } } protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { System.Web.UI.WebControls.TextBox _label = (System.Web.UI.WebControls.TextBox)Grid1.Rows[e.RowIndex].FindControl("txtQty"); if (!string.IsNullOrEmpty(_label.Text)) { if (decimal.Parse(_label.Text) < 0) { _label.ForeColor = Color.Red; } } } } }