C#Sendfax

来源:互联网 发布:矩阵按键引脚 编辑:程序博客网 时间:2024/06/04 21:55

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();
   }

原创粉丝点击