Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            string query = "select * from bsm031t where cd_astore = :cd_astore and fg_use = '1'";
            //string connString = "Data Source=124.137.10.26:1521/wmalldev;User Id=wmalldev;Password=wmall#dev;Persist Security Info=True;";
            string connString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=124.137.10.26)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=wmalldev)));User Id=wmalldev;Password=wmall#dev;";

            OracleDacHelper.DefaultConnectionString = connString;
            using (var dac = new OracleDacHelper())
            {
                var ds = dac.ExecuteQuery(query,
                                          new string[] {
                    ":cd_astore"
                }, new object[] {
                    "01"
                });
                dataGridView1.DataSource = ds.Tables[0];
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 메시지 중복 처리
        /// 1) 중복 메시지 코드 찾기
        /// 2) 한 코드만 사용, 나머지 삭제
        /// 3) 삭제 하기 전에 소스 바꾸고 저장 & 메시지 삭제
        /// </summary>
        private void ProcessDupMsgFiles()
        {
            #region Find dup msg and and get list of code

            lblProgress.Text = "중복 메시지 검색 중...";
            Application.DoEvents();

            /*
             * SELECT * FROM SYT012T mto
             *      INNER JOIN
             *      (SELECT NM_MSG FROM SYT012T mtp
             *              WHERE mtp.CD_BIZ_DIV = 'PS' AND mtp.CD_MSG_DIV = 'P'
             *              GROUP BY mtp.NM_MSG
             *              HAVING COUNT(*) > 1
             *              ) mtp ON mto.NM_MSG = mtp.NM_MSG
             * WHERE mto.CD_BIZ_DIV = 'PS' AND mto.CD_MSG_DIV = 'P'
             * ORDER BY mto.NM_MSG DESC;
             *
             */

            Dictionary <string, List <string> > dupCodes = new Dictionary <string, List <string> >();
            using (var dac = new OracleDacHelper())
            {
                var query = "SELECT * FROM SYT012T mto INNER JOIN (SELECT NM_MSG FROM SYT012T mtp WHERE mtp.CD_BIZ_DIV = 'PS' AND mtp.CD_MSG_DIV = 'A' GROUP BY mtp.NM_MSG HAVING COUNT(*) > 1) mtp ON mto.NM_MSG = mtp.NM_MSG WHERE mto.CD_BIZ_DIV = 'PS' AND mto.CD_MSG_DIV = 'A' ORDER BY mto.NM_MSG DESC, mto.CD_MSG ASC";

                var dupDataset = dac.ExecuteQuery(query, null, null);

                string lastNmMsg = string.Empty;
                string lastCdMsg = string.Empty;
                foreach (DataRow dr in dupDataset.Tables[0].Rows)
                {
                    List <string> lst = null;

                    string cdMsg = dr["CD_MSG"].ToString();
                    string nmMsg = dr["NM_MSG"].ToString();

                    if (!lastNmMsg.Equals(nmMsg))
                    {
                        lst = new List <string>();
                        dupCodes.Add(cdMsg, lst);

                        lastCdMsg = cdMsg;
                        lastNmMsg = nmMsg;
                    }
                    else
                    {
                        lst = dupCodes[lastCdMsg];
                    }

                    lst.Add(cdMsg);
                }
            }

            #endregion

            #region Search and get related cs file

            lblProgress.Text = "처리 할 소스 파일 리스트 만드는 중...";
            Application.DoEvents();

            // get list of files exception designer.cs
            List <string> processingFiles = new List <string>();
            var           files           = Directory.GetFiles(txtDupSrcPath.Text, "*.cs", SearchOption.AllDirectories);
            foreach (var file in files)
            {
                try
                {
                    string fileContent = File.ReadAllText(file, Encoding.UTF8);
                    if (fileContent.Contains("ConfigData.Current.SysMessage.GetMessage"))
                    {
                        processingFiles.Add(file);

                        lblProgress.Text = "처리 할 소스 파일 리스트 만드는 중..." + Path.GetFileName(file);
                        Application.DoEvents();
                    }
                }
                catch
                {
                }
            }

            #endregion

            #region Search in POS source, replace all code with first code if above

            lblProgress.Text = "중복 메시지를 처리 중...";
            Application.DoEvents();

            // dupCodes
            // Search in each key of dupCodes, find all msg code, replace with keyCode
            foreach (var file in processingFiles)
            {
                try
                {
                    string fileContent = File.ReadAllText(file, Encoding.UTF8);
                    lblProgress.Text = "중복 메시지를 처리 중..." + Path.GetFileName(file);
                    Application.DoEvents();

                    bool changed = false;

                    foreach (var key in dupCodes.Keys)
                    {
                        List <string> lst = dupCodes[key];
                        lst.Remove(key);

                        foreach (var code in lst)
                        {
                            string rt = string.Format("Current.SysMessage.GetMessage(\"{0}\")", code);
                            if (!fileContent.Contains(rt))
                            {
                                continue;
                            }

                            fileContent = fileContent.Replace(rt, string.Format("Current.SysMessage.GetMessage(\"{0}\")", key));
                            changed     = true;
                        }
                    }

                    if (changed)
                    {
                        File.WriteAllText(file, fileContent, Encoding.UTF8);
                    }
                }
                catch
                {
                }
            }

            lblProgress.Text = "중복 메시지를 처리 완료..." + processingFiles.Count.ToString();
            Application.DoEvents();

            #endregion

            #region 메시지를 디비에서 삭제

            // 메시지를 디비에서 삭제
            lblProgress.Text = "중복 메시지를 처리 중...";
            Application.DoEvents();

            using (var dac = new OracleDacHelper())
            {
                foreach (var key in dupCodes.Keys)
                {
                    List <string> lst = dupCodes[key];
                    lst.Remove(key);
                    foreach (var code in lst)
                    {
                        // Delete from DB
                        var query = string.Format("DELETE FROM SYT012T mtp WHERE mtp.CD_BIZ_DIV = 'PS' AND mtp.CD_MSG_DIV = 'A' AND mtp.CD_MSG = '{0}'", code);
                        dac.ExecuteNonQuery(query, null, null);
                    }
                }
            }

            #endregion

            lblProgress.Text = "작업 완료.";
            Application.DoEvents();
        }