using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading; using System.Collections; using System.Reflection; using CoreFS.CA06; namespace Core.StlMes.Client.Sale.UI.Balance.BalanceAccount { public partial class FrmBalanceInvoceMgtOrg : Core.StlMes.Client.Sale.Common.FrmStyleBase.FrmUIBase { public FrmBalanceInvoceMgtOrg() { InitializeComponent(); } private DataSet dsInvoice = new DataSet(); private DataSet dsInvoiceDetail = null; private DataSet dsInvoiceSeq = new DataSet(); private DataSet dsInvoiceList = new DataSet(); private void initDataSource() { dsInvoice = base.GetDataSetByColumnName(this.GetGrid1DataStruct(), null, GetColumnAndCaption()); this.ultraGrid1.DataSource = dsInvoice; dsInvoiceSeq = base.GetDataSetByColumnName(this.GetGrid2DataStruct(), null, GetColumnAndCaption()); this.ultraGrid2.DataSource = dsInvoiceSeq; dsInvoiceList = base.GetDataSetByColumnName(this.GetGrid3DataStruct(), null, GetColumnAndCaption()); this.ultraGrid3.DataSource = dsInvoiceList; } private void HiddenColumn() { try { this.ultraGrid2.DisplayLayout.Bands[0].Columns[this.INVOICENO].Hidden = true; this.ultraGrid2.DisplayLayout.Bands[0].Columns[this.INVOICENO_SEQ].Hidden = true; this.ultraGrid1.DisplayLayout.Bands[0].Columns["REALINVOICENO"].Hidden = true; } catch { } } protected override List GetNumberColumn() { return new List(new string[] { "SEND_NUM", "MONEY", "WEIGHT", "QUANTITY", "ACT_WGT", "OUTSTOCKMNY", "TRANSMNY", "PRICE", "PRICE_ORG", "MONEY_ORG", }); } private Core.StlMes.Client.Sale.BLL.SaleBusinessMgt.Balance.SlmBalanceInfo slmBalanceInfo = null; private void FrmBalanceInvoceMgt_Load(object sender, EventArgs e) { this.ultraExpandableGroupBox2.Visible = false; this.dateTimePicker1.Value = System.DateTime.Now.AddMonths(-1); slmBalanceInfo = new Core.StlMes.Client.Sale.BLL.SaleBusinessMgt.Balance.SlmBalanceInfo(this.ob); initDataSource(); this.ultraGrid5.DataSource = base.GetDataSetByColumnName(this.GetGrid5DataStruct(), null, GetColumnAndCaption()); this.ultraGrid4.DataSource = base.GetDataSetByColumnName(this.GetGrid4DataStruct(), null, GetColumnAndCaption()); base.SetGridStyle(ref this.ultraGrid1,ref this.ultraGrid5,ref this.ultraGrid2,ref this.ultraGrid3,ref this.ultraGrid4); InitGrid(); HiddenColumn(); InitGridValue(); } private void SaveRealInvoiceNo() { this.ultraGrid1.UpdateData(); Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null; if (this.ultraGrid1.Rows.Count == 0) return; ugr = this.ultraGrid1.ActiveRow; if (ugr == null) { MessageBox.Show("请选择需要保存的行"); return; } string invoiceno = ugr.Cells["INVOICENO_ORG"].Value.ToString(); string realInvoiceNo = ugr.Cells["REALINVOICENO_ORG"].Value.ToString(); if (realInvoiceNo.Length == 0) return; if (realInvoiceNo.Length > 30) { MessageBox.Show("发票号允许最大长度30"); return; } string errMsg = ""; this.slmBalanceInfo.UpdateRealInvoiceNoOrg(invoiceno, realInvoiceNo, CoreFS.SA06.CoreUserInfo.UserInfo .GetUserName(), out errMsg); if (errMsg.Length == 0) { MessageBox.Show("保存成功"); } } private void InitGrid() { System.Drawing.Color color = System.Drawing.Color.FromArgb(255, 255, 128); try { this.ultraGrid1.DisplayLayout.Bands[0].Columns["REALINVOICENO"].CellActivation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit; this.ultraGrid1.DisplayLayout.Bands[0].Columns["REALINVOICENO"].CellAppearance.BackColor = color; this.ultraGrid1.DisplayLayout.Bands[0].Columns["REALINVOICENO_ORG"].CellActivation = Infragistics.Win.UltraWinGrid.Activation.AllowEdit; this.ultraGrid1.DisplayLayout.Bands[0].Columns["REALINVOICENO_ORG"].CellAppearance.BackColor = color; } catch { } } private void InitGridValue() { try { this.ultraGrid1.DisplayLayout.Bands[0].Columns["FST_DRAWEE_UNIT"].ValueList = GetFstDraWeeUnit(); } catch { } } private Infragistics.Win.ValueList GetFstDraWeeUnit() { Infragistics.Win.ValueList lit = new Infragistics.Win.ValueList(); lit.ValueListItems.Add("120601", "N/A"); lit.ValueListItems.Add("120602", "/"); lit.ValueListItems.Add("120603", "天津钢管集团股份有限公司"); lit.ValueListItems.Add("120604", "天津钢管钢铁贸易有限公司"); lit.ValueListItems.Add("120605", "天津钢管国际贸易有限公司"); lit.ValueListItems.Add("120606", "合同结算单位"); return lit; } public override void ToolBar_Click(object sender, string ToolbarKey) { switch (ToolbarKey) { case "Query": { this.Query(); break; } case "RollInv": { this.RollBackInvoiceNo(); break; } case "Exit": { this.Close(); break; } case "Save": { this.SaveRealInvoiceNo(); break; } case "PrintInvoice": { this.PrintInvoice(); break; } case "Credit": { this.Credit(); break; } } } /// /// 冲减 /// private void Credit() { Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null; Infragistics.Win.UltraWinGrid.UltraGridRow ugrc = null; if (this.ultraGrid1.Rows.Count == 0) return; if (this.ultraGrid2.Rows.Count == 0) return; if (this.ultraGrid1.Rows.Count == 1) this.ultraGrid1.Rows[0].Activated = true; ugr = this.ultraGrid1.ActiveRow; if (ugr == null) { Util.MessageUtil.ShowTips("请选择需要保存的行"); return; } if (this.ultraGrid5.Rows.Count == 0) return; if (this.ultraGrid5.Rows.Count == 1) this.ultraGrid5.Rows[0].Activated = true; ugrc = this.ultraGrid5.ActiveRow; if (ugrc == null) { Util.MessageUtil.ShowTips("请选择待冲减的行"); return; } string invoiceno = ugr.Cells["INVOICENO_ORG"].Value.ToString(); // "WEIGHT", // "MONEY", double money = Util.ConverObject.ConvertToDouble(ugr.Cells["MONEY_ORG"].Value); double weight = Util.ConverObject.ConvertToDouble(ugr.Cells["WEIGHT"].Value); double creditMny = Util.ConverObject.ConvertToDouble(ugrc.Cells["MONEY_ORG"].Value); if (creditMny >= money) { Util.MessageUtil.ShowError("冲减金额必须小于货款"); return; } if (weight == 0) { Util.MessageUtil.ShowError("只能冲减货款"); return; } if (Util.MessageUtil.ShowYesNoAndQuestion("是否确定冲减结算单?") == DialogResult.No) return; double dlivPrice = (money - creditMny) / weight; ArrayList list = new ArrayList(); string[] str = null; string sub_seq = ugrc.Cells["SUB_SEQ"].Value.ToString(); foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugrr in this.ultraGrid2.Rows) { double seqmoney = dlivPrice * Util.ConverObject.ConvertToDouble(ugrr.Cells["WEIGHT"].Value); str = new string[] { invoiceno, ugrr.Cells["INVOICENO_SEQ_ORG"].Value.ToString(), dlivPrice + "", seqmoney +"",sub_seq}; list.Add(str); } string errMsg = ""; this.slmBalanceInfo.Credit(list, CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName(), out errMsg); if (errMsg.Length == 0) { Util.MessageUtil.ShowTips("操作成功"); } this.Query(); } private void PrintInvoice() { string INVOICENO = "INVOICENO_ORG"; List list = new List(); if (this.ultraGrid1.Rows.Count == 0) return; if (this.ultraGrid1.Rows.Count == 1) this.ultraGrid1.Rows[0].Selected = true; this.ultraGrid1.ActiveRow.Selected = true; foreach (Infragistics.Win.UltraWinGrid.UltraGridRow ugr in this.ultraGrid1.Selected.Rows) { list.Add(ugr.Cells[INVOICENO].Value.ToString()); } DlgInvoicePrint print = null; print = new DlgInvoicePrint(this.ob); print.listInvoiceNo = list; print.isOrgInvoice = true; print.ShowDialog(); } private void RollBackInvoiceNo() { if (this.ultraGrid1.Rows.Count == 0) return; Infragistics.Win.UltraWinGrid.UltraGridRow ugr = this.ultraGrid1.ActiveRow; if (ugr == null) return; string invoinceno = ugr.Cells[this.INVOICENO].Value.ToString(); this.slmBalanceInfo.RollBaskInvoiceNoOrg(invoinceno, CoreFS.SA06.CoreUserInfo.UserInfo.GetUserName()); ugr.Delete(false); this.ultraGrid1.UpdateData(); } private string saleOrg_Corp = "120603"; private string saleOrg_Gm = "120604"; private string saleOrg_Gtm = "120605"; private void Query() { dsInvoiceDetail = this.slmBalanceInfo.GeOrgtInvoiceSlmBalaneInfoByInvoiceBeginDateAndEndDate(this.dateTimePicker1.Value, this.dateTimePicker2.Value); //if (this.textBox3.Text.Length > 0) //{ // dsInvoiceDetail = Util.UtilDataSet.GetDataSetWithRowFilterWithApproximateMatch(dsInvoiceDetail, "ORD_NO", this.textBox3.Text.Trim()); //} // 只显示首次受票单位为国贸,钢贸,集团的数据 try { dsInvoiceDetail = Util.UtilDataSet.GetDataSetWithRowFilter(dsInvoiceDetail, "FST_DRAWEE_UNIT", new string[] { saleOrg_Corp, saleOrg_Gm, saleOrg_Gtm } ); } catch { } DataSet ds = Util.UtilDataSet.GetDateSetByGroupColumnAndStaticsColumnName(dsInvoiceDetail, new List(GetGroupByName()), new List(GetShowName()), new List(GetStaticName())); Util.UtilDataSet.SetDataSetByMergeSameColumnName(ref this.dsInvoice, ds); SetTransMoneyAndOutStockMoney(); // QueryTransMny(); ClearGrid(); } private DataSet GetTransMnyByInvoiceNo(string invoiceno) { string sql = @"select sum(a.money) money,sum(a.weight) weight,a.money_type,a.invoiceno_org from slm_balance_transmoney a where invoiceno_org = '{0}' and a.invoiceno_org is not null group by a.money_type,a.invoiceno_org"; sql = string.Format(sql,invoiceno); DataSet ds = base.ExecuteReader(sql); return ds; } private void SetTransMoneyAndOutStockMoney() { if (this.dsInvoice == null || this.dsInvoice.Tables.Count == 0 || this.dsInvoice.Tables[0].Rows.Count == 0) return; foreach (DataRow dri in this.dsInvoice.Tables[0].Rows) { try { string invoiceno = dri[this.INVOICENO].ToString(); DataSet ds = GetTransMnyByInvoiceNo(invoiceno); //DataSet ds = this.slmBalanceInfo.GetInvoiceSlmBalanceTransMoneyAndOutStockMoney(this.dateTimePicker1.Value, // this.dateTimePicker2.Value); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) continue; foreach (DataRow drd in ds.Tables[0].Rows) { if (drd["MONEY_TYPE"].ToString() == "运费") { dri["TRANSMNY"] = drd["MONEY"]; } if (drd["MONEY_TYPE"].ToString() == "出库费") { dri["OUTSTOCKMNY"] = drd["MONEY"]; } } } catch { } } this.dsInvoice.AcceptChanges(); ClearGrid(); } private void ClearGrid() { this.dsInvoiceSeq.Clear(); this.dsInvoiceList.Clear(); } private void QueryTransMny() { DataSet ds = this.slmBalanceInfo.GetInvoiceSlmBalanceTransMoney(this.dateTimePicker1.Value, this.dateTimePicker2.Value); if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0) return; ds.Tables[0].TableName = this.dsInvoice.Tables[0].TableName; this.dsInvoice.Merge(ds); this.dsInvoice.AcceptChanges(); } private void QuryGrid2(string invoiceNo) { DataSet ds2 = Util.UtilDataSet.GetDataSetWithRowFilter(dsInvoiceDetail, this.INVOICENO, invoiceNo); DataSet ds = Util.UtilDataSet.GetDateSetByGroupColumnAndStaticsColumnName(ds2, new List(this.GetGrid2GroupByCol()), new List(this.GetGrid2ShowCol()), new List(this.GetGrid2StaticCol())); Util.UtilDataSet.SetDataSetByMergeSameColumnName(ref this.dsInvoiceSeq, ds); } private void QueryGrid3(String invoiceno, string invoiceno_seq) { DataSet ds2 = Util.UtilDataSet.GetDataSetWithRowFilter(dsInvoiceDetail, this.INVOICENO, invoiceno); DataSet ds3 = Util.UtilDataSet.GetDataSetWithRowFilter(ds2, this.INVOICENO_SEQ, invoiceno_seq); Util.UtilDataSet.SetDataSetByMergeSameColumnName(ref this.dsInvoiceList, ds3); } private string[] GetGroupByName() { return new string[] { "INVOICENO_ORG", "FST_DRAWEE_UNIT", // "BUYERNAME", "FORECORPCODE" // "ORD_NO" }; } private string[] GetShowName() { return new string[] { "REMARK" , "PRICE_ORG", "REALINVOICENO_ORG" }; } private string[] GetStaticName() { return new string[] { "WEIGHT", "MONEY_ORG" }; } private string[] GetGrid1DataStruct() { return new string[] { "INVOICENO_ORG", "REALINVOICENO_ORG", "FST_DRAWEE_UNIT", "REALINVOICENO", // "BUYERNAME", "WEIGHT", "MONEY_ORG", "TRANSMNY", "OUTSTOCKMNY", // "TRANSMONEYQC", //"TRANSMONEYSY1", //"TRANSMONETRAIN", // "HOISTINGFEE", // "ORD_NO", "REMARK", "FORECORPCODE" } ; } private Hashtable GetColumnAndCaption() { return StaticData.TbColumnAndCaption.GetColumnAndCaption(); Hashtable hs = new Hashtable(); hs.Add("WEIGHT", "重量"); hs.Add("INVOICENO", "结算单号"); hs.Add("FORECORPCODE", "子公司"); hs.Add("SHIPNO", "船号"); hs.Add("TRANSMONEYQC", "汽运费"); hs.Add("TRANSMONEYSY1", "船运费"); hs.Add("TRANSMONETRAIN", "火运费"); hs.Add("HOISTINGFEE", "吊装费"); hs.Add("PLY", "厚/直径/壁厚"); hs.Add("WIDTH", "宽/外径"); hs.Add("ORD_NO", "合同号"); hs.Add("BUYERNAME", "结算单位名称"); hs.Add("BUYERCODE", "结算单位名称"); hs.Add("FST_DRAWEE_UNIT", "首次受票人"); hs.Add("STATIONCODE", "到站"); hs.Add("MONEY_ORG", "金额"); hs.Add("PRICE_ORG", "单价"); hs.Add("INVOICENO_ORG", "结算单号"); hs.Add("INVOICENO_SEQ_ORG", "序号"); return hs; } protected override Hashtable GetGridColumnLength() { return StaticData.TbColumnAndCaption.GetDataSetColumnLength(); } private string[] GetGrid5DataStruct() { return new string[] { "SUBTCT_TYP", "SUBTCT_MOD", "SUBTCT_MNY", "SUBTCT_DSP", "DCL_ID", "DCL_DTIME", "REV_ID", "REV_DTIME", "REV_DSP" } ; } private string[] GetGrid2DataStruct() { return new string[] { "INVOICENO_ORG", "INVOICENO_SEQ_ORG", "SPETKEY", "STEELCODEKEY", "PRICE_ORG", "WEIGHT", "MONEY_ORG" } ; } private string[] GetGrid2GroupByCol() { return new string[] { "INVOICENO_ORG", "INVOICENO_SEQ_ORG" }; } private string[] GetGrid2ShowCol() { return GetGrid2DataStruct(); } private string[] GetGrid2StaticCol() { return new string[] { "WEIGHT", "MONEY_ORG" }; } private string[] GetGrid3DataStruct() { return new string[] { "SPETKEY", "STEELCODEKEY", "QUANTITY", "WEIGHT", "MONEY_ORG", "TRAINWAGON", // "SHIPNO", // "DOCKCODE", "STATIONCODE", } ; } private string[] GetGrid4DataStruct() { return new string[] { "SUBTCT_TYP", "SUBTCT_MOD", "SUBTCT_MNY", "SUBTCT_DSP", "SUBTCT_TIME" } ; } private string BUYERCODE = "BUYERCODE"; private string ORD_NO = "ORD_NO"; private string ORD_SEQ = "ORD_SEQ"; private string ORD_LN_DLY = "ORD_LN_DLY"; private string ASKPLAN_ID = "ASKPLAN_ID"; private string ASKPLAN_ID_SEQ = "ASKPLAN_ID_SEQ"; private string SPETKEY = "SPETKEY"; private string STEELCODEKEY = "STEELCODEKEY"; private string MONEY = "MONEY_ORG"; private string WEIGHT = "WEIGHT"; private string PRICE = "PRICE_ORG"; private string BALANCESTATUS = "BALANCESTATUS"; private string ADJUSTPRICEREASON = "ADJUSTPRICEREASON"; private string INVOICENO = "INVOICENO_ORG"; private string INVOICENO_SEQ = "INVOICENO_SEQ_ORG"; private string BALANCESTATUS_INIT = "0"; private string BALANCESTATUS_AFFRIM = "1"; private string BALANCESTATUS_INVOINCE = "2"; private void ultraGrid1_AfterRowActivate(object sender, EventArgs e) { if (this.ultraGrid1.Rows.Count == 0) return; Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null; if (this.ultraGrid1.Rows.Count == 1) ugr = this.ultraGrid1.Rows[0]; else ugr = this.ultraGrid1.ActiveRow; string invoiceno = ugr.Cells[this.INVOICENO].Value.ToString(); this.QuryGrid2(invoiceno); } private void ultraGrid2_AfterRowActivate(object sender, EventArgs e) { if (this.ultraGrid2.Rows.Count == 0) return; Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null; if (this.ultraGrid2.Rows.Count == 1) ugr = this.ultraGrid2.Rows[0]; else ugr = this.ultraGrid2.ActiveRow; string invoiceno = ugr.Cells[this.INVOICENO].Value.ToString(); string invoicenoseq = ugr.Cells[this.INVOICENO_SEQ].Value.ToString(); this.QueryGrid3(invoiceno, invoicenoseq); } private void button3_Click(object sender, EventArgs e) { this.PrintInvoice(); } private void ultraGrid1_AfterRowActivate_1(object sender, EventArgs e) { if (this.ultraGrid1.Rows.Count == 0) return; Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null; if (this.ultraGrid1.Rows.Count == 1) ugr = this.ultraGrid1.Rows[0]; else ugr = this.ultraGrid1.ActiveRow; string invoiceno = ugr.Cells[this.INVOICENO].Value.ToString(); this.QuryGrid2(invoiceno); } private void ultraGrid2_AfterRowActivate_1(object sender, EventArgs e) { if (this.ultraGrid2.Rows.Count == 0) return; Infragistics.Win.UltraWinGrid.UltraGridRow ugr = null; if (this.ultraGrid2.Rows.Count == 1) ugr = this.ultraGrid2.Rows[0]; else ugr = this.ultraGrid2.ActiveRow; string invoiceno = ugr.Cells[this.INVOICENO].Value.ToString(); string invoicenoseq = ugr.Cells[this.INVOICENO_SEQ].Value.ToString(); this.QueryGrid3(invoiceno, invoicenoseq); } } }