using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using DevExpress.XtraEditors; using System.ServiceModel; using DevExpress.XtraEditors.Controls; using DevExpress.XtraEditors.DXErrorProvider; namespace Pror.AirExport { /// <summary> /// 新建空运出口订单 /// </summary> public partial class TFormNewOrder : FormCommonDialog { #region 枚举 public enum NewOrderOper { NewOrder, BindNewOrder } #endregion #region 变量 private string orderID = string.Empty; private string jobID = string.Empty; private string loading = string.Empty; private FormJob parent = null; private string discharging = string.Empty; private NewOrderOper orderOper; private string tempOrderId = string.Empty; private string tempJobId = string.Empty; private DXValidationProvider validator = new DXValidationProvider(); #endregion #region 属性 /// <summary> /// 获取新建订单对象 /// </summary> internal NewAirExportOrder NewOrderObject { get { NewAirExportOrder data = new NewAirExportOrder(); return data; } } #endregion #region 静态方法 public static DialogResult Dialog() { TFormNewOrder frmFormOrderNew = new TFormNewOrder(); return frmFormOrderNew.ShowDialog(); } internal static DialogResult Dialog(string jobID, string loading, string discharging, out string orderID, FormJob parent) { TFormNewOrder fr = new TFormNewOrder(jobID, loading, discharging, out orderID, parent); DialogResult dr = fr.ShowDialog(); return dr; } #endregion #region 私有方法 protected override void InitUI() { base.InitUI(); this.beCustomer.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(btnCustomer_ButtonClick); this.beOperator.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(btnOperator_ButtonClick); if (this.orderOper == NewOrderOper.BindNewOrder) { 加拼委托时,不用输入订舱信息 //this.xtraTabControl.TabPages.Remove(this.xtpBooking); //用户不能修改起运,目的港口信息 this.bteLoading.EditValue = this.loading; this.bteDischarging.EditValue = this.discharging; this.bteLoading.Enabled = false; this.bteDischarging.Enabled = false; } this.validator.SetValidationRule(beCustomer, ConditionOperator.IsNotBlank, "请选择客户", ErrorIconAlignment.MiddleRight); this.validator.SetValidationRule(bteLoading, ConditionOperator.IsNotBlank, "请选择起运港", ErrorIconAlignment.MiddleRight); this.validator.SetValidationRule(bteDischarging, ConditionOperator.IsNotBlank, "请选择目的港", ErrorIconAlignment.MiddleRight); this.validator.SetValidationRule(bteDischarging, ConditionOperator.IsNotBlank, "请选择目的港", ErrorIconAlignment.MiddleRight); this.validator.SetValidationRule(deFlight, ConditionOperator.IsNotBlank, "请选择开航时间", ErrorIconAlignment.MiddleRight); beCustomer.Focus(); } /// <summary> /// 使用系统枚举值填充指定的RadioGroup /// </summary> /// <typeparam name="T">系统枚举类型</typeparam> /// <param name="cbe"></param> public void FillSystemEnumeration<T>(RadioGroup rg) { rg.Properties.Items.Clear(); foreach (SysEnum.CargoCanvassingEnumerationRow agRow in SysEnum.Inst.CargoCanvassingEnumeration) { RadioGroupItem item = new RadioGroupItem(); item.Value = (T)Enum.Parse(typeof(T), Convert.ToString(agRow.ID)); item.Description = agRow.NAME; rg.Properties.Items.Add(item); } } /// <summary> /// 使用系统枚举值填充指定的RadioGroup /// </summary> /// <typeparam name="T">系统枚举类型</typeparam> /// <param name="cbe"></param> public void FillStoreTypeEnumeration<T>(RadioGroup rg) { rg.Properties.Items.Clear(); foreach (SysEnum.StoreTypeEnumerationRow agRow in SysEnum.Inst.StoreTypeEnumeration) { RadioGroupItem item = new RadioGroupItem(); item.Value = (T)Enum.Parse(typeof(T), Convert.ToString(agRow.ID)); item.Description = agRow.NAME; rg.Properties.Items.Add(item); } } private void CreateOrder(IdRegular idRagular) { Job.AE_ORDERRow order = this.dsJob.AE_ORDER.NewAE_ORDERRow(); order.ORDER_ID = CommonTool.GenerateUniqueID(); order.CUST_ID = Convert.ToString(this.beCustomer.Tag); ; order.CUST_CONTACT = teLinkMan.EditValue as string; order.CUSTOM_NUM = teLinkTel.EditValue as string; order.LOADING = Convert.ToString(this.bteLoading.EditValue); order.DISCHARGING = Convert.ToString(this.bteDischarging.EditValue); order.STATUS = -1; order.SALESPERSON = (string)this.beOperator.Tag; order.OWNER = ""; if ((AgentTypeEnumeration)this.rgCargoCanvassing.EditValue == AgentTypeEnumeration.Agency) { order.AGENT_TYPE = (int)(AgentTypeEnumeration.Agency); } else if ((AgentTypeEnumeration)this.rgCargoCanvassing.EditValue == AgentTypeEnumeration.Direct) { order.AGENT_TYPE = (int)(AgentTypeEnumeration.Direct); } //销售人 order.SALESPERSON = this.beOperator.Tag == null ? "" : Convert.ToString(this.beOperator.Tag); order.CARGO_NAME = this.teCargoName.EditValue == null ? "" : Convert.ToString(this.teCargoName.EditValue); order.UNIT_PRICE = this.teUnitPrice.EditValue as string; order.PAY_TYPE = -1; order.PAY_TYPE2 = -1; order.TRAFFIC_TYPE = -1; order.IS_LOCAL_STORE = Convert.ToInt32(rbeIsLocalStore.EditValue); order.STORE_FLAG = -1; order.CANVASSING = this.rgCargoCanvassing.EditValue == null ? 0 : Convert.ToInt32(this.rgCargoCanvassing.EditValue); order.PRE_QUANTITY = tePiece.EditValue == null ? 0 : Convert.ToInt32(this.tePiece.EditValue); order.PRE_GROSS_WEIGHT = this.teWeight.EditValue == null ? 0 : Convert.ToInt32(this.teWeight.EditValue); order.PRE_VOLUME = this.teVolumns.EditValue == null ? 0 : Convert.ToInt32(this.teVolumns.EditValue); order.QUANTITY = -1; order.GROSS_WEIGHT = -1; order.VOLUME = -1; order.REMARK = ""; order.CREATE_BY = LoginUser.UserId; order.DEPT_ID = Convert.ToString(LoginUser.DeptId); ; order.FIRM = ""; this.tempOrderId = order.ORDER_ID; this.dsJob.AE_ORDER.AddAE_ORDERRow(order); Job.AE_JOBRow job = this.dsJob.AE_JOB.NewAE_JOBRow(); job.JOB_ID = CommonTool.GenerateUniqueID(); job.PAYMENT_TYPE = -1; job.PAYMENT_TYPE2 = -1; job.FLIGHT_NUM = this.teFlightNum.EditValue == null ? "":(string)this.teFlightNum.EditValue ; job.FLIGHT_DATE = (DateTime)this.deFlight.EditValue; job.JOB_TYPE = -1; job.MAWB_NUM = null; job.SPACE = ""; job.PROVIDER = ""; job.CARRIER = ""; job.BOOKING_STATUS = -1; job.ORIGINAL_RATE = -1; job.APPLY_RATE = -1; job.OPER_ID = LoginUser.UserId; job.BOOKING_DATE = DateTime.Now; //job.FINISH_DATE = null ; idRagular.PostfixJob = ""; idRagular.PrefixJob = ""; idRagular.PrefixOrder = ""; idRagular.PostfixOrder = ""; this.tempJobId = job.JOB_ID; this.dsJob.AE_JOB.AddAE_JOBRow(job); } private void CreateDeclare(string jobId,string orderId) { Job.AE_DECLARERow declare = this.dsJob.AE_DECLARE.NewAE_DECLARERow(); declare.QUALITY = tePiece.EditValue == null ? 0 : Convert.ToInt32(this.tePiece.EditValue); declare.GROSS_WEIGHT = this.teWeight.EditValue == null ? 0 : Convert.ToInt32(this.teWeight.EditValue); declare.VOLUME = this.teVolumns.EditValue == null ? 0 : Convert.ToInt32(this.teVolumns.EditValue); declare.CARGO_NAME = this.teCargoName.EditValue == null ? "" : Convert.ToString(this.teCargoName.EditValue); declare.ORDER_ID = orderId; declare.JOB_ID = jobId; declare.DEC_ID = CommonTool.GenerateUniqueID(); this.dsJob.AE_DECLARE.AddAE_DECLARERow(declare); } private void Create2Order(IdRegular idRagular) { Job.AE_ORDERRow orders = ((DataRowView)this.parent.bsOrder.AddNew()).Row as Job.AE_ORDERRow; if (orders != null) { orders.ORDER_ID = CommonTool.GenerateUniqueID(); orders.JOB_ID = this.jobID; orders.CUST_ID = Convert.ToString(this.beCustomer.Tag); ; orders.CUST_CONTACT = teLinkMan.EditValue as string; orders.CUSTOM_NUM = ""; orders.LOADING = this.loading; orders.DISCHARGING = this.discharging; orders.STATUS = -1; orders.SALESPERSON = (string)this.beOperator.Tag; orders.OWNER = ""; if ((AgentTypeEnumeration)this.rgCargoCanvassing.EditValue == AgentTypeEnumeration.Agency) { orders.AGENT_TYPE = (int)(AgentTypeEnumeration.Agency); } else if ((AgentTypeEnumeration)this.rgCargoCanvassing.EditValue == AgentTypeEnumeration.Direct) { orders.AGENT_TYPE = (int)(AgentTypeEnumeration.Direct); } //销售人 orders.SALESPERSON = this.beOperator.Tag == null ? "" : Convert.ToString(this.beOperator.Tag); orders.JOB_TYPE = -1; orders.CARGO_NAME = this.teCargoName.EditValue == null ? "" : Convert.ToString(this.teCargoName.EditValue); orders.UNIT_PRICE = this.teUnitPrice.EditValue as string; orders.PAY_TYPE = -1; orders.PAY_TYPE2 = -1; orders.TRAFFIC_TYPE = -1; orders.IS_LOCAL_STORE = Convert.ToInt32(rbeIsLocalStore.EditValue); orders.STORE_FLAG = -1; orders.CANVASSING = this.rgCargoCanvassing.EditValue == null ? 0 : Convert.ToInt32(this.rgCargoCanvassing.EditValue); orders.PRE_QUANTITY = tePiece.EditValue == null ? 0 : Convert.ToInt32(this.tePiece.EditValue); orders.PRE_GROSS_WEIGHT = this.teWeight.EditValue == null ? 0 : Convert.ToInt32(this.teWeight.EditValue); orders.PRE_VOLUME = this.teVolumns.EditValue == null ? 0 : Convert.ToInt32(this.teVolumns.EditValue); orders.QUANTITY = -1; orders.GROSS_WEIGHT = -1; orders.VOLUME = -1; orders.REMARK = ""; orders.CREATE_BY = LoginUser.UserId; orders.DEPT_ID = Convert.ToString(LoginUser.DeptId); ; orders.FIRM = ""; this.tempOrderId = orders.ORDER_ID; } this.parent.bsOrder.EndEdit(); } private void CreateBindJob(string orderId) { Job.AE_DECLARERow declare = ((DataRowView)this.parent.bsDeclare.AddNew()).Row as Job.AE_DECLARERow; declare.QUALITY = tePiece.EditValue == null ? 0 : Convert.ToInt32(this.tePiece.EditValue); declare.GROSS_WEIGHT = this.teWeight.EditValue == null ? 0 : Convert.ToInt32(this.teWeight.EditValue); declare.VOLUME = this.teVolumns.EditValue == null ? 0 : Convert.ToInt32(this.teVolumns.EditValue); declare.CARGO_NAME = this.teCargoName.EditValue == null ? "" : Convert.ToString(this.teCargoName.EditValue); declare.ORDER_ID = orderId; declare.JOB_ID = this.jobID; declare.DEC_ID = CommonTool.GenerateUniqueID(); this.parent.bsDeclare.EndEdit(); } #endregion #region 窗体构造 /// <summary> /// 新建空运出口订单,作业,并且绑定两者 /// </summary> public TFormNewOrder() { this.orderOper = NewOrderOper.NewOrder; InitializeComponent(); } /// <summary> /// 根据现有作业绑定订单 /// </summary> /// <param name="jobID"></param> public TFormNewOrder(string jobID, string loading, string discharging, out string orderID, FormJob parent) { this.parent = parent; this.orderOper = NewOrderOper.BindNewOrder; this.jobID = jobID; this.loading = loading; this.discharging = discharging; orderID = this.orderID; InitializeComponent(); this.bsJob.DataSource = this.parent.bsMain.DataSource; } #endregion #region 窗体事件 private void FormNewOrder_Load(object sender, EventArgs e) { //初始化揽货方式 this.FillSystemEnumeration<CargoCanvassingEnumeration>(this.rgCargoCanvassing); this.rgCargoCanvassing.Properties.Items.Remove( this.rgCargoCanvassing.Properties.Items.GetItemByValue(CargoCanvassingEnumeration.AirLine)); this.rgCargoCanvassing.Properties.Items.Remove( this.rgCargoCanvassing.Properties.Items.GetItemByValue(CargoCanvassingEnumeration.Other)); this.rgCargoCanvassing.EditValue = CargoCanvassingEnumeration.Self; //初始化港口 FillStoreTypeEnumeration<StoreTypeEnumeration>(rbeIsLocalStore); this.rbeIsLocalStore.EditValue = StoreTypeEnumeration.Self; this.bteLoading.Properties.DataSource = DataDict.Inst.DC_AIRPORT; this.bteDischarging.Properties.DataSource = DataDict.Inst.DC_AIRPORT; this.lueTRAFFIC_TYPE.Properties.DataSource = SysEnum.Inst.TransportTypeEnumeration; this.cePayType.Properties.DataSource = SysEnum.Inst.PaymentTypeEnumeration; } #endregion #region 工具栏事件 #endregion #region 控件事件 /// <summary> /// 完成 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnFinish_Click(object sender, EventArgs e) { //判断是添加那种功能 if (this.validator.FocusFirstInvalid()) { this.DialogResult = System.Windows.Forms.DialogResult.None; return; } IdRegular idRagular = new IdRegular(); using (AirExportOrderClient sc = FreightService.Get<AirExportOrderClient, IAirExportOrder>()) { try { switch (orderOper) { case NewOrderOper.BindNewOrder: this.Create2Order(idRagular); if (!this.parent.dsMain.HasChanges()) { return; } if (sc.NewOrder2Job(out orderID, this.parent.dsMain.GetChanges(), idRagular, this.jobID)) { //--更新申报 if (orderID != string.Empty) { //更换表格编号 this.parent.dsMain.AE_ORDER.FindByORDER_ID(tempOrderId).ORDER_ID = orderID; this.CreateBindJob(orderID); sc.UpdateDeclare(this.parent.dsMain.GetChanges()); if (!string.IsNullOrEmpty(jobID)) { FormMain.AddChildForm(FormJob.NewForm(jobID)); string msg = string.Format("已经创建空运出口订单:/nSN:{0}", orderID); AlertControlTool.Show("恭喜", msg); } else { XtraMessageBox.Show("创建空运出口订单失败,请联系系统管理员!", null, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } } } break; case NewOrderOper.NewOrder: this.CreateOrder(idRagular); if (sc.NewOrder(out jobID, out orderID, this.dsJob.GetChanges(), idRagular)) { if (orderID != string.Empty && jobID != string.Empty) { //更换表格编号 this.dsJob.AE_ORDER.FindByORDER_ID(tempOrderId).ORDER_ID = orderID; this.dsJob.AE_JOB.FindByJOB_ID(tempJobId).JOB_ID = jobID; this.CreateDeclare(jobID, orderID); //--更新申报 sc.UpdateDeclare(this.dsJob.GetChanges()); if (!string.IsNullOrEmpty(jobID)) { FormMain.AddChildForm(FormJob.NewForm(jobID)); string msg = string.Format("已经创建空运出口订单:/nSN:{0}:{1}", jobID, orderID); AlertControlTool.Show("恭喜", msg); } else { XtraMessageBox.Show("创建空运出口订单失败,请联系系统管理员!", null, MessageBoxButtons.OK, MessageBoxIcon.Error); this.DialogResult = DialogResult.None; return; } } } break; } } catch (FaultException<FreightException> ex) { XtraMessageBox.Show(ex.Message); return; } catch (Exception ex) { XtraMessageBox.Show(ex.Message); return; } } } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } void btnCustomer_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { switch (e.Button.Kind) { case DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis: string custID = FormSelectCustomer.Dialog(Core.Enum.CustomerPropertyEnumeration.Normal, true); DataDict.DC_CUSTOMERRow cust = DataDict.Inst.DC_CUSTOMER.FindByCUST_ID(custID); if (cust != null) { //判断客户账户余额 this.beCustomer.EditValue = cust.ABBREVIATION; this.beCustomer.Tag = cust.CUST_ID; this.teChineseName.EditValue = cust.C_NAME; this.teEnglishName.EditValue = cust.E_NAME; this.teCredit.EditValue = cust.CREDIT * 10000; this.teCreditBalance.EditValue = cust.CREDIT * 10000; DataDict.DC_CUST_CONTACTRow contact = DataDict.Inst.DC_CUST_CONTACT.FindByCONTACT_ID(cust.CUST_ID); if (contact != null) { this.teLinkMan.EditValue = contact.C_NAME; this.teLinkTel.EditValue = contact.TEL; } //+ balance; //if (cust.CREDIT * 10000 + balance <= (cust.CREDIT * 10000) * FreightConfig.CreditAlarmRate) //{ // this.txtCreditBalance.ForeColor = Color.Red; // MessageBoxEx.Show(string.Format("请尽快向客户 {0} 催款,否则该客户将停用!", // cust.ABBREVIATION), null, MessageBoxButtons.OK, MessageBoxIcon.Warning); //} //else //{ // this.txtCreditBalance.ForeColor = Color.Black; //} } break; case DevExpress.XtraEditors.Controls.ButtonPredefines.Delete: this.beCustomer.EditValue = null; this.beCustomer.Tag = null; this.teChineseName.EditValue = null; this.teEnglishName.EditValue = null; this.teCredit.EditValue = null; this.teCreditBalance.EditValue = null; break; } } void btnOperator_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) { if (this.rgCargoCanvassing.EditValue == null) { return; } switch (e.Button.Kind) { case DevExpress.XtraEditors.Controls.ButtonPredefines.Ellipsis: CargoCanvassingEnumeration canv = (CargoCanvassingEnumeration)this.rgCargoCanvassing.EditValue; switch (canv) { case CargoCanvassingEnumeration.Agency: string agentID = FormSelectCustomer.Dialog(CustomerPropertyEnumeration.Agent, true); DataDict.DC_CUSTOMERRow cusRow = DataDict.Inst.DC_CUSTOMER.FindByCUST_ID(agentID); if (cusRow != null) { this.beOperator.EditValue = cusRow.TYPE_ID; this.beOperator.Text = cusRow.C_NAME; this.beOperator.Tag = cusRow.TYPE_ID; } break; case CargoCanvassingEnumeration.Self: string sefId = FormSelectUser.Dialog(); DataDict.DC_USERRow uerRow = DataDict.Inst.DC_USER.FindByUSER_ID(sefId); if (uerRow != null) { this.beOperator.EditValue = uerRow.USER_ID; this.beOperator.Text = uerRow.C_NAME; this.beOperator.Tag = uerRow.USER_ID; } break; } break; case DevExpress.XtraEditors.Controls.ButtonPredefines.Delete: this.beOperator.EditValue = null; this.beOperator.Tag = null; break; } } #endregion private void rdoGroup_EditValueChanged(object sender, EventArgs e) { this.beOperator.EditValue = null; this.beOperator.Tag = null; } #region 网格事件 #endregion #region 数据集事件 #endregion #region 数据源事件 #endregion //private void btnClose_Click(object sender, EventArgs e) //{ // this.Close(); //} //private void btnCustomer_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) //{ // FormCustomerSearch frmSearchCustomer = new FormCustomerSearch(); // frmSearchCustomer.ShowDialog(); //} //private void NewAEOrder_Load(object sender, EventArgs e) //{ // btnOperator.Enabled = false; //} //private void rdo_SelectedIndexChanged(object sender, EventArgs e) //{ // btnOperator.Enabled = true; //} //private void btnOperator_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e) //{ // if (rdo.SelectedIndex == 0) // { // FormCustomerSearch frmSearchCustomer = new FormCustomerSearch(); // frmSearchCustomer.ShowDialog(); // } // else if (rdo.SelectedIndex == 1) // { // FormOperatorSearch frmSearchOperator = new FormOperatorSearch(); // frmSearchOperator.ShowDialog(); // } //} //private void btnSave_Click(object sender, EventArgs e) //{ // if (FormMain.ActivateChildForm<FormJob>() == null) // { // FormJob frmFormJobManager = new FormJob();//作业 // FormMain.AddChildForm(frmFormJobManager); // } // this.Close(); //} } }