Ejemplo n.º 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string adresafizicaserver = Server.MapPath("~");
        string cale_rap           = Server.MapPath("~/Documents/Sms/");
        string cale_log           = Server.MapPath("~/Documents/Sms/");

        string               logname     = "LogSmsFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string               smsname     = "SmsTrimise" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string               fulllogname = adresafizicaserver + @"\Documents\Sms\" + logname;
        string               fullsmsname = adresafizicaserver + @"\Documents\Sms\" + smsname;
        string               datatestare = DataSelectie.Text;
        MostreDB             mostre      = new MostreDB();
        List <MostreFabrica> mostresms   = MostreFabrica.GetMostreSMS(datatestare);
        SerialPort           port        = new SerialPort();
        clsSMS               objclsSMS   = new clsSMS();
        string               portname    = ConfigurationManager.AppSettings["ComPort"].ToString();
        string               baudrate    = "9600";

        port = objclsSMS.OpenPort(portname, baudrate);

        StringBuilder updateSql  = new StringBuilder("update mostretancuri set SentSms=1 where ");
        int           countSms   = 0;
        int           countError = 0;

        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        int counter = 0;

        foreach (MostreFabrica ms in mostresms)
        {
            //create sms string
            // G:99,99;P:9,99;C:9,99;L:9,99;SUN:99,99;pH:9,99;Pct ing:-0,513;
            //Inhib:N;U:99,99;NTG:10000000;NCS:99999999
            // G-grasime; P-proteina; C-cazeina; L-lactoza; SUN- subst. uscata negrasa;
            //Pct. ing- punct inghet;
            //Inhib- reziduuri inhibitori ce poate fi P-pozitiv sau N-negativ; U- uree

            //TODO : uncomment !!!
            if (!string.IsNullOrEmpty(ms.TelContact))
            {
                if (ms.FermeNume.Length > 30)
                {
                    ms.FermeNume = ms.FermeNume.Substring(0, 30);
                }
                StringBuilder sms = new StringBuilder();
                sms.Append(ms.FermeNume + ";");
                sms.Append("G:" + ms.Grasime + ";");
                sms.Append("P:" + ms.Proteina + ";");
                sms.Append("C:" + ms.Casein + ";");
                sms.Append("L:" + ms.Lactoza + ";");
                sms.Append("SUN:" + ms.Substu + ";");
                sms.Append("pH:" + ms.Ph + ";");
                sms.Append("Pct.ing.:" + ms.Puncti + ";");
                sms.Append("Inhib:" + ms.Antib + ";");
                sms.Append("U:" + ms.Urea + ";");
                try
                {
                    sms.Append("NTG:" + ms.NTG + "000;");
                }
                catch
                {
                    sms.Append("NTG:>10000000;");
                }
                try
                {
                    sms.Append("NCS:" + ms.NCS + "000;");
                }
                catch
                {
                    sms.Append("NCS:" + ms.NCS + ";");
                }
                sms.Append("Cod:" + ms.CodBare);

                string cellnumber = Regex.Replace(ms.TelContact, @"[\s()-]", "");
                cellnumber = (cellnumber.StartsWith("0") ? "+4" + cellnumber : cellnumber);

                try
                {
                    bool res = objclsSMS.sendMsg(port, portname, "9600", cellnumber, sms.ToString());
                    if (res)
                    {
                        string strupdate = (countSms > 0) ? " or codbare ='" + ms.CodBare + "' " : " codbare ='" + ms.CodBare + "' ";
                        updateSql.Append(strupdate);
                        countSms++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, countSms + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, sms.ToString());
                    }
                    else
                    {
                        countError++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, countError + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, sms.ToString());
                    }
                }
                catch (Exception ex)
                {
                    mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, ex.Message + " - " + ex.StackTrace);
                }
                counter++;
            }
        }
        try
        {
            objclsSMS.ClosePort(port);
        }
        catch { }
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "End Data: " + DateTime.Now.ToString() + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "End Data: " + DateTime.Now.ToString() + "**********");
        // update moste tancuri set sentsms=1
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString);

        try
        {
            if (countSms > 0)
            {
                SqlCommand cmd = new SqlCommand(updateSql.ToString(), cnn);
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
            }
        }
        catch (Exception exU)
        {
            Label1.Text = " Update MostreTancuri failed! " + exU.Message;
        }


        fissms.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + smsname;
        fissms.Visible     = true;


        fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + logname;
        fislog.Visible     = true;
    }
Ejemplo n.º 2
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string adresafizicaserver = Server.MapPath("~");
        string cale_rap           = Server.MapPath("~/Documents/");
        string cale_log           = Server.MapPath("~/LogFiles/Mail/");

        string filename, serverfile;
        string paternfile;
        string strEmail = "";

        paternfile = "CSV_Registru*" + DataSelectie.Text.Trim().Replace(@"/", @"") + "*.csv";


        FilesArray1 = Directory.GetFiles(cale_rap + @"\Registru\", paternfile);
        string logname;

        logname = "LogEmailRegistru" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";


        string   txtlog = "";
        MostreDB mostre = new MostreDB();

        mostre.Addtext(adresafizicaserver + @"\Documents\Registru\FisiereTrimisePeEmail\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");

        foreach (string strFile1 in FilesArray1)
        {
            filename = strFile1.Substring(strFile1.LastIndexOf(@"\") + 1);
            string strFileXls = strFile1;
            //  if (CharCount(filename, "_") < 4 && !filename.ToUpper().EndsWith("TMP.PDF"))
            {
                serverfile = adresafizicaserver + @"\Documents\Registru\FisiereTrimisePeEmail\" + filename;
                string   withoutext = filename.Substring(0, filename.LastIndexOf('.'));
                string[] parts      = withoutext.Split('_');
                string   fermaid    = parts[parts.Length - 2];

                strEmail = GetEmailFerma(fermaid);
                if (strEmail.Trim() != "")
                {
                    /***trimitere email***/
                    MailMessage objEmail = new MailMessage();
                    string      to       = strEmail.Trim();
                    //  string to ="*****@*****.**";
                    string[] recipients = to.Split(new Char[] { ';' });
                    foreach (string recipient in recipients)
                    {
                        objEmail.To.Add(new MailAddress(recipient));
                    }


                    objEmail.From    = new MailAddress("*****@*****.**");
                    objEmail.Subject = "Raport Registru";
                    objEmail.Body    = "Atasat acestui email este raportul pentru registru";

                    objEmail.Priority   = MailPriority.High;
                    objEmail.IsBodyHtml = true;
                    try
                    {
                        if (File.Exists(serverfile))
                        {
                            File.Delete(serverfile);
                        }
                        File.Move(strFile1, serverfile);

                        objEmail.Attachments.Add(new Attachment(serverfile));
                    }
                    catch { }
                    // send xls
                    try
                    {
                        if (File.Exists(serverfile))
                        {
                            File.Delete(serverfile);
                        }
                        File.Move(strFileXls, serverfile);

                        objEmail.Attachments.Add(new Attachment(serverfile));
                    }
                    catch { }


                    try
                    {
                        SmtpClient client = new SmtpClient();

                        client.Send(objEmail);


                        txtlog = "Fisierul : " + filename + " a fost trimis.";
                    }
                    catch (Exception exc)
                    {
                        txtlog = "Send failure: " + exc;
                    }
                    mostre.Addtext(adresafizicaserver + @"\Documents\Registru\FisiereTrimisePeEmail\" + logname, txtlog);
                } //if mail exists
            }     // end count
        }         // end foreach
        string sYear      = DateTime.Now.Year.ToString();
        string sMonth     = DateTime.Now.Month.ToString();
        string sDay       = DateTime.Now.Day.ToString();
        string sErrorTime = sYear + sMonth + sDay;

        fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Registru/FisiereTrimisePeEmail/" + logname;

        fislog.Visible = true;
    }
Ejemplo n.º 3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string adresafizicaserver = Server.MapPath("~");
        string cale_rap = Server.MapPath("~/Documents/Sms/");
        string cale_log = Server.MapPath("~/Documents/Sms/");
        string logname = "LogSmsFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string smsname = "SmsTrimise" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string fulllogname = adresafizicaserver + @"\Documents\Sms\" + logname;
        string fullsmsname = adresafizicaserver + @"\Documents\Sms\" + smsname;
        DateTime datatestare = DateTime.Parse(DataSelectie.Text);
        MostreDB mostre = new MostreDB();
        List<MostreFabrica> mostresms = MostreFabrica.GetMostreSMS(datatestare);
        SerialPort port = new SerialPort();
        clsSMS objclsSMS = new clsSMS();
        string portname = ConfigurationManager.AppSettings["ComPort"].ToString();
        string baudrate = "9600";
        port = objclsSMS.OpenPort(portname, baudrate);

        StringBuilder updateSql = new StringBuilder("update mostretancuri set SentSms=1 where ");
        int countSms = 0;
        int countError = 0;

        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        int counter = 0;
        foreach (MostreFabrica ms in mostresms)
        {
           // text sms
            //TODO : uncomment !!!
            if (!string.IsNullOrEmpty(ms.TelContact))
            {
                if (ms.FermeNume.Length > 30)
                    ms.FermeNume = ms.FermeNume.Substring(0, 30);
                //  if (string.IsNullOrEmpty(ms.TelContact))
              //  ms.TelContact = "+40722217495";
                StringBuilder sms = new StringBuilder();
         //       sms.Append(ms.FermeNume + " analizele sunt incarcate pe site");
                sms.Append("In " + datatestare + " contul dvs. " + ms.FermeNume + " a fost actualizat cu rezultatele analizelor"); 
                string cellnumber = Regex.Replace(ms.TelContact, @"[\s()-]", "");
                cellnumber = (cellnumber.StartsWith("0") ? "+4"+cellnumber : cellnumber);

                try
                {
                    //todo uncomment
                    bool res = objclsSMS.sendMsg(port, portname, "9600", cellnumber, sms.ToString());
                  //  bool res = true;
                    if (res == true)
                    {
                        string cond = "(FermaID = " + ms.FermeId + " AND DataTestare = CONVERT(date, ''" + datatestare.ToShortDateString() + "', 103))";
                        string strupdate = (countSms > 0) ? " or "+ cond : cond;
                        updateSql.Append(strupdate);
                        countSms++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, countSms + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, sms.ToString());
                    }
                    else
                    {
                        countError++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, countError + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, sms.ToString());
                    }
                }
                catch (Exception ex)
                {
                      mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname,ex.Message+ " - " + ex.StackTrace);
                }
                counter++;
            }
    
        }
        try
        {
            objclsSMS.ClosePort(port);
        }
        catch { }
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "End Data: " + DateTime.Now + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "End Data: " + DateTime.Now + "**********");
        // update moste tancuri set sentsms=1
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString);

        try
        {
            if (countSms > 0)
            {
                SqlCommand cmd = new SqlCommand(updateSql.ToString(), cnn);
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
            }
        }
        catch (Exception exU)
        {
            Label1.Text = " Update MostreTancuri failed! " + exU.Message;
        }

        fissms.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + smsname;
        fissms.Visible = true;
      
   	    fislog.NavigateUrl  = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/"+logname;
        fislog.Visible = true;
    }
Ejemplo n.º 4
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string adresafizicaserver = Server.MapPath("~");
        string cale_rap = Server.MapPath("~/Documents/Sms/");
        string cale_log = Server.MapPath("~/Documents/Sms/");

        string logname = "LogSmsFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string smsname = "SmsTrimise" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string fulllogname = adresafizicaserver + @"\Documents\Sms\" + logname;
        string fullsmsname = adresafizicaserver + @"\Documents\Sms\" + smsname;
        string datatestare = DataSelectie.Text;
        MostreDB mostre = new MostreDB();
        List<MostreFabrica> mostresms = MostreFabrica.GetMostreSMS(datatestare);
        SerialPort port = new SerialPort();
        clsSMS objclsSMS = new clsSMS();
        string portname = ConfigurationManager.AppSettings["ComPort"].ToString();
        string baudrate = "9600";
        port = objclsSMS.OpenPort(portname, baudrate);

        StringBuilder updateSql = new StringBuilder("update mostretancuri set SentSms=1 where ");
        int countSms = 0;
        int countError = 0;

        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        int counter = 0;
        foreach (MostreFabrica ms in mostresms)
        {
            //create sms string
            // G:99,99;P:9,99;C:9,99;L:9,99;SUN:99,99;pH:9,99;Pct ing:-0,513;
            //Inhib:N;U:99,99;NTG:10000000;NCS:99999999
            // G-grasime; P-proteina; C-cazeina; L-lactoza; SUN- subst. uscata negrasa; 
            //Pct. ing- punct inghet; 
            //Inhib- reziduuri inhibitori ce poate fi P-pozitiv sau N-negativ; U- uree

            //TODO : uncomment !!!
            if (!string.IsNullOrEmpty(ms.TelContact))
            {
                if (ms.FermeNume.Length > 30)
                    ms.FermeNume = ms.FermeNume.Substring(0, 30);
                StringBuilder sms = new StringBuilder();
                sms.Append(ms.FermeNume + ";");
                sms.Append("G:" + ms.Grasime + ";");
                sms.Append("P:" + ms.Proteina + ";");
                sms.Append("C:" + ms.Casein + ";");
                sms.Append("L:" + ms.Lactoza + ";");
                sms.Append("SUN:" + ms.Substu + ";");
                sms.Append("pH:" + ms.Ph + ";");
                sms.Append("Pct.ing.:" + ms.Puncti + ";");
                sms.Append("Inhib:" + ms.Antib + ";");
                sms.Append("U:" + ms.Urea + ";");
                try
                {
                    sms.Append("NTG:" + ms.NTG + "000;");
                }
                catch
                {
                    sms.Append("NTG:>10000000;");
                }
                try
                {
                    sms.Append("NCS:" + ms.NCS + "000;");
                }
                catch
                {
                    sms.Append("NCS:" + ms.NCS + ";");
                }
                sms.Append("Cod:" + ms.CodBare);

                string cellnumber = Regex.Replace(ms.TelContact, @"[\s()-]", "");
                cellnumber = (cellnumber.StartsWith("0") ? "+4" + cellnumber : cellnumber);

                try
                {
                    bool res = objclsSMS.sendMsg(port, portname, "9600", cellnumber, sms.ToString());
                    if (res)
                    {
                        string strupdate = (countSms > 0) ? " or codbare ='" + ms.CodBare + "' " : " codbare ='" + ms.CodBare + "' ";
                        updateSql.Append(strupdate);
                        countSms++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, countSms + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, sms.ToString());
                    }
                    else
                    {
                        countError++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, countError + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, sms.ToString());
                    }
                }
                catch (Exception ex)
                {
                    mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, ex.Message + " - " + ex.StackTrace);
                }
                counter++;
            }
        }
        try
        {
            objclsSMS.ClosePort(port);
        }
        catch { }
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "End Data: " + DateTime.Now.ToString() + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "End Data: " + DateTime.Now.ToString() + "**********");
        // update moste tancuri set sentsms=1
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString);

        try
        {
            if (countSms > 0)
            {
                SqlCommand cmd = new SqlCommand(updateSql.ToString(), cnn);
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
            }
        }
        catch (Exception exU)
        {
            Label1.Text = " Update MostreTancuri failed! " + exU.Message;
        }


        fissms.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + smsname;
        fissms.Visible = true;


        fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + logname;
        fislog.Visible = true;
    }
Ejemplo n.º 5
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string adresafizicaserver = Server.MapPath("~");
        string cale_rap           = Server.MapPath("~/Documents/");
        string cale_log           = Server.MapPath("~/LogFiles/Mail/");

        string filename, filename_xls, serverfile;
        string paternfile;
        int    id_ferma = 0;
        string strFerma;
        string strEmail;
        string nametmp;

        if (eferma == 1)
        {
            paternfile = "*Ferma" + DataSelectie.Text.Trim().Replace(@"/", @"_") + "*.pdf";
        }
        else
        {
            paternfile = "*Fabrica" + DataSelectie.Text.Trim().Replace(@"/", @"_") + "*.pdf";
        }


        if (eferma == 1)
        {
            FilesArray1 = Directory.GetFiles(cale_rap + @"\Ferme\", paternfile);
        }
        else
        {
            FilesArray1 = Directory.GetFiles(cale_rap + @"\Fabrici\", paternfile);
        }
        string logname;

        if (eferma == 1)
        {
            logname = "LogEmailFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        }
        else
        {
            logname = "LogEmailFabrici" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        }

        string   txtlog = "";
        MostreDB mostre = new MostreDB();

        if (eferma == 1)
        {
            mostre.Addtext(adresafizicaserver + @"\Documents\Ferme\FisiereTrimisePeEmail\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        }
        else
        {
            mostre.Addtext(adresafizicaserver + @"\Documents\Fabrici\FisiereTrimisePeEmail\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        }

        foreach (string strFile1 in FilesArray1)
        {
            filename     = strFile1.Substring(strFile1.LastIndexOf(@"\") + 1);
            filename_xls = filename.Replace(".pdf", ".xls");
            string strFileXls = strFile1.Replace(".pdf", ".xls");
            if (CharCount(filename, "_") < 4 && !filename.ToUpper().EndsWith("TMP.PDF"))
            {
                if (eferma == 1)
                {
                    serverfile = adresafizicaserver + @"\Documents\Ferme\FisiereTrimisePeEmail\" + filename;
                }
                else
                {
                    serverfile = adresafizicaserver + @"\Documents\Fabrici\FisiereTrimisePeEmail\" + filename;
                }
                nametmp  = filename.Substring(filename.LastIndexOf("-"));
                strFerma = filename.Replace(nametmp, "");
                strFerma = strFerma.Substring(filename.LastIndexOf("_") + 1);
                id_ferma = Convert.ToInt32(strFerma);
                if (eferma == 1)
                {
                    strEmail = GetEmailFerma(id_ferma);
                }
                else
                {
                    strEmail = GetEmailFabrica(id_ferma);
                }

                if (strEmail.Trim() != "")
                {
                    /***trimitere email***/
                    MailMessage objEmail   = new MailMessage();
                    string      to         = strEmail.Trim();
                    string[]    recipients = to.Split(new Char[] { ';' });
                    foreach (string recipient in recipients)
                    {
                        try
                        {
                            objEmail.To.Add(new MailAddress(recipient));
                        }
                        catch (Exception ex)
                        {
                            logger.Error(string.Format("Button1_Click|ERROR:{0}", ex.Message));
                            txtlog = "Failed to add address:" + recipient;
                            if (eferma == 1)
                            {
                                mostre.Addtext(adresafizicaserver + @"\Documents\Ferme\FisiereTrimisePeEmail\" + logname, txtlog);
                            }
                            else
                            {
                                mostre.Addtext(adresafizicaserver + @"\Documents\Fabrici\FisiereTrimisePeEmail\" + logname, txtlog);
                            }
                        }
                    }

                    objEmail.From    = new MailAddress("*****@*****.**");
                    objEmail.Subject = "Raport de Analiza a Laptelui";
                    objEmail.Body    = "Atasat acestui email este raportul de analiza a laptelui";
                    //if (eferma==1)
                    {
                        objEmail.Body += " in format PDF. Pentru vizualizarea raportului veti avea nevoie de Acrobat Reader.<br/>";
                        objEmail.Body += "Puteti descarca ultima versiune de Acrobat Reader dand click pe link-ul de mai jos:<br/>";
                        objEmail.Body += "http://www.adobe.com/products/acrobat/readstep2.html";
                    }
                    objEmail.Priority   = MailPriority.High;
                    objEmail.IsBodyHtml = true;
                    try
                    {
                        if (File.Exists(serverfile))
                        {
                            File.Delete(serverfile);
                        }
                        File.Move(strFile1, serverfile);

                        objEmail.Attachments.Add(new Attachment(serverfile));
                    }
                    catch { }
                    if (eferma == 0)
                    {
                        try
                        {
                            serverfile = serverfile.Replace(".pdf", ".xls");
                            if (File.Exists(serverfile))
                            {
                                File.Delete(serverfile);
                            }
                            File.Move(strFileXls, serverfile);

                            objEmail.Attachments.Add(new Attachment(serverfile));
                        }
                        catch { }
                    }

                    try
                    {
                        SmtpClient client = new SmtpClient();

                        client.Send(objEmail);


                        if (eferma == 1)
                        {
                            txtlog = "Fermei: " + nametmp + " cu adresa de email: " + strEmail + " i-a fost trimis fisierul: " + filename;
                        }
                        else
                        {
                            txtlog = "Fabricii: " + nametmp + " cu adresa de email: " + strEmail + " i-a fost trimis fisierul: " + filename + "," + filename_xls;
                        }
                    }
                    catch (Exception exc)
                    {
                        txtlog = "Send failure: " + exc.ToString();
                    }
                    if (eferma == 1)
                    {
                        mostre.Addtext(adresafizicaserver + @"\Documents\Ferme\FisiereTrimisePeEmail\" + logname, txtlog);
                    }
                    else
                    {
                        mostre.Addtext(adresafizicaserver + @"\Documents\Fabrici\FisiereTrimisePeEmail\" + logname, txtlog);
                    }
                } //if mail exists
            }     // end count
        }
        if (eferma == 1)
        {
            fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Ferme/FisiereTrimisePeEmail/" + logname;
        }
        else
        {
            fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Fabrici/FisiereTrimisePeEmail/" + logname;
        }

        // fislog.NavigateUrl = "LogFiles/Mail/" + logname + sErrorTime+".txt";
        fislog.Visible = true;
    }
Ejemplo n.º 6
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string               adresafizicaserver = Server.MapPath("~");
        string               cale_rap           = Server.MapPath("~/Documents/Sms/");
        string               cale_log           = Server.MapPath("~/Documents/Sms/");
        string               logname            = "LogSmsFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string               smsname            = "SmsTrimise" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        string               fulllogname        = adresafizicaserver + @"\Documents\Sms\" + logname;
        string               fullsmsname        = adresafizicaserver + @"\Documents\Sms\" + smsname;
        DateTime             datatestare        = DateTime.Parse(DataSelectie.Text);
        MostreDB             mostre             = new MostreDB();
        List <MostreFabrica> mostresms          = MostreFabrica.GetMostreSMS(datatestare);
        SerialPort           port      = new SerialPort();
        clsSMS               objclsSMS = new clsSMS();
        string               portname  = ConfigurationManager.AppSettings["ComPort"].ToString();
        string               baudrate  = "9600";

        port = objclsSMS.OpenPort(portname, baudrate);

        StringBuilder updateSql  = new StringBuilder("update mostretancuri set SentSms=1 where ");
        int           countSms   = 0;
        int           countError = 0;

        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        int counter = 0;

        foreach (MostreFabrica ms in mostresms)
        {
            // text sms
            //TODO : uncomment !!!
            if (!string.IsNullOrEmpty(ms.TelContact))
            {
                if (ms.FermeNume.Length > 30)
                {
                    ms.FermeNume = ms.FermeNume.Substring(0, 30);
                }
                //  if (string.IsNullOrEmpty(ms.TelContact))
                //  ms.TelContact = "+40722217495";
                StringBuilder sms = new StringBuilder();
                //       sms.Append(ms.FermeNume + " analizele sunt incarcate pe site");
                sms.Append("In " + datatestare + " contul dvs. " + ms.FermeNume + " a fost actualizat cu rezultatele analizelor");
                string cellnumber = Regex.Replace(ms.TelContact, @"[\s()-]", "");
                cellnumber = (cellnumber.StartsWith("0") ? "+4" + cellnumber : cellnumber);

                try
                {
                    //todo uncomment
                    bool res = objclsSMS.sendMsg(port, portname, "9600", cellnumber, sms.ToString());
                    //  bool res = true;
                    if (res == true)
                    {
                        string cond      = "(FermaID = " + ms.FermeId + " AND DataTestare = CONVERT(date, ''" + datatestare.ToShortDateString() + "', 103))";
                        string strupdate = (countSms > 0) ? " or " + cond : cond;
                        updateSql.Append(strupdate);
                        countSms++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, countSms + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, sms.ToString());
                    }
                    else
                    {
                        countError++;
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, countError + ". " + ms.CodFerma + " " + ms.FermeNume + " " + cellnumber + " - " + DateTime.Now.ToString());
                        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, sms.ToString());
                    }
                }
                catch (Exception ex)
                {
                    mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, ex.Message + " - " + ex.StackTrace);
                }
                counter++;
            }
        }
        try
        {
            objclsSMS.ClosePort(port);
        }
        catch { }
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + logname, "************" + "End Data: " + DateTime.Now + "**********");
        mostre.Addtext(adresafizicaserver + @"\Documents\Sms\" + smsname, "************" + "End Data: " + DateTime.Now + "**********");
        // update moste tancuri set sentsms=1
        SqlConnection cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["fccl2ConnectionString"].ConnectionString);

        try
        {
            if (countSms > 0)
            {
                SqlCommand cmd = new SqlCommand(updateSql.ToString(), cnn);
                cmd.Connection.Open();
                cmd.ExecuteNonQuery();
                cmd.Connection.Close();
            }
        }
        catch (Exception exU)
        {
            Label1.Text = " Update MostreTancuri failed! " + exU.Message;
        }

        fissms.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + smsname;
        fissms.Visible     = true;

        fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Sms/" + logname;
        fislog.Visible     = true;
    }
Ejemplo n.º 7
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string adresafizicaserver = Server.MapPath("~");
        string cale_rap = Server.MapPath("~/Documents/");
        string cale_log = Server.MapPath("~/LogFiles/Mail/");

        string filename,filename_xls,serverfile;
        string paternfile;
      //  int id_ferma = 0;
        string strFerma;
        string strEmail = "";
        string nametmp;
      
        if (eferma == 1)
            paternfile = "Raport*" + DataSelectie.Text.Trim().Replace(@"/", @"") + "*.pdf";
        else
            paternfile = "*Fabrica" + DataSelectie.Text.Trim().Replace(@"/", @"_") + "*.pdf";


        if (eferma == 1)
            FilesArray1 = Directory.GetFiles(cale_rap + @"\Ferme\", paternfile);
        else
            FilesArray1 = Directory.GetFiles(cale_rap + @"\Fabrici\", paternfile);
        string logname;
        if (eferma == 1)
            logname = "LogEmailFerme" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
        else
            logname = "LogEmailFabrici" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
       
        string txtlog = "";
        MostreDB mostre = new MostreDB();
        if (eferma == 1)
            mostre.Addtext(adresafizicaserver + @"\Documents\Ferme\FisiereTrimisePeEmail\" + logname, "************" + "Data: " + DateTime.Now + "**********");
        else
            mostre.Addtext(adresafizicaserver + @"\Documents\Fabrici\FisiereTrimisePeEmail\" + logname, "************" + "Data: " + DateTime.Now + "**********");
   
        foreach (string strFile1 in FilesArray1)
        {
          filename = strFile1.Substring(strFile1.LastIndexOf(@"\") + 1);
		  filename_xls = filename.Replace(".pdf", ".xls");
          string strFileXls = strFile1.Replace(".pdf", ".xls");
          if (CharCount(filename, "_") < 4 && !filename.ToUpper().EndsWith("TMP.PDF"))
          {
              if (eferma == 1)
                    serverfile = adresafizicaserver + @"\Documents\Ferme\FisiereTrimisePeEmail\" + filename;
                else
                    serverfile = adresafizicaserver + @"\Documents\Fabrici\FisiereTrimisePeEmail\" + filename;
              nametmp = filename.Substring(filename.IndexOf("-") + 1, filename.LastIndexOf("_") - filename.IndexOf("-")-1);
                strFerma = filename.Substring(filename.LastIndexOf("_")+1,filename.LastIndexOf("-") - filename.LastIndexOf("_")-1);
                if (eferma == 1)
                {
                    strEmail = GetEmailFerma(strFerma);
                   
                }
               // getemailfabrica                 

                if (strEmail.Trim() != "")
                {
                    /***trimitere email***/
                    MailMessage objEmail = new MailMessage();
                    string to = strEmail.Trim();
                  //  string to ="*****@*****.**";
                    string[] recipients = to.Split(new Char[] { ';' });
                    foreach (string recipient in recipients)
                        objEmail.To.Add(new MailAddress(recipient));


                    objEmail.From = new MailAddress("*****@*****.**");
                    objEmail.Subject = "Raport de Analiza a Laptelui";
                    objEmail.Body = "Atasat acestui email este raportul de analiza a laptelui";
                    //if (eferma==1)
                    {
                        objEmail.Body += " in format PDF. Pentru vizualizarea raportului veti avea nevoie de Acrobat Reader.<br/>";
                        objEmail.Body += "Puteti descarca ultima versiune de Acrobat Reader dand click pe link-ul de mai jos:<br/>";
                        objEmail.Body += "http://www.adobe.com/products/acrobat/readstep2.html";
                    }
                    objEmail.Priority = MailPriority.High;
                    objEmail.IsBodyHtml = true;
                    try
                    {
                        if (File.Exists(serverfile))
                            File.Delete(serverfile);
                        File.Move(strFile1, serverfile);

                        objEmail.Attachments.Add(new Attachment(serverfile));
                    }
                    catch { }
                    // send xls
                    try
                        {
                            serverfile = serverfile.Replace(".pdf", ".xls");
                            if (File.Exists(serverfile))
                                File.Delete(serverfile);
                            File.Move(strFileXls, serverfile);

                            objEmail.Attachments.Add(new Attachment(serverfile));
                        }
                        catch { }
                    

                    try
                    {
                        SmtpClient client = new SmtpClient();

                        client.Send(objEmail);
                      

                        if (eferma == 1)
                            txtlog = "Fermei: " + nametmp + " cu adresa de email: " + strEmail + " i-a fost trimis fisierul: " + filename + "," + filename_xls;
                        else
                            txtlog = "Fabricii: " + nametmp + " cu adresa de email: " + strEmail + " i-a fost trimis fisierul: " + filename + "," + filename_xls;
                    }
                    catch (Exception exc)
                    {
                        txtlog = "Send failure: " + exc.ToString();
                    }
                    if (eferma == 1)
                        mostre.Addtext(adresafizicaserver + @"\Documents\Ferme\FisiereTrimisePeEmail\" + logname, txtlog);
                    else
                        mostre.Addtext(adresafizicaserver + @"\Documents\Fabrici\FisiereTrimisePeEmail\" + logname, txtlog);
                } //if mail exists

            }// end count		
        }// end foreach
        string sYear = DateTime.Now.Year.ToString();
        string sMonth = DateTime.Now.Month.ToString();
        string sDay = DateTime.Now.Day.ToString();
        string sErrorTime = sYear + sMonth + sDay;
		if (eferma==1)
   	   fislog.NavigateUrl  = HttpContext.Current.Request.ApplicationPath + @"/Documents/Ferme/FisiereTrimisePeEmail/"+logname;
	else
	    fislog.NavigateUrl = HttpContext.Current.Request.ApplicationPath + @"/Documents/Fabrici/FisiereTrimisePeEmail/"+logname;

        fislog.Visible = true;
    }
Ejemplo n.º 8
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        string adresafizicaserver = Server.MapPath("~");
        string cale_rap = Server.MapPath("~/Documents/");
        string cale_log = Server.MapPath("~/LogFiles/Mail/");

        string filename,serverfile;
        string paternfile;
        string strEmail = "";
      
         paternfile = "CSV_Registru*" + DataSelectie.Text.Trim().Replace(@"/", @"") + "*.csv";

      
        FilesArray1 = Directory.GetFiles(cale_rap + @"\Registru\", paternfile);
        string logname;
        logname = "LogEmailRegistru" + DataSelectie.Text.Trim().Replace(@"/", @"_") + ".txt";
       
       
        string txtlog = "";
        MostreDB mostre = new MostreDB();
        mostre.Addtext(adresafizicaserver + @"\Documents\Registru\FisiereTrimisePeEmail\" + logname, "************" + "Data: " + DateTime.Now.ToString() + "**********");
        
        foreach (string strFile1 in FilesArray1)
        {
          filename = strFile1.Substring(strFile1.LastIndexOf(@"\") + 1);
          string strFileXls = strFile1;
        //  if (CharCount(filename, "_") < 4 && !filename.ToUpper().EndsWith("TMP.PDF"))
          {
              
               serverfile = adresafizicaserver + @"\Documents\Registru\FisiereTrimisePeEmail\" + filename;
			  string withoutext = filename.Substring(0, filename.LastIndexOf('.')); 
              string[] parts = withoutext.Split('_');
              string fermaid = parts[parts.Length - 2];

               strEmail = GetEmailFerma(fermaid);
                if (strEmail.Trim() != "")
                {
                    /***trimitere email***/
                    MailMessage objEmail = new MailMessage();
                    string to = strEmail.Trim();
                  //  string to ="*****@*****.**";
                    string[] recipients = to.Split(new Char[] { ';' });
                    foreach (string recipient in recipients)
                        objEmail.To.Add(new MailAddress(recipient));


                    objEmail.From = new MailAddress("*****@*****.**");
                    objEmail.Subject = "Raport Registru";
                    objEmail.Body = "Atasat acestui email este raportul pentru registru";
                    
                    objEmail.Priority = MailPriority.High;
                    objEmail.IsBodyHtml = true;
                    try
                    {
                        if (File.Exists(serverfile))
                            File.Delete(serverfile);
                        File.Move(strFile1, serverfile);

                        objEmail.Attachments.Add(new Attachment(serverfile));
                    }
                    catch { }
                    // send xls
                    try
                        {
                          
                            if (File.Exists(serverfile))
                                File.Delete(serverfile);
                            File.Move(strFileXls, serverfile);

                            objEmail.Attachments.Add(new Attachment(serverfile));
                        }
                        catch { }
                    

                    try
                    {
                        SmtpClient client = new SmtpClient();

                        client.Send(objEmail);


                        txtlog = "Fisierul : " + filename + " a fost trimis.";
                    }
                    catch (Exception exc)
                    {
                        txtlog = "Send failure: " + exc;
                    }
                    mostre.Addtext(adresafizicaserver + @"\Documents\Registru\FisiereTrimisePeEmail\" + logname, txtlog);
                } //if mail exists

            }// end count		
        }// end foreach
        string sYear = DateTime.Now.Year.ToString();
        string sMonth = DateTime.Now.Month.ToString();
        string sDay = DateTime.Now.Day.ToString();
        string sErrorTime = sYear + sMonth + sDay;
   	    fislog.NavigateUrl  = HttpContext.Current.Request.ApplicationPath + @"/Documents/Registru/FisiereTrimisePeEmail/"+logname;

        fislog.Visible = true;
    }