Пример #1
0
        protected void Email_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                conn.Open();
                string name = "", id = "", kol = "";
                string name1 = "", id1 = "", kol1 = "";
                string name2 = "", id2 = "", kol2 = "";
                string name3 = "", id3 = "", kol3 = "";
                string name4 = "", id4 = "", kol4 = "";
                string dat = DateTime.Now.Date.ToLongDateString();
                string dd  = DateTime.Now.Day.ToString();
                string mm  = DateTime.Now.Month.ToString();
                string yy  = DateTime.Now.Year.ToString();
                string hh  = DateTime.Now.Hour.ToString() + "час." + DateTime.Now.Minute.ToString() + "мин.";
                //   _wz = Int32.Parse(EventId.Text);
                App_Code.Base db = new App_Code.Base(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString());
                //   DataTable data = db.GetEvent(_wz);
                DataTable dt = db.GetPartsList(_wz);
                try
                {
                    name = dt.Rows[0]["Name"].ToString();
                    id   = dt.Rows[0]["NumID"].ToString();
                    kol  = dt.Rows[0]["Kol"].ToString();
                }
                catch { }
                try
                {
                    name1 = dt.Rows[1]["Name"].ToString();
                    id1   = dt.Rows[1]["NumID"].ToString();
                    kol1  = dt.Rows[1]["Kol"].ToString();
                }
                catch { }
                try
                {
                    name2 = dt.Rows[2]["Name"].ToString();
                    id2   = dt.Rows[2]["NumID"].ToString();
                    kol2  = dt.Rows[2]["Kol"].ToString();
                }
                catch { }
                try
                {
                    name3 = dt.Rows[3]["Name"].ToString();
                    id3   = dt.Rows[3]["NumID"].ToString();
                    kol3  = dt.Rows[3]["Kol"].ToString();
                }
                catch { }
                try
                {
                    name4 = dt.Rows[4]["Name"].ToString();
                    id4   = dt.Rows[4]["NumID"].ToString();
                    kol4  = dt.Rows[4]["Kol"].ToString();
                }

                catch { }

                BaseFont baseFont = BaseFont.CreateFont(@"C:\Windows\Fonts\Arial.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);

                PdfReader  template = new PdfReader(@"C:\temp\kp.pdf");    // файл шаблона
                PdfStamper stamper  = new PdfStamper(template, new FileStream(@"C:\temp\zkp.pdf", FileMode.Create));
                AcroFields fields   = stamper.AcroFields;
                fields.AddSubstitutionFont(baseFont);
                fields.SetField("dd", dd);
                fields.SetField("mm", mm);
                fields.SetField("yy", yy);
                if (name != "")
                {
                    fields.SetField("npp1", " 1.");
                }
                fields.SetField("name", name);
                if (name1 != "")
                {
                    fields.SetField("npp2", " 2.");
                }
                fields.SetField("name1", name1);
                if (name2 != "")
                {
                    fields.SetField("npp3", " 3.");
                }
                fields.SetField("name2", name2);
                if (name3 != "")
                {
                    fields.SetField("npp4", " 4.");
                }
                fields.SetField("name3", name3);
                if (name4 != "")
                {
                    fields.SetField("npp5", " 5.");
                }
                fields.SetField("name4", name4);
                fields.SetField("id", id);
                fields.SetField("id1", id1);
                fields.SetField("id2", id2);
                fields.SetField("id3", id3);
                fields.SetField("id4", id4);
                fields.SetField("kol", kol);
                fields.SetField("kol1", kol1);
                fields.SetField("kol2", kol2);
                fields.SetField("kol3", kol3);
                fields.SetField("kol4", kol4);
                // fields.SetField("kol1", kol1);
                fields.SetField("dni", "один");
                stamper.FormFlattening = false;    // ложь - открыт для записи, истина - закрыт
                stamper.Close();
                // запись в БД
                FileStream fs  = new FileStream(@"C:\temp\zkp.pdf", FileMode.Open);
                Byte[]     pdf = new byte[fs.Length];
                fs.Read(pdf, 0, pdf.Length);
                SqlCommand cmd = new SqlCommand("insert into Documents (Name, NumEvent, Image, NameFile, Status) values (@name, @nev, @img, @namefile, @st )", conn);
                cmd.Parameters.AddWithValue("name", "запрос КП");
                cmd.Parameters.AddWithValue("nev", Id.Text);
                cmd.Parameters.Add("img", SqlDbType.Image).Value         = pdf;
                cmd.Parameters.Add("namefile", SqlDbType.NVarChar).Value = Id.Text + "/ЗКП.pdf";
                cmd.Parameters.AddWithValue("st", "отправлен");
                cmd.ExecuteNonQuery();
                fs.Close();

                //  Response.ContentType = "image"; //image/Jpeg
                //  Response.BinaryWrite(pdf);
            }

            string text = "Здравствуйте! Вышлите пожалуйста коммерческое предложение на перечень запчастей во вложенном файле";

            if (!IsAllSelected(Post))
            {
                List <string> sel = GetSelectedEmails(Post);
                for (int i = 0; i < sel.Count; i++)
                {
                    Send(sel[i], text);
                }
            }
            Msg.Text = "Запрос нв КП разослан по выбранным адресам!";
        }
Пример #2
0
        protected void Parts_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("insert into PartsList (NumEvent, Foto, namefoto, Name, NumID, Kol, Obz) values (@nev, @foto, @namefoto, @name, @numid, @kol, @obz) ", conn);
                //выбор фото из устройства
                string namePhoto = FileUpload.FileName;
                //преобразование в двоичный код
                byte[] photo = FileUpload.FileBytes;
                cmd.Parameters.AddWithValue("nev", NumEvent.Text);
                cmd.Parameters.Add("foto", SqlDbType.Image).Value        = photo;
                cmd.Parameters.Add("namefoto", SqlDbType.NVarChar).Value = namePhoto;
                cmd.Parameters.AddWithValue("name", Text1.Text);
                cmd.Parameters.AddWithValue("obz", TextBox1.Text);
                cmd.Parameters.AddWithValue("numid", Text2.Text);
                cmd.Parameters.AddWithValue("kol", Text3.Text);
                cmd.ExecuteNonQuery();
                int           ei = int.Parse(NumEvent.Text);
                App_Code.Base db = new App_Code.Base(WebConfigurationManager.ConnectionStrings["DefaultConnection"].ToString());
                DataTable     dt = db.GetPartsList(ei);
                try
                {
                    Name1.Text = dt.Rows[0]["Name"] is DBNull ? "" : dt.Rows[0]["Name"].ToString();
                    Obz1.Text  = dt.Rows[0]["Obz"] is DBNull ? "" : dt.Rows[0]["Obz"].ToString();
                    ID1.Text   = dt.Rows[0]["NumID"] is DBNull ? "" : dt.Rows[0]["NumID"].ToString();
                    Kol1.Text  = dt.Rows[0]["Kol"] is DBNull ? "" : dt.Rows[0]["Kol"].ToString();
                }

                catch { }
                try
                {
                    Name2.Text = dt.Rows[1]["Name"] is DBNull ? "" : dt.Rows[1]["Name"].ToString();
                    Obz2.Text  = dt.Rows[1]["Obz"] is DBNull ? "" : dt.Rows[1]["Obz"].ToString();
                    ID2.Text   = dt.Rows[1]["NumID"] is DBNull ? "" : dt.Rows[1]["NumID"].ToString();
                    Kol2.Text  = dt.Rows[1]["Kol"] is DBNull ? "" : dt.Rows[1]["Kol"].ToString();
                }
                catch { }
                try
                {
                    Name3.Text = dt.Rows[2]["Name"] is DBNull ? "" : dt.Rows[2]["Name"].ToString();
                    Obz3.Text  = dt.Rows[2]["Obz"] is DBNull ? "" : dt.Rows[2]["Obz"].ToString();
                    ID3.Text   = dt.Rows[2]["NumID"] is DBNull ? "" : dt.Rows[2]["NumID"].ToString();
                    Kol3.Text  = dt.Rows[2]["Kol"] is DBNull ? "" : dt.Rows[2]["Kol"].ToString();
                }
                catch { }
                try
                {
                    Name4.Text = dt.Rows[3]["Name"] is DBNull ? "" : dt.Rows[3]["Name"].ToString();
                    Obz4.Text  = dt.Rows[3]["Obz"] is DBNull ? "" : dt.Rows[3]["Obz"].ToString();
                    ID4.Text   = dt.Rows[3]["NumID"] is DBNull ? "" : dt.Rows[3]["NumID"].ToString();
                    Kol4.Text  = dt.Rows[3]["Kol"] is DBNull ? "" : dt.Rows[3]["Kol"].ToString();
                }
                catch { }
                try
                {
                    Name5.Text = dt.Rows[4]["Name"].ToString();
                    Obz5.Text  = dt.Rows[4]["Obz"].ToString();
                    ID5.Text   = dt.Rows[4]["NumID"].ToString();
                    Kol5.Text  = dt.Rows[4]["Kol"].ToString();
                }
                catch { }
            }
            Text1.Text = ""; Text2.Text = ""; Text3.Text = ""; TextBox1.Text = "";
        }