예제 #1
0
        protected void btnUpdateCM_Command(object sender, CommandEventArgs e)
        {
            if (txtEDate.Text != "" && txtETime.Text != "")
            {
                bool chk_time = false;
                try
                {
                    double.Parse(txtETime.Text);
                    chk_time = true;
                }
                catch { ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('กรุณาใส่เวลาให้ถูกต้อง ไม่ต้องใส่ น.')", true); }

                if (chk_time)
                {
                    String NewFileDocName = "";
                    if (txtMethod.Text != "")
                    {
                        if (fileImg.HasFile)
                        {
                            string typeFile = fileImg.FileName.Split('.')[fileImg.FileName.Split('.').Length - 1];
                            if (typeFile == "jpg" || typeFile == "jpeg" || typeFile == "png")
                            {
                                NewFileDocName = "E_" + DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + fileImg.FileName.Split('.')[0];
                                NewFileDocName = "/CM/Upload/" + function.getMd5Hash(NewFileDocName) + "." + typeFile;
                                fileImg.SaveAs(Server.MapPath(NewFileDocName.ToString()));
                                string sql = "UPDATE tbl_cm_detail SET cm_detail_edate = '" + txtEDate.Text + "', cm_detail_etime = '" + txtETime.Text.Trim() + "', cm_detail_note = '" + txtNote.Text.Trim() + "', cm_detail_status_id = '1',cm_detail_eimg='" + NewFileDocName + "',cm_detail_method='" + txtMethod.Text + "' WHERE cm_detail_id = '" + Label1.Text.Replace('#', ' ').Trim() + "'";
                                if (function.MySqlQuery(sql))
                                {
                                    ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('บันทึกข้อมูลสำเร็จ')", true);
                                    BindData("");
                                }
                                else
                                {
                                    ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('ล้มเหลวเกิดข้อผิดพลาด')", true);
                                }
                            }
                            else
                            {
                                //AlertPop("Error : แนบรูปภาพล้มเหลว ไฟล์เอกสารต้องเป็น *.jpg *.jpge *.png เท่านั้น", "error");
                                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Error : แนบรูปภาพล้มเหลว ไฟล์เอกสารต้องเป็น *.jpg *.jpge *.png เท่านั้น')", true);
                            }
                        }
                        else
                        {
                            //UpdateCM("");
                            //AlertPop("Error : แนบรูปภาพล้มเหลวไม่พบไฟล์", "error");
                            ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Error : แนบรูปภาพล้มเหลวไม่พบไฟล์')", true);
                        }
                    }
                    else
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('**กรุณาใส่วิธีแก้ไข')", true);
                    }
                }
            }
        }
        protected void btnSaveRecive_Click(object sender, EventArgs e)
        {
            String NewFileDocName = "";

            if (fileDoc.HasFile)
            {
                string typeFile = fileDoc.FileName.Split('.')[fileDoc.FileName.Split('.').Length - 1];
                if (typeFile == "jpg" || typeFile == "jpeg" || typeFile == "png")
                {
                    if (txtDateRecive.Text.Trim() != "")
                    {
                        NewFileDocName = Session["CodePK"].ToString() + "_Recive" + Quotations_id + new Random().Next(1000, 9999);
                        NewFileDocName = "/Techno/Upload/" + function.getMd5Hash(NewFileDocName) + "." + typeFile;
                        fileDoc.SaveAs(Server.MapPath(NewFileDocName.ToString()));

                        try { double.Parse(txtPrice.Text); }
                        catch { txtPrice.Text = "0.00"; }

                        string sql_text   = "quotations_date_recive = '" + txtDateRecive.Text.Trim() + "',quotations_company_price='" + double.Parse(txtPrice.Text) + "',quotations_doc_img='" + NewFileDocName + "'";
                        string condition  = "quotations_id = '" + Session["Quota_id"].ToString() + "'";
                        string sql_update = "UPDATE tbl_quotations SET " + sql_text + " WHERE " + condition;
                        function.MySqlQuery(sql_update);
                        Response.Redirect("/Techno/TechnoFormDetail");
                    }
                    else
                    {
                        //AlertPop("Error : แนบรูปภาพล้มเหลว ไฟล์เอกสารต้องเป็น *.jpg *.jpge *.png เท่านั้น", "error");
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('กรุณาใส่วันที่')", true);
                    }
                }
                else
                {
                    //AlertPop("Error : แนบรูปภาพล้มเหลว ไฟล์เอกสารต้องเป็น *.jpg *.jpge *.png เท่านั้น", "error");
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Error : แนบรูปภาพล้มเหลว ไฟล์เอกสารต้องเป็น *.jpg *.jpge *.png เท่านั้น')", true);
                }
            }
            else
            {
                //AlertPop("Error : แนบรูปภาพล้มเหลวไม่พบไฟล์", "error");
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Error : แนบรูปภาพล้มเหลวไม่พบไฟล์')", true);
            }
        }
예제 #3
0
 public void DownLoad(string FName)
 {
     try
     {
         string       strURL   = FName;
         string[]     typeFile = FName.Split('/');
         WebClient    req      = new WebClient();
         HttpResponse response = HttpContext.Current.Response;
         response.Clear();
         response.ClearContent();
         response.ClearHeaders();
         response.Buffer = true;
         response.AddHeader("Content-Disposition", "attachment;filename=\"" + function.getMd5Hash(Session["CodePK"].ToString() + DateTime.Now) + "." + typeFile[typeFile.Length - 1].Split('.')[1] + "\"");
         byte[] data = req.DownloadData(Server.MapPath(strURL));
         response.BinaryWrite(data);
         response.End();
     }
     catch
     {
     }
 }
        protected void btnSaveCM_Click(object sender, EventArgs e)
        {
            String NewFileDocName = "";

            if (fileImg.HasFile)
            {
                string typeFile = fileImg.FileName.Split('.')[fileImg.FileName.Split('.').Length - 1];
                if (typeFile == "jpg" || typeFile == "jpeg" || typeFile == "png")
                {
                    NewFileDocName = DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + fileImg.FileName.Split('.')[0];
                    NewFileDocName = "/CM/Upload/" + function.getMd5Hash(NewFileDocName) + "." + typeFile;
                    fileImg.SaveAs(Server.MapPath(NewFileDocName.ToString()));

                    string sql_insert = "INSERT INTO tbl_cm_detail (cm_detail_driver_id,cm_detail_problem,cm_detail_status_id,cm_detail_channel,cm_detail_sdate,cm_detail_stime,cm_detail_simg,cm_detail_note,cm_cpoint,cm_point,cm_user) VALUES ('" + txtDeviceAdd.SelectedValue + "','" + txtProblem.Text + "','0','" + txtChannel.Text + "','" + txtSDate.Text + "','" + txtSTime.Text + "','" + NewFileDocName + "','" + txtNote.Text + "','" + txtCpoint.SelectedValue + "','" + txtPoint.Text.Trim() + "','" + Session["User"].ToString() + "')";
                    if (function.MySqlQuery(sql_insert))
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('บันทึกข้อมูลสำเร็จ')", true);
                        BindData("");
                        ClearDate();
                    }
                    else
                    {
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('ล้มเหลว เกิดข้อผิดพลาด')", true);
                    }
                }
                else
                {
                    //AlertPop("Error : แนบรูปภาพล้มเหลว ไฟล์เอกสารต้องเป็น *.jpg *.jpge *.png เท่านั้น", "error");
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Error : แนบรูปภาพล้มเหลว ไฟล์เอกสารต้องเป็น *.jpg *.jpge *.png เท่านั้น')", true);
                }
            }
            else
            {
                //AlertPop("Error : แนบรูปภาพล้มเหลวไม่พบไฟล์", "error");
                ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", "alert('Error : แนบรูปภาพล้มเหลวไม่พบไฟล์')", true);
            }
        }