Beispiel #1
0
        public bool InsertCompanyAttach(List <MAS_COMPANYATTACHMENT> lData)
        {
            IDbConnection conn = null;
            bool          ret  = false;

            try
            {
                //SET CONNECTION
                conn = ConnectionFactory.GetConnection();
                conn.ConnectionString = ConfigurationManager.GetConfiguration().DbConnectionString;

                //OPEN CONNECTION
                conn.Open();

                Mas_BiddingCompanyBL bl = new Mas_BiddingCompanyBL(conn);
                /******* Inset table [tb_mas_CompanyAttachment] *******/
                foreach (var item in lData)
                {
                    MAS_COMPANYATTACHMENT data = new MAS_COMPANYATTACHMENT();
                    data = item;
                    ret  = bl.InsertCompanyAttachData(data);
                }

                /******************************************************/
            }
            catch (Exception ex)
            {
                ret = false;

                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
            finally
            {
                if (conn != null)
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                    conn.Dispose();
                }
            }

            return(ret);
        }
Beispiel #2
0
        private List <MAS_COMPANYATTACHMENT> SetCompanyFileUpload(string CompanyNo)
        {
            List <MAS_COMPANYATTACHMENT> lCompanyAttach = new List <MAS_COMPANYATTACHMENT>();

            try
            {
                string strPathFile     = ConfigurationManager.GetConfiguration().AttachFilePath;
                string strPathDate     = DateTime.Now.ToString("ddMMyyyy");
                string strUploadFolder = ConfigurationManager.GetConfiguration().CompanyUploadFolder;

                string pathUpload = strPathFile + strUploadFolder + "/" + strPathDate + "/" + CompanyNo + "/";
                //String ServerMapPath = Server.MapPath(pathUpload);

                /**************** Upload File To Server ***********************/
                if (!System.IO.Directory.Exists(Server.MapPath(pathUpload)))
                {
                    System.IO.Directory.CreateDirectory(Server.MapPath(pathUpload));
                }
                if (fuCompanyCert.HasFile)
                {
                    //string fileName = fuCompanyCert.FileName;
                    //String ServerMapPath = Server.MapPath(pathUpload);
                    //fuCompanyCert.PostedFile.SaveAs(ServerMapPath + fuCompanyCert.FileName);

                    string fileName = Path.GetFileName(fuCompanyCert.PostedFile.FileName);
                    //Save files to disk
                    fuCompanyCert.SaveAs(Server.MapPath(pathUpload + fileName));


                    MAS_COMPANYATTACHMENT data = new MAS_COMPANYATTACHMENT();
                    data.CompanyNo      = Int64.Parse(CompanyNo);
                    data.AttachFilePath = pathUpload + fileName;
                    data.FileName       = fileName;
                    data.Description    = "หนังสือรับรองบริษัท";
                    data.CreatedBy      = GetIPAddress();
                    data.CreatedDate    = DateTime.Now;
                    data.UpdatedBy      = GetIPAddress();
                    data.UpdatedDate    = DateTime.Now;

                    lCompanyAttach.Add(data);
                }

                if (fuVat20.HasFile)
                {
                    //string fileName = fuVat20.FileName;
                    ////pathUpload = pathUpload + fileName;
                    //String ServerMapPath = Server.MapPath(pathUpload);
                    //fuCompanyCert.PostedFile.SaveAs(ServerMapPath + fuVat20.FileName);

                    string fileName = Path.GetFileName(fuVat20.PostedFile.FileName);
                    //Save files to disk
                    fuVat20.SaveAs(Server.MapPath(pathUpload + fileName));

                    MAS_COMPANYATTACHMENT data = new MAS_COMPANYATTACHMENT();
                    data.CompanyNo      = Int64.Parse(CompanyNo);
                    data.AttachFilePath = pathUpload + fileName;
                    data.FileName       = fileName;
                    data.Description    = "เอกสาร ภพ.20";
                    data.CreatedBy      = GetIPAddress();
                    data.CreatedDate    = DateTime.Now;
                    data.UpdatedBy      = GetIPAddress();
                    data.UpdatedDate    = DateTime.Now;

                    lCompanyAttach.Add(data);
                }

                if (fuIDCard.HasFile)
                {
                    //string fileName = fuIDCard.FileName;
                    ////pathUpload = pathUpload + fileName;
                    //String ServerMapPath = Server.MapPath(pathUpload);
                    //fuCompanyCert.PostedFile.SaveAs(ServerMapPath + fuIDCard.FileName);

                    string fileName = Path.GetFileName(fuIDCard.PostedFile.FileName);
                    //Save files to disk
                    fuIDCard.SaveAs(Server.MapPath(pathUpload + fileName));


                    MAS_COMPANYATTACHMENT data = new MAS_COMPANYATTACHMENT();
                    data.CompanyNo      = Int64.Parse(CompanyNo);
                    data.AttachFilePath = pathUpload + fileName;
                    data.FileName       = fileName;
                    data.Description    = "บัตรประจำตัวประชาชน";
                    data.CreatedBy      = GetIPAddress();
                    data.CreatedDate    = DateTime.Now;
                    data.UpdatedBy      = GetIPAddress();
                    data.UpdatedDate    = DateTime.Now;

                    lCompanyAttach.Add(data);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);

                throw ex;
            }

            return(lCompanyAttach);
        }
Beispiel #3
0
        public bool UpdateCompanyAttach(List <MAS_COMPANYATTACHMENT> lData, string CompanyNo)
        {
            IDbConnection  conn = null;
            IDbTransaction tran = null;

            bool ret = false;

            try
            {
                //SET CONNECTION
                conn = ConnectionFactory.GetConnection();
                conn.ConnectionString = ConfigurationManager.GetConfiguration().DbConnectionString;

                //OPEN CONNECTION
                conn.Open();
                tran = conn.BeginTransaction(IsolationLevel.Serializable);

                Mas_BiddingCompanyBL bl = new Mas_BiddingCompanyBL(conn, tran);
                /********** Delete CompanyAttach before Insert **********/
                bool retDel = bl.DeleteCompanyAttachData(CompanyNo);
                /********************************************************/
                /******* Inset table [tb_mas_CompanyAttachment]  After delete *******/
                if (retDel)
                {
                    foreach (MAS_COMPANYATTACHMENT item in lData)
                    {
                        MAS_COMPANYATTACHMENT data = new MAS_COMPANYATTACHMENT();
                        data = item;
                        ret  = bl.InsertCompanyAttachData(data);
                    }
                }
                /******************************************************/

                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();

                ret = false;

                logger.Error(ex.Message);
                logger.Error(ex.StackTrace);
            }
            finally
            {
                if (tran != null)
                {
                    tran.Dispose();
                }

                if (conn != null)
                {
                    if (conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                    conn.Dispose();
                }
            }

            return(ret);
        }