C#Sendfax

using FAXCOMLib; 

 private void SendFax(string FaxNumber,string FaxFile, string RecMan ,string RecCompany,string RecAddress,string SendMan,string SendCompany,string FaxTitle,string SendCompAddress)
  {
   string sql = "select * from Fax where FaxNumber=" + FaxNumber;
   SqlConnection conn = new SqlConnection(connstr);
   cmd = new SqlCommand(sql,conn);
   conn.Open();
   dr = cmd.ExecuteReader();
   
   if(dr.Read())
   {
    Session["send"] = dr["SendFlagID"].ToString();
    if(!Convert.ToBoolean(Session["send"]))
    {
     if(Convert.ToBoolean(dr["FaxNumber"]))
     {
      if(FaxFile!="")
      {
       try
       {
        FileInfo file = new FileInfo(FaxFile);
        FAXCOMLib.FaxDoc fd = null;
        FaxServer fs = null;
        if(file.Exists)
        {
         try
         {
          fs =new FaxServerClass();
          fd = (FaxDoc)fs.CreateDocument(file.FullName);
         }
         catch(Exception ex)
         {
          string Showex = ex.ToString();
         }  
        }
        try
        {
         fs.Connect(Environment.MachineName);
        }
        catch(Exception error)
        {
         throw new Exception(error.Message,error);
        }
        try
        {
         fd.FaxNumber=FaxNumber;
        }
        catch(Exception error)
        {
         throw new Exception(error.Message,error);
        }
     
        fd.FileName=FaxFile;
        fd.RecipientName=RecMan;
        fd.RecipientCompany=RecCompany;
        fd.RecipientAddress=RecAddress;
        fd.SenderName=SendMan;
        fd.SenderCompany=SendCompany;
        fd.DisplayName=FaxTitle;
        fd.SenderAddress=SendCompAddress;
        fd.ConnectionObject=fs;
        try
        {
         int send = fd.Send();
        }
        catch(Exception error)
        {
         throw new Exception(error.Message,error);
        }
        FaxSendFlag=1;
        Message.Visible=true;
        Message.Text="发送成功!";
       }
       catch(Exception error)
       {
        throw new Exception("Create fax error"+error.Message,error);
       }
      }
      else
      {
       Message.Visible=true;
       Message.Text="发送失败!";
       FaxSendFlag=0;
      }
   
      if(FaxSendFlag==1)
      {
       UpdateSql();
      }
      else
       if(FaxSendFlag==0)
      {
       txtRemark.Text="";
       txtFaxTitle.Text="";
       UpdateSqlEvent();
      }
     }
     else
     {
      Response.Write("<script>alert('服务器忙,请稍后再试!');window.window.location.href='SendFax.aspx';</script>");
      txtRemark.Text="";
      txtFaxTitle.Text="";
     }
    }
    else
    {
     if(FaxFile!="")
     {
      try
      {
       FileInfo file = new FileInfo(FaxFile);
       FAXCOMLib.FaxDoc fd = null;
       FaxServer fs = null;
       if(file.Exists)
       {
        try
        {
         fs =new FaxServerClass();
         fd = (FaxDoc)fs.CreateDocument(file.FullName);
        }
        catch(Exception ex)
        {
         string Showex = ex.ToString();
        }  
       }
       try
       {
        fs.Connect(Environment.MachineName);
       }
       catch(Exception ex)
       {
        string Showex = ex.ToString();
       }
       try
       {
        fd.FaxNumber=FaxNumber;
       }
       catch(Exception ex)
       {
        string Showex = ex.ToString();
       }
     
       fd.FileName=FaxFile;
       fd.RecipientName=RecMan;
       fd.RecipientCompany=RecCompany;
       fd.RecipientAddress=RecAddress;
       fd.SenderName=SendMan;
       fd.SenderCompany=SendCompany;
       fd.DisplayName=FaxTitle;
       fd.SenderAddress=SendCompAddress;
       fd.ConnectionObject=fs;
       try
       {
        int send = fd.Send();
       }
       catch(Exception ex)
       {
        string Showex = ex.ToString();
       }
       FaxSendFlag=1;
       Message.Visible=true;
       Message.Text="发送成功!";
      }
      catch(Exception error)
      {
       throw new Exception("Create fax error"+error.Message,error);
      }
     }
     else
     {
      Message.Visible=true;
      Message.Text="发送失败!";
      FaxSendFlag=0;
     }
   
     if(FaxSendFlag==1)
     {
      UpdateSql();
     }
     else
      if(FaxSendFlag==0)
     {
      txtRemark.Text="";
      txtFaxTitle.Text="";
      UpdateSqlEvent();
     }
    }
   }
   dr.Close();
   conn.Close();
   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值