1. 程式人生 > >基於WF的報銷單流轉審批業務5(淺析)

基於WF的報銷單流轉審批業務5(淺析)

專案名:ShenPBXXT(審批申請報銷)

窗體名:Form1

 

Form1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using System.Workflow.Activities;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;

namespace ShenPBXXT
{
    
public partial class Form1 : Form, InterFaces.IClass
    {
        WorkflowRuntime wr;
        WorkflowInstance wfi;
        ExternalDataExchangeService edes;
        Model.BXDan bxd;
        BLL.BLBXDan blbx 
= new BLBXDan();
        List
<Model.BXDan> lbx = new List<Model.BXDan>();
        
public Form1()
        {
            InitializeComponent();
            wr 
= new WorkflowRuntime();
            edes 
= new ExternalDataExchangeService();
            wr.AddService(edes);
            edes.AddService(
this);
            wr.WorkflowIdled 
+= new EventHandler<WorkflowEventArgs>(wr_WorkflowIdled);
            wr.AddService(
new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=192.168.1.5;uid=sa;pwd=sa"));
            wr.StartRuntime();
            
this.Height = 403;
            lbx 
= blbx.GetModelList("");
            
for (int i = 0; i < lbx.Count; i++)
            {
                
object[] obj = new object[3];
                obj[
0= lbx[i].BXID;
                obj[
1= lbx[i].BXName;
                
switch (lbx[i].stated)
                {
                    
case 0:
                        obj[
2= "被打回需要補充!";
                        
break;
                    
case 1:
                        obj[
2= "財務在核審中!";
                        
break;
                    
case 2:
                        obj[
2= "經理正在核審中!";
                        
break;
                    
case 3:
                        obj[
2= "出納正在準備報銷款!";
                        
break;
                    
case 9:
                        obj[
2= "沒有通過審批不提供報銷!";
                        
break;
                    
default:
                        obj[
2= "款項已經準備完成請去出納處取款!";
                        
break;
                }
                dgv1.Rows.Add(obj);
            }
        }

        
void wr_WorkflowIdled(object sender, WorkflowEventArgs e)
        {
            e.WorkflowInstance.TryUnload();
        }

        
private void button1_Click(object sender, EventArgs e)
        {
            
this.Close();
        }

        
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            
if (e.RowIndex < 0)
            {
                
return;
            }
            
else
            {
                
this.Height = 748 - 46;
                
this.dbx1.Location = new Point(dbx1.Location.X, 377 - 46);
                
this.button1.Enabled = false;
                
this.CenterToScreen();
                bxd 
= new Model.BXDan();
                bxd 
= blbx.GetModel(Convert.ToInt32(dgv1.Rows[e.RowIndex].Cells[0].Value.ToString()));
                txtName.Text 
= bxd.BXName;
                txtBaoXiaoNR.Text 
= bxd.BXNeiRong;
                txtBaoXiao.Text 
= bxd.BXJin;
                labState.Text 
= dgv1.Rows[e.RowIndex].Cells[2].Value.ToString();
                txtName.Enabled 
= false;
                
if (bxd.stated != 0)
                {
                    txtBaoXiao.Enabled 
= false;
                    txtBaoXiaoNR.Enabled 
= false;
                    btnShangBao.Enabled 
= false;
                }

            }
        }

        
private void button2_Click(object sender, EventArgs e)
        {
            
this.Close();
        }

        
private void btnShangBao_Click(object sender, EventArgs e)
        {
            Model.BXDan bb 
= bxd;
            wfi 
= wr.GetWorkflow(new Guid(bb.BXGID));
            bb.BXJin 
= txtBaoXiao.Text.Trim().ToString();
            bb.BXName 
= txtName.Text.Trim().ToString();
            bb.BXNeiRong 
= txtBaoXiaoNR.Text.Trim().ToString();
            
if (Convert.ToInt32(txtBaoXiao.Text.Trim().ToString()) >= 1000)
            {
                bb.stated 
= 2;
            }
            
else
            {
                bb.stated 
= 1;
            }
            blbx.Update(bb);
            ShenQing(
nullnew InterFaces.ShenQingBaoXiao(wfi.InstanceId, Convert.ToDouble(txtBaoXiao.Text.Trim().ToString())));
            
this.Close();
        }

        
private void txtBaoXiao_KeyPress(object sender, KeyPressEventArgs e)
        {
            
if (e.KeyChar >= '0' && e.KeyChar <= '9')
            {
                e.Handled 
= false;
            }
            
else if (e.KeyChar == 8)
            {
                e.Handled 
= false;
            }
            
else
            {
                e.Handled 
= true;
            }
        }

        
#region IClass 成員

        
public event EventHandler<ExternalDataEventArgs> ShenQing;

        
public event EventHandler<ExternalDataEventArgs> CaiWuShenPi;

        
public event EventHandler<ExternalDataEventArgs> JingLiShenPi;

        
public event EventHandler<ExternalDataEventArgs> ChuNaShenPi;

        
public void quqian()
        {
            
throw new NotImplementedException();
        }

        
#endregion
    }
}

 

窗體名:FrmMain

 

FrmMain
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Workflow.Activities;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;

namespace ShenPBXXT
{
    
public partial class FrmMain : Form, InterFaces.IClass
    {
        WorkflowRuntime wr;
        WorkflowInstance wfi;
        ExternalDataExchangeService edes;
        BLL.BLBXDan blbxd 
= new BLL.BLBXDan();
        
public FrmMain()
        {
            InitializeComponent();
            wr 
= new WorkflowRuntime();
            edes 
= new ExternalDataExchangeService();
            wr.AddService(edes);
            wr.WorkflowIdled 
+= new EventHandler<WorkflowEventArgs>(wr_WorkflowIdled);
            edes.AddService(
this);
            wr.AddService(
new SqlWorkflowPersistenceService("Initial Catalog=SqlPersistenceService;Data Source=192.168.1.5;uid=sa;pwd=sa"));
            wr.StartRuntime();
        }

        
void wr_WorkflowIdled(object sender, WorkflowEventArgs e)
        {
            e.WorkflowInstance.TryUnload();
        }

        
private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        
private void button1_Click(object sender, EventArgs e)
        {
            wfi 
= wr.CreateWorkflow(typeof(BaoXiaoShenPin.ShenQing));
            wfi.Start();
            Model.BXDan bxd 
= new Model.BXDan();
            
if ((Convert.ToInt32(txtBaoXiaoJin.Text.Trim().ToString())) >= 1000)
            {
                bxd.stated 
= 2;
            }
            
else
            {
                bxd.stated 
= 1;
            }
            bxd.BXName 
= txtName.Text.Trim().ToString();
            bxd.BXNeiRong 
= txtNeiRong.Text.Trim().ToString();
            bxd.BXJin 
= txtBaoXiaoJin.Text.Trim().ToString();
            bxd.BXGID 
= wfi.InstanceId.ToString();
            blbxd.Add(bxd);
            ShenQing(
nullnew InterFaces.ShenQingBaoXiao(wfi.InstanceId, Convert.ToDouble(txtBaoXiaoJin.Text.Trim().ToString())));
        }

        
private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            
if (e.KeyChar >= '0' && e.KeyChar <= '9')
            {
                e.Handled 
= false;
            }
            
else if (e.KeyChar == 8)
            {
                e.Handled 
= false;
            }
            
else
            {
                e.Handled 
= true;
            }
        }

        
#region IClass 成員

        
public event EventHandler<ExternalDataEventArgs> ShenQing;

        
public event EventHandler<ExternalDataEventArgs> CaiWuShenPi;

        
public event EventHandler<ExternalDataEventArgs> JingLiShenPi;

        
public event EventHandler<ExternalDataEventArgs> ChuNaShenPi;

        
public void quqian()
        {
            
throw new NotImplementedException();
        }

        
#endregion

        
private void button3_Click(object sender, EventArgs e)
        {
            Form1 f1 
= new Form1();
            f1.Show();
        }
    }
}

 

配置檔案:App.config

 

App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  
<appSettings>
    
<add key="SQL2000" value="server=192.168.1.3;database=Shenp;uid=sa" />
  
</appSettings>
</configuration>

 

基於WF的報銷單流轉審批業務1(淺析)
基於WF的報銷單流轉審批業務2(淺析)
基於WF的報銷單流轉審批業務3(淺析)
基於WF的報銷單流轉審批業務4(淺析)
基於WF的報銷單流轉審批業務6(淺析)