protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                StringBuilder sb = new StringBuilder();
                if (Request.QueryString["tbl"] != null && Request.QueryString["key"] != null)
                {
                    /* prevent manually constructed request that would lead to information leakage via hashing of
                     * query string and session secret, only apply for database related retrieval which are all generated by the system
                     */
                    ValidatedQS();
                    string dbConnectionString;
                    if (Request.QueryString["sys"] != null)
                    {
                        sid = byte.Parse(Request.QueryString["sys"].ToString());
                    }
                    else
                    {
                        throw new Exception("Please make sure '&sys=' is present and try again.");
                    }
                    if (new AdminSystem().IsMDesignDb(Request.QueryString["tbl"].ToString()))
                    {
                        dbConnectionString = base.SysConnectStr(sid);
                    }
                    else
                    {
                        dbConnectionString = base.AppConnectStr(sid);
                    }

                    if (Request.QueryString["multi"] != null)
                    {
                        SaveMultiDocUpload(dbConnectionString, base.AppPwd(sid), sid, true);
                    }
                    else
                    {
                        SaveUpload(dbConnectionString, sid);
                    }
                    return;

                    /* To be Deleted:
                     * DataTable dt = null;
                     * try
                     * {
                     *  if (Request.QueryString["knm"] != null && Request.QueryString["col"] != null)     // ImageButton
                     *  {
                     *      dt = (new AdminSystem()).GetDbImg(Request.QueryString["key"].ToString(), Request.QueryString["tbl"].ToString(), Request.QueryString["knm"].ToString(), Request.QueryString["col"].ToString(), dbConnectionString, base.AppPwd(sid));
                     *      Response.Buffer = true; Response.ClearHeaders(); Response.ClearContent();
                     *      Response.ContentType = "image/jpeg";
                     *      Response.AppendHeader("Content-Disposition", "Attachment; Filename=");
                     *      Response.BinaryWrite((byte[])dt.Rows[0][0]);
                     *      HttpContext.Current.ApplicationInstance.CompleteRequest();
                     *  }
                     *  else // Document.
                     *  {
                     *      dt = (new AdminSystem()).GetDbDoc(Request.QueryString["key"].ToString(), Request.QueryString["tbl"].ToString(), dbConnectionString, base.AppPwd(sid));
                     *      Response.Buffer = true; Response.ClearHeaders(); Response.ClearContent();
                     *      Response.ContentType = dt.Rows[0]["MimeType"].ToString();
                     *      Response.AppendHeader("Content-Disposition", "Attachment; Filename=" + dt.Rows[0]["DocName"].ToString());
                     *      Response.BinaryWrite((byte[])dt.Rows[0]["DocImage"]);
                     *      Response.End();
                     *  }
                     * }
                     * catch (Exception err) { ApplicationAssert.CheckCondition(false, "DnLoadModule", "", err.Message); }
                     */
                }
                else if (Request.QueryString["file"] != null)
                {
                    /* file based download needs to be catered manually by webrule for protected contents
                     * via access control in the IIS directory level(no access) and gated by dnloadmodule via server side transfer
                     */
                    try
                    {
                        bool pub = true;
                        if (LImpr != null)
                        {
                            string UsrGroup = (char)191 + base.LImpr.UsrGroups + (char)191;
                            if (UsrGroup.IndexOf((char)191 + "25" + (char)191) < 0 && UsrGroup.IndexOf((char)191 + "5" + (char)191) < 0)
                            {
                                pub = true;
                            }
                            else
                            {
                                pub = false;
                            }
                        }
                        string fileName         = Request.QueryString["file"].ToString();
                        string key              = Request.QueryString["key"].ToString();
                        string DownloadLinkCode = Session.SessionID;
                        byte[] Download_code    = System.Text.Encoding.ASCII.GetBytes(DownloadLinkCode);
                        System.Security.Cryptography.HMACSHA256 bkup_hmac = new System.Security.Cryptography.HMACSHA256(Download_code);
                        byte[] Download_hash       = bkup_hmac.ComputeHash(System.Text.Encoding.ASCII.GetBytes(fileName));
                        string Download_hashString = BitConverter.ToString(Download_hash);
                        bool   allowDownload       = Download_hashString == key;
                        fileName = fileName.ToLower().ReplaceInsensitive("/guarded/", "/source/");
                        string             url          = fileName;
                        string             fullfileName = Server.MapPath(fileName); // we enforce everything file for download is under ../files
                        System.IO.FileInfo file         = new System.IO.FileInfo(fullfileName);
                        string             oname        = file.Name;
                        if (!allowDownload && pub && !(file.Name.StartsWith("Pub") || file.Name.StartsWith("pub")))
                        {
                            if (file.Name.EndsWith(".wmv"))
                            {
                                file = new FileInfo(file.DirectoryName + "/PubMsg.wmv");
                                url  = fileName.ReplaceInsensitive(oname, "PubMsg.wmv");
                            }
                            else
                            {
                                if (LUser == null || LUser.LoginName == "Anonymous")
                                {
                                    string loginUrl = System.Web.Security.FormsAuthentication.LoginUrl;
                                    if (string.IsNullOrEmpty(loginUrl))
                                    {
                                        loginUrl = "MyAccount.aspx";
                                    }
                                    this.Redirect(loginUrl + (loginUrl.IndexOf('?') > 0 ? "&" : "?") + "wrn=1&ReturnUrl=" + Server.UrlEncode(Request.Url.PathAndQuery));
                                }
                                else
                                {
                                    throw new Exception("Access Denied");
                                }
                            }
                        }
                        Response.Buffer      = true; Response.ClearHeaders(); Response.ClearContent();
                        Response.ContentType = GetMimeTypeFromExtension(file.Extension);
                        Response.AddHeader("Content-Disposition", "Attachment; Filename=" + file.Name);
                        Response.AddHeader("Content-Length", file.Length.ToString());
                        Server.Transfer(url);
                    }
                    catch (Exception err) { ApplicationAssert.CheckCondition(false, "DnLoadModule", "", err.Message); }
                }
            }
        }
        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                StringBuilder sb = new StringBuilder();
                if (!string.IsNullOrEmpty(Request.Form["_r"])
                    ||
                    !string.IsNullOrEmpty(Request.QueryString["_r"])
                    )
                {
                    DirectPost();
                    return;
                }
                if (Request.QueryString["tbl"] != null && Request.QueryString["key"] != null)
                {
                    /* prevent manually constructed request that would lead to information leakage via hashing of
                     * query string and session secret, only apply for database related retrieval which are all generated by the system
                     */
                    if (!string.IsNullOrEmpty(Request.QueryString["_h"]))
                    {
                        ValidateQSV2();
                    }
                    else
                    {
                        ValidatedQS();
                    }
                    string dbConnectionString;
                    if (Request.QueryString["sys"] != null)
                    {
                        sid = byte.Parse(Request.QueryString["sys"].ToString());
                    }
                    else
                    {
                        throw new Exception("Please make sure '&sys=' is present and try again.");
                    }
                    if (new AdminSystem().IsMDesignDb(Request.QueryString["tbl"].ToString()))
                    {
                        dbConnectionString = base.SysConnectStr(sid);
                    }
                    else
                    {
                        dbConnectionString = base.AppConnectStr(sid);
                    }
                    DataTable dt = null;
                    try
                    {
                        if (Request.QueryString["knm"] != null && Request.QueryString["col"] != null)     // ImageButton
                        {
                            string emptyFile = "iVBORw0KGgoAAAANSUhEUgAAAhwAAAABCAQAAAA/IL+bAAAAFElEQVR42mN89p9hFIyCUTAKSAIABgMB58aXfLgAAAAASUVORK5CYII=";
                            dt = (new AdminSystem()).GetDbImg(Request.QueryString["key"].ToString(), Request.QueryString["tbl"].ToString(), Request.QueryString["knm"].ToString(), Request.QueryString["col"].ToString(), dbConnectionString, base.AppPwd(sid));
                            if (Request.QueryString["ico"] != null)
                            {
                                string icon = RO.Common3.Utils.BlobPlaceHolder(dt.Rows[0][0] as byte[], true);
                                if (icon != null)
                                {
                                    icon = icon.Replace("data:application/base64;base64,", "");
                                }
                                else
                                {
                                    icon = emptyFile;
                                }
                                ReturnAsAttachment(Convert.FromBase64String(icon), "");
                                return;
                            }
                            Response.Buffer = true; Response.ClearHeaders(); Response.ClearContent();
                            string fileContent   = dt.Rows[0][0] as byte[] == null ? emptyFile : RO.Common3.Utils.DecodeFileStream(dt.Rows[0][0] as byte[]);
                            string fileName      = "";
                            string mimeType      = "application/octet";
                            string contentBase64 = "";
                            System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                            try
                            {
                                RO.Common3.FileUploadObj fileInfo = jss.Deserialize <RO.Common3.FileUploadObj>(fileContent);
                                mimeType      = fileInfo.mimeType;
                                fileName      = fileInfo.fileName;
                                contentBase64 = fileInfo.base64;
                            }
                            catch
                            {
                                try
                                {
                                    List <RO.Common3._ReactFileUploadObj> fileList = jss.Deserialize <List <RO.Common3._ReactFileUploadObj> >(fileContent);
                                    List <FileUploadObj> x = new List <FileUploadObj>();
                                    foreach (var fileInfo in fileList)
                                    {
                                        mimeType      = fileInfo.mimeType;
                                        fileName      = fileInfo.fileName;
                                        contentBase64 = fileInfo.base64;
                                        break;
                                    }
                                }
                                catch
                                {
                                    contentBase64 = fileContent;
                                    fileName      = "";
                                    mimeType      = "image/jpeg";
                                }
                            }

                            string contentDisposition = "attachment";
                            if (!string.IsNullOrEmpty(Request.QueryString["inline"]) && Request.QueryString["inline"] == "Y")
                            {
                                contentDisposition = "inline";
                            }

                            byte[] content = new byte[0];
                            try
                            {
                                content = (byte[])Convert.FromBase64String(contentBase64);
                                Response.ContentType = mimeType;
                                Response.AppendHeader("Content-Disposition", contentDisposition + "; Filename=" + fileName);
                            }
                            catch (Exception ex)
                            {
                                if (ex != null)
                                {
                                    try
                                    {
                                        content = (byte[])dt.Rows[0][0];
                                        Response.ContentType = "image/jpeg";
                                        Response.AppendHeader("Content-Disposition", contentDisposition + "; Filename=");
                                    }
                                    catch { }
                                }
                            }
                            Response.Flush();
                            Response.BinaryWrite(content);
                            Response.End();
                        }
                        else // Document.
                        {
                            dt = (new AdminSystem()).GetDbDoc(Request.QueryString["key"].ToString(), Request.QueryString["tbl"].ToString(), dbConnectionString, base.AppPwd(sid));
                            Response.Buffer      = true; Response.ClearHeaders(); Response.ClearContent();
                            Response.ContentType = dt.Rows[0]["MimeType"].ToString();
                            string contentDisposition = "attachment";
                            if (!string.IsNullOrEmpty(Request.QueryString["inline"]) && Request.QueryString["inline"] == "Y")
                            {
                                contentDisposition = "inline";
                            }
                            Response.AppendHeader("Content-Disposition", contentDisposition + "; Filename=" + dt.Rows[0]["DocName"].ToString());
                            //Response.AppendHeader("Content-Disposition", "Attachment; Filename=" + dt.Rows[0]["DocName"].ToString());
                            Response.BinaryWrite((byte[])dt.Rows[0]["DocImage"]);
                            Response.End();
                        }
                    }
                    catch (Exception err)
                    {
                        if (!(err is ThreadAbortException))
                        {
                            ApplicationAssert.CheckCondition(false, "DnLoadModule", "", err.Message);
                        }
                    }
                }
                else if (Request.QueryString["file"] != null)
                {
                    /* file based download needs to be catered manually by webrule for protected contents
                     * via access control in the IIS directory level(no access) and gated by dnloadmodule via server side transfer
                     */
                    try
                    {
                        bool pub = true;
                        if (LImpr != null)
                        {
                            string UsrGroup = (char)191 + base.LImpr.UsrGroups + (char)191;
                            if (UsrGroup.IndexOf((char)191 + "25" + (char)191) < 0 && UsrGroup.IndexOf((char)191 + "5" + (char)191) < 0)
                            {
                                pub = true;
                            }
                            else
                            {
                                pub = false;
                            }
                        }
                        string fileName         = Request.QueryString["file"].ToString();
                        string key              = Request.QueryString["key"].ToString();
                        string DownloadLinkCode = Session.SessionID;
                        byte[] Download_code    = System.Text.Encoding.ASCII.GetBytes(DownloadLinkCode);
                        System.Security.Cryptography.HMACMD5 bkup_hmac = new System.Security.Cryptography.HMACMD5(Download_code);
                        byte[] Download_hash       = bkup_hmac.ComputeHash(System.Text.Encoding.ASCII.GetBytes(fileName));
                        string Download_hashString = BitConverter.ToString(Download_hash);
                        bool   allowDownload       = Download_hashString == key;
                        fileName = fileName.ToLower().Replace("/guarded/", "/source/");
                        string             url          = fileName;
                        string             fullfileName = Server.MapPath(fileName); // we enforce everything file for download is under ../files
                        System.IO.FileInfo file         = new System.IO.FileInfo(fullfileName);
                        string             oname        = file.Name;
                        if (!allowDownload && pub && !(file.Name.StartsWith("Pub") || file.Name.StartsWith("pub")))
                        {
                            if (file.Name.EndsWith(".wmv"))
                            {
                                file = new FileInfo(file.DirectoryName + "/PubMsg.wmv");
                                url  = fileName.Replace(oname, "PubMsg.wmv");
                            }
                            else
                            {
                                if (LUser == null || LUser.LoginName == "Anonymous")
                                {
                                    string loginUrl = System.Web.Security.FormsAuthentication.LoginUrl;
                                    if (string.IsNullOrEmpty(loginUrl))
                                    {
                                        loginUrl = "MyAccount.aspx";
                                    }
                                    this.Redirect(loginUrl + (loginUrl.IndexOf('?') > 0 ? "&" : "?") + "wrn=1&ReturnUrl=" + Server.UrlEncode(Request.Url.PathAndQuery));
                                }
                                else
                                {
                                    throw new Exception("Access Denied");
                                }
                            }
                        }
                        Response.Buffer      = true; Response.ClearHeaders(); Response.ClearContent();
                        Response.ContentType = GetMimeTypeFromExtension(file.Extension);
                        Response.AddHeader("Content-Disposition", "Attachment; Filename=" + file.Name);
                        Response.AddHeader("Content-Length", file.Length.ToString());
                        Server.Transfer(url);
                    }
                    catch (Exception err) { ApplicationAssert.CheckCondition(false, "DnLoadModule", "", err.Message); }
                }
            }
        }
        public void UpdDshFldDtl(string PublicAccess, string DshFldDtlId, string DshFldId, string DshFldDtlName, string DshFldDtlDesc, Int32 UsrId, string SystemId, string dbConnectionString, string dbPassword)
        {
            if (da == null)
            {
                throw new System.ObjectDisposedException(GetType().FullName);
            }
            OleDbConnection cn = new OleDbConnection(dbConnectionString + DecryptString(dbPassword));

            cn.Open();
            OleDbTransaction tr  = cn.BeginTransaction();
            OleDbCommand     cmd = new OleDbCommand("UpdDshFldDtl", cn);

            cmd.CommandType    = CommandType.StoredProcedure;
            cmd.CommandTimeout = 1800;
            cmd.Transaction    = tr;
            cmd.Parameters.Add("@PublicAccess", OleDbType.Char).Value = PublicAccess;
            if (DshFldDtlId == string.Empty)
            {
                cmd.Parameters.Add("@DshFldDtlId", OleDbType.Numeric).Value = System.DBNull.Value;
            }
            else
            {
                cmd.Parameters.Add("@DshFldDtlId", OleDbType.Numeric).Value = DshFldDtlId;
            }
            if (DshFldId == string.Empty)
            {
                ApplicationAssert.CheckCondition(false, "WebPartAccess", "UpdDshFldDtl", "Please select a folder and try again.");
            }
            else
            {
                cmd.Parameters.Add("@DshFldId", OleDbType.Numeric).Value = DshFldId;
            }
            if (DshFldDtlName == string.Empty)
            {
                ApplicationAssert.CheckCondition(false, "WebPartAccess", "UpdDshFldDtl", "Please enter a name for this memorized criteria and try again.");
            }
            else
            {
                cmd.Parameters.Add("@DshFldDtlName", OleDbType.VarWChar).Value = DshFldDtlName;
            }
            if (DshFldDtlDesc == string.Empty)
            {
                cmd.Parameters.Add("@DshFldDtlDesc", OleDbType.VarWChar).Value = System.DBNull.Value;
            }
            else
            {
                cmd.Parameters.Add("@DshFldDtlDesc", OleDbType.VarWChar).Value = DshFldDtlDesc;
            }
            cmd.Parameters.Add("@UsrId", OleDbType.Numeric).Value    = UsrId;
            cmd.Parameters.Add("@SystemId", OleDbType.Numeric).Value = SystemId;
            try
            {
                da.UpdateCommand = cmd;
                cmd.ExecuteNonQuery();
                tr.Commit();
            }
            catch (Exception e)
            {
                tr.Rollback();
                ApplicationAssert.CheckCondition(false, "", "", e.Message);
            }
            finally
            {
                cn.Close();
            }
            return;
        }
        public override void RestoreWaDb(string dbProviderCd, string connStr, string pwd, string waDb, string waFile, string waPath)
        {
            if (da == null)
            {
                throw new System.ObjectDisposedException(GetType().FullName);
            }
            OleDbConnection cn = new OleDbConnection(connStr + DecryptString(pwd));

            cn.Open();
            OleDbCommand cmd;

            if (dbProviderCd == "S")
            {
                cmd = new OleDbCommand("LOAD DATABASE " + waDb + " FROM '" + waFile + "'", cn);
            }
            else                //Ms Windows only for now, not Linux
            {
                cmd              = new OleDbCommand("RESTORE FILELISTONLY FROM DISK = '" + waFile + "'", cn);
                cmd.CommandType  = CommandType.Text;
                da.SelectCommand = cmd;
                DataTable dt = new DataTable();
                da.Fill(dt);
                ApplicationAssert.CheckCondition(dt.Rows.Count != 0, "DeployAccess.RestoreWaDb", "", "Resotre file does not have any logical file name:" + waFile);
                string restoreCmd = "RESTORE DATABASE " + waDb + " FROM DISK = '" + waFile + "' WITH ";
                foreach (DataRow dr in dt.Rows)
                {
                    if (dr["Type"].ToString() == "L")
                    {
                        restoreCmd += "MOVE '" + dr["LogicalName"].ToString() + "' TO '" + waPath + waDb + ".ldf',";
                    }
                    else
                    {
                        restoreCmd += "MOVE '" + dr["LogicalName"].ToString() + "' TO '" + waPath + waDb + ".mdf',";
                    }
                }
                if (restoreCmd.EndsWith(","))
                {
                    restoreCmd = restoreCmd.Remove(restoreCmd.Length - 1, 1);
                }
                cn.Close();
                cn.Open();
                cmd = new OleDbCommand(restoreCmd, cn);
            }
            cmd.CommandType    = CommandType.Text;
            cmd.CommandTimeout = 10000;
            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                if (e.Message.IndexOf("No error information available") < 0)                    // Dump&Load always throw exception regardless.
                {
                    ApplicationAssert.CheckCondition(false, "DeployAccess.RestoreWaDb", "", e.Message);
                }
            }
            finally
            {
                cn.Close();
                cn = null;
            }
            return;
        }
        private string WrGenericTranslate(string CrawlerCd, string TrlCode, string InStr, string dbConnectionString, string dbPassword)
        {
            HttpWebRequest request;
            string         posttext;
            DataTable      dt  = null;
            string         rtn = string.Empty;

            using (Access3.WebAccess dac = new Access3.WebAccess())
            {
                dt = dac.WrGetCtCrawler(CrawlerCd);
            }
            try
            {
                if (CrawlerCd == "GA")
                {
                    // Get:
                    posttext = dt.Rows[0]["PreText"].ToString() + TrlCode + dt.Rows[0]["PostText"].ToString() + HttpUtility.UrlEncode(InStr.Replace("\\", "/"));
                    request  = (HttpWebRequest)WebRequest.Create(new Uri(dt.Rows[0]["CrawlerURL"].ToString() + posttext));
                }
                else if (CrawlerCd == "GB")
                {
                    // Get google translation paid api v2:
                    string   apiKey = base.DecryptString(Config.GoogleAPIKey);
                    string[] fromTo = TrlCode.Split(new char[] { '|' });
                    posttext = dt.Rows[0]["PreText"].ToString() + apiKey + string.Format("&source={0}&target={1}", fromTo[0], fromTo[1]) + dt.Rows[0]["PostText"].ToString() + HttpUtility.UrlEncode(InStr.Replace("\\", "/"));
                    request  = (HttpWebRequest)WebRequest.Create(new Uri(dt.Rows[0]["CrawlerURL"].ToString() + posttext));
                }
                else
                {
                    // Post:
                    request               = (HttpWebRequest)WebRequest.Create(new Uri(dt.Rows[0]["CrawlerURL"].ToString()));
                    posttext              = dt.Rows[0]["PreText"].ToString() + TrlCode + dt.Rows[0]["PostText"].ToString() + HttpUtility.UrlEncode(InStr.Replace("\\", "/"));
                    request.Method        = "POST";
                    request.ContentType   = "application/x-www-form-urlencoded";
                    request.ContentLength = posttext.Length;
                    request.UserAgent     = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                    Stream       writeStream = request.GetRequestStream();
                    UTF8Encoding encoding    = new UTF8Encoding();
                    byte[]       bytes       = encoding.GetBytes(posttext);
                    writeStream.Write(bytes, 0, bytes.Length);
                    writeStream.Close();
                }
                request.Referer = dt.Rows[0]["CrawlerREF"].ToString();
                HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
                StreamReader    readStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string          page       = readStream.ReadToEnd();
                Regex           reg        = new Regex(dt.Rows[0]["ResultRegex"].ToString(), RegexOptions.IgnoreCase | RegexOptions.Multiline);
                MatchCollection matches    = reg.Matches(page);
                if (matches.Count == 1 && matches[0].Groups.Count == 2 && matches[0].Groups[1].Value != string.Empty)
                {
                    rtn = matches[0].Groups[1].Value;
                }
            }
            catch (Exception err)
            {
                ApplicationAssert.CheckCondition(false, "WrGenericTranslate", dt.Rows[0]["CrawlerURL"].ToString() + ": " + err.Message, "Translation engine cannot handle \"" + InStr + "\". Please investigate and try again.");
            }
            if (CrawlerCd == "GA" || CrawlerCd == "GB")
            {
                // google translate API returns JSONEncode(htmlencoded(string)) and we need to reverse it
                var json_encoded = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize <System.Collections.Generic.Dictionary <string, string> >(string.Format("{{\"translatedText\":\"{0}\"}}", rtn));
                rtn = System.Web.HttpUtility.HtmlDecode(json_encoded["translatedText"]);
            }
            return(rtn);
        }
        public void ExecScript(string dbProviderCd, string Source, string CmdName, string IsqlFile, CurrSrc CSrc, CurrTar CTar, string dbConnectionString, string dbPassword)
        {
            StringBuilder sbError         = new StringBuilder("");
            Regex         isqlWarningRule = new Regex(@"Level\s+([1-9],|1[0-1],)");
            Regex         isqlErrorRule   = new Regex(@"(?i)(Level\s+(1[2-9]|2[0-9]))|(Library\serror:)|(not\srecognized\sas\san\sinternal)|(isql:\sunknown\soption)|(Syntax\sError\sin)");
            Regex         batErrorRule    = new Regex(@"(?i)(\s+denied\.|\s+msg\s+|\s+error\s+|\s+failed)");
            bool          addToError      = false;
            bool          addToWarning    = false;

            sbWarning.Remove(0, sbWarning.Length);
            //OleDbDataReader drd;
            Func <object, string, bool> processResult = (v, s) =>
            {
                if (!v.Equals(System.DBNull.Value))
                {
                    if (IsqlFile == string.Empty)       // batch bcp
                    {
                        if (batErrorRule.IsMatch(s))
                        {
                            addToError = true;
                        }
                        if (addToError)
                        {
                            sbError.Append(Regex.Replace(s, @"(-P\s*\w*\s|-U\s*\w*\s)", "") + "\r\n");
                        }
                    }
                    else
                    {
                        if (isqlErrorRule.IsMatch(s))
                        {
                            addToError   = true;
                            addToWarning = false;
                        }
                        else if (isqlWarningRule.IsMatch(s))
                        {
                            addToError   = false;
                            addToWarning = true;
                        }
                        if (addToError)
                        {
                            sbError.Append(Regex.Replace(s, @"(-P\s*\w*\s|-U\s*\w*\s)", "") + "\r\n");
                        }
                        else if (addToWarning)
                        {
                            sbWarning.Append(Regex.Replace(s, @"(-P\s*\w*\s|-U\s*\w*\s)", "") + "\r\n");
                        }
                    }
                }
                return(true);
            };

            using (DbScriptAccessBase dac = GetDbScriptAccess())
            {
                dac.ExecScript(dbProviderCd, CmdName, IsqlFile, dbProviderCd == string.Empty, CSrc, CTar, dbConnectionString, dbPassword, processResult);
            }
            //while (drd.Read())
            //{
            //    if (!drd.GetValue(0).Equals(System.DBNull.Value))
            //    {
            //        if (IsqlFile == string.Empty)	// batch bcp
            //        {
            //            if (batErrorRule.IsMatch(drd.GetString(0))) { addToError = true; }
            //            if (addToError) { sbError.Append(Regex.Replace(drd.GetString(0), @"(-P\s*\w*\s|-U\s*\w*\s)", "") + "\r\n"); }
            //        }
            //        else
            //        {
            //            if (isqlErrorRule.IsMatch(drd.GetString(0)))
            //            {
            //                addToError = true;
            //                addToWarning = false;
            //            }
            //            else if (isqlWarningRule.IsMatch(drd.GetString(0)))
            //            {
            //                addToError = false;
            //                addToWarning = true;
            //            }
            //            if (addToError)
            //            {
            //                sbError.Append(Regex.Replace(drd.GetString(0), @"(-P\s*\w*\s|-U\s*\w*\s)", "") + "\r\n");
            //            }
            //            else if (addToWarning)
            //            {
            //                sbWarning.Append(Regex.Replace(drd.GetString(0), @"(-P\s*\w*\s|-U\s*\w*\s)", "") + "\r\n");
            //            }
            //        }
            //    }
            //}
            if (IsqlFile == string.Empty)               // batch bcp
            {
                ApplicationAssert.CheckCondition(!batErrorRule.IsMatch(sbError.ToString()), Source, "DbScript.ExecScript()", sbError.ToString());
            }
            else
            {
                ApplicationAssert.CheckCondition(!isqlErrorRule.IsMatch(sbError.ToString()), Source, "DbScript.ExecScript()", sbError.ToString());
            }
            if (sbWarning.ToString() != "")
            {
                sbWarning.Insert(0, Source + ": DbScript.ExecScript(): ");
            }
        }
        public string CreateProgC(bool Overwrite, DataView dv, CurrSrc CSrc, string ProgramPath, string AppNameSpace, string ObjectTypeCd, string FrameworkCd)
        {
            StreamWriter  sw;
            BinaryWriter  bw;
            FileInfo      fi;
            bool          ErrFound;
            StringBuilder sb = new StringBuilder();
            string        Framewk;

            foreach (DataRowView drv in dv)
            {
                if (drv["FrameworkCd"].ToString() == string.Empty)
                {
                    Framewk = string.Empty;
                }
                else if (drv["FrameworkCd"].ToString() == "1")
                {
                    Framewk = "Dotnet 1.1 ";
                }
                else
                {
                    Framewk = "Dotnet 2.0 ";
                }
                ErrFound = false;
                fi       = new FileInfo(ProgramPath + drv["RelativePath"].ToString() + drv["ProgramName"].ToString());
                if (!Overwrite && fi.LastWriteTime > Convert.ToDateTime(drv["ModifiedOn"].ToString()))
                {
                    ErrFound = true;
                    sb.Append("<br />" + Framewk + drv["RelativePath"].ToString() + drv["ProgramName"].ToString() + " is more recent and not over-written;");
                }
                if (!ErrFound)
                {
                    if (drv["CustomCode"].ToString().Trim() != string.Empty)
                    {
                        sw = new StreamWriter(ProgramPath + drv["RelativePath"].ToString() + drv["ProgramName"].ToString());
                        try { sw.Write(drv["CustomCode"].ToString().Replace("[[" + "?]]", AppNameSpace)); }                     //avoid being replaced by iteself.
                        catch (Exception err) { ApplicationAssert.CheckCondition(false, "", "", err.Message); }
                        finally { sw.Close(); }
                    }
                    else if (drv["CustomBin"] != null && drv["CustomBin"].ToString() != string.Empty)
                    {
                        bw = new BinaryWriter(File.Open(ProgramPath + drv["RelativePath"].ToString() + drv["ProgramName"].ToString(), FileMode.Create, FileAccess.ReadWrite));
                        try { bw.Write((Byte[])drv["CustomBin"]); }
                        catch (Exception err) { ApplicationAssert.CheckCondition(false, "", "", err.Message); }
                        finally { bw.Close(); }
                    }
                    else
                    {
                        ErrFound = true;
                        sb.Append("<br />" + drv["RelativePath"].ToString() + drv["ProgramName"].ToString() + " is ignored;");
                    }
                }
                if (!ErrFound)
                {
                    if (ObjectTypeCd == "C")                            // Client tier
                    {
                        if (FrameworkCd == "1")
                        {
                            Robot.ModifyCsproj(false, ProgramPath + "Web.csproj", drv["RelativePath"].ToString() + drv["ProgramName"].ToString(), FrameworkCd, string.Empty);
                        }
                    }
                    else if (ObjectTypeCd == "R")                       // Rule tier
                    {
                        if (drv["RelativePath"].ToString() == "Common" + CSrc.SrcSystemId.ToString() + "\\Data\\")
                        {
                            Robot.ModifyCsproj(false, ProgramPath + "Common" + CSrc.SrcSystemId.ToString() + "\\Common" + CSrc.SrcSystemId.ToString() + ".csproj", @"Data\" + drv["ProgramName"].ToString(), string.Empty, FrameworkCd);
                        }
                        else if (drv["RelativePath"].ToString().Length > 1)
                        {
                            Robot.ModifyCsproj(false, ProgramPath + drv["RelativePath"].ToString() + drv["RelativePath"].ToString().Substring(0, drv["RelativePath"].ToString().Length - 1) + ".csproj", drv["ProgramName"].ToString(), string.Empty, FrameworkCd);
                        }
                    }
                    using (Access3.GenCustomsAccess dac = new Access3.GenCustomsAccess())
                    {
                        dac.SetLastGenDt(drv["CustomDtlId"].ToString(), CSrc);
                    }
                }
            }
            return(sb.ToString());
        }
예제 #8
0
 public void LoadDataSource()
 {
     ApplicationAssert.CheckCondition(ApplicationConfiguration.DataSourceConfigFile != null, "DataSourceConfigFile参数没有设置!", ApplicationAssert.LineNumber);
     _dataSources = DataSource.GetAllDataSources(ApplicationConfiguration.DataSourceConfigFile);
 }