Esempio n. 1
0
        public bool SaveFilesAttachment(DataTable dtfileAttachments, string SaveUpdate, string Productid)
        {
            SqlConnection conn = new SqlConnection(DBConnect.dbConnectionString());
            SaveDownloadFile objSaveDownload = new SaveDownloadFile();
            bool variable = false;
            try
            {

                if (dtfileAttachments.Rows.Count > 0)
                {

                    for (int i = 0; i < dtfileAttachments.Rows.Count; i++)
                    {
                        if (SaveUpdate == "Save")
                        {
                            Thread.Sleep(1000);
                            if (!objSaveDownload.SendFile("Fk_Productid", Productid, "FilePath", "M_ProductAttachments", dtfileAttachments.Rows[i]["Path"].ToString(), dtfileAttachments.Rows[i]["Remarks"].ToString(), dtfileAttachments.Rows[i]["File Name"].ToString()))
                            {
                                variable = false;
                                break;
                            }
                        }
                        if (SaveUpdate == "Update")
                        {
                            if (dtfileAttachments.Rows[i].RowState == DataRowState.Deleted)
                            {
                                if (conn.State == ConnectionState.Open) { conn.Close(); }
                                conn.Open();
                                SqlCommand cmdDelete = new SqlCommand("DELETE FROM M_ProductAttachments WHERE FilePath = '" + dtfileAttachments.Rows[i][0, DataRowVersion.Original].ToString() + "' ", conn);
                                cmdDelete.CommandType = CommandType.Text;
                                cmdDelete.ExecuteNonQuery();
                                cmdDelete.Parameters.Clear();
                                cmdDelete.Dispose();
                                conn.Close();
                            }
                            if (dtfileAttachments.Rows[i].RowState == DataRowState.Added)
                            {
                                if (!objSaveDownload.SendFile("Fk_Productid", Productid, "FilePath", "M_ProductAttachments", dtfileAttachments.Rows[i]["Path"].ToString(), dtfileAttachments.Rows[i]["Remarks"].ToString(), dtfileAttachments.Rows[i]["File Name"].ToString()))
                                {
                                    variable = false;
                                    break;
                                }
                            }
                            if (dtfileAttachments.Rows[i].RowState == DataRowState.Modified)
                            {
                                if (conn.State == ConnectionState.Open) { conn.Close(); }
                                conn.Open();
                                if (dtfileAttachments.Rows[i][0, DataRowVersion.Original].ToString() == dtfileAttachments.Rows[i][0].ToString())
                                {
                                    SqlCommand cmdUpdate = new SqlCommand("Update M_ProductAttachments SET Remarks = '" + dtfileAttachments.Rows[i]["Remarks"].ToString() + "' , FileName = '" + dtfileAttachments.Rows[i]["File Name"].ToString() + "'  WHERE FilePath = '" + dtfileAttachments.Rows[i][0, DataRowVersion.Original].ToString() + "' ", conn);
                                    cmdUpdate.CommandType = CommandType.Text;
                                    cmdUpdate.ExecuteNonQuery();
                                    cmdUpdate.Parameters.Clear();
                                    cmdUpdate.Dispose();
                                    con.Close();
                                }
                                else
                                {
                                    SqlCommand cmdDelete = new SqlCommand("DELETE FROM M_ProductAttachments WHERE FilePath = '" + dtfileAttachments.Rows[i][0, DataRowVersion.Original].ToString() + "' ", conn);
                                    cmdDelete.CommandType = CommandType.Text;
                                    cmdDelete.ExecuteNonQuery();
                                    cmdDelete.Parameters.Clear();
                                    cmdDelete.Dispose();
                                    con.Close();

                                    if (!objSaveDownload.SendFile("Fk_Productid", Productid, "FilePath", "M_ProductAttachments", dtfileAttachments.Rows[i]["Path"].ToString(), dtfileAttachments.Rows[i]["Remarks"].ToString(), dtfileAttachments.Rows[i]["File Name"].ToString()))
                                    {
                                        variable = false;
                                        break;
                                    }
                                }
                            }
                        }
                        variable = true;
                    }
                }
                else
                {
                    variable = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ERP - Babar Medicine Company Lahore", MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (con.State == ConnectionState.Open)
                {
                    con.Close();
                }
                variable = false;
            }
            return variable;
        }
Esempio n. 2
0
 public void DownLoadFile(string path, string LocalPath, string DocumentName, string FileFormat)
 {
     SaveDownloadFile objSaveDownload = new SaveDownloadFile();
     objSaveDownload.DownLoadFile(LocalPath, path, DocumentName, FileFormat);
 }