コード例 #1
0
        public static List <CustomGroupList> CustomGroupList2(string person)
        {
            List <CustomGroupList> list = new List <CustomGroupList>();

            string query = string.Format("select g_name, g_member from TB_CUSTOM_GROUP where g_owner = N'{0}' and g_member != '-'", person);

            using (GlobalService.Reader = DataService.GetInstance().ExecuteReader(query))
            {
                while (GlobalService.Reader.Read())
                {
                    list.Add(new CustomGroupList {
                        Group = GlobalService.Reader.GetString(0), Member = GlobalService.Reader.GetString(1), Division = ""
                    });
                }
            }

            List <CustomGroupList> tmpList = list;

            foreach (CustomGroupList item in list)
            {
                var obj = tmpList.FirstOrDefault(x => x.Member == item.Member);
                if (obj != null)
                {
                    obj.Division = UserUtil.IsCnMember(item.Member.Trim()) ? UserUtil.GetCnDivision(item.Member.Trim())
                        : UserUtil.IsJpMember(item.Member.Trim()) ? UserUtil.GetJpDivision(item.Member.Trim())
                        : UserUtil.IsVnMember(item.Member.Trim()) ? UserUtil.GetVnDivision(item.Member.Trim()) : UserUtil.GetDivision(item.Member.Trim());
                }
            }

            return(list);
        }
コード例 #2
0
        public static void AutoDeleteData()
        {
            List <string> pathList = new List <string>();
            string        q1       = string.Format("select r_path from " + GlobalService.DbTable + " where r_deletedate <= getdate() and r_owner = N'{0}'", GlobalService.User);

            using (IDataReader reader = DataService.GetInstance().ExecuteReader(q1))
            {
                while (reader.Read())
                {
                    pathList.Add(reader.GetString(0).Trim());
                }
            }

            pathList = pathList.Distinct().ToList();

            foreach (string path in pathList)
            {
                List <string> sharedList = DataUtil.GetSharedList(GlobalService.DbTable, path);

                string sPath = path.Contains("'") ? path.Replace("'", "''") : path;

                foreach (string shared in sharedList)
                {
                    if (shared == "-")
                    {
                        continue;
                    }

                    if (!UserUtil.IsCnMember(shared.Trim()) && !UserUtil.IsVnMember(shared.Trim()) && !UserUtil.IsJpMember(shared.Trim()))
                    {
                        try
                        {
                            string tableName  = "TB_" + AdUtil.GetUserIdByUsername(shared.Trim(), "kmhk.local");
                            string sharedText = string.Format("delete from " + tableName + " where r_path = N'{0}'", sPath);
                            DataService.GetInstance().ExecuteNonQuery(sharedText);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine("Shared: " + shared);
                            Debug.WriteLine(ex.Message + ex.StackTrace);
                        }
                    }
                    else
                    {
                        string sharedText = string.Format("delete from TB_OUTSIDE_SHARE where o_path = N'{0}'", sPath);
                        DataService.GetInstance().ExecuteNonQuery(sharedText);
                    }
                }
            }

            string query = "delete from " + GlobalService.DbTable + " where r_deletedate <= getdate()";

            DataService.GetInstance().ExecuteNonQuery(query);
        }
コード例 #3
0
        public static void SendNotificationEmail(List <string> receiverList)
        {
            try
            {
                string fromEmail = AdUtil.GetEmailByUsername(GlobalService.User, "kmhk.local");

                string hostname = "Kdmail.km.local";

                string text = "Dear colleague,<br/><br/>You have received file from " + GlobalService.User + ". Please use the link below to read file.<br/><br/>" +
                              "<a href=\"\\\\172.16.13.231\\project\\KDTHK-DM\\littlesource\\LittleCloud.xlsm\">Installation Source (Excel 2007 or above)</a><br/><br/>" +
                              "<a href=\"\\\\172.16.13.231\\project\\KDTHK-DM\\littlesource\\LittleCloud.xls\">Installation Source (Excel 2003 only)</a><br/><br/>" +
                              "If you have any questions, please follow the instruction below.<br/><a href=\"\\\\172.16.13.231\\project\\KDTHK-DM\\littlesource\\Enable Macro.pdf\">Installation Guide</a><br/><br/>Regards";

                string content = "<p><span style=\"font-family: Calibri;\">" + text + "</span></p>";

                string subject = "File Received";

                foreach (string user in receiverList)
                {
                    string domain = UserUtil.IsCnMember(user) ? "kmcn.local"
                        : UserUtil.IsVnMember(user) ? "kdtvn.local"
                        : UserUtil.IsJpMember(user) ? "km.local" : "kmhk.local";

                    string toEmail = AdUtil.GetEmailByUsername(user, domain);

                    if (user == GlobalService.User)
                    {
                        continue;
                    }

                    if (!IsEmailSent(toEmail))
                    {
                        SmtpClient client = new SmtpClient(hostname);
                        client.DeliveryMethod = SmtpDeliveryMethod.Network;

                        MailMessage mail = new MailMessage(fromEmail, toEmail);
                        mail.IsBodyHtml = true;
                        mail.Subject    = subject;
                        mail.Body       = content;
                        client.Send(mail);

                        string query = string.Format("insert into TB_EMAIL_RECORD (e_datetime, e_name, e_from, e_receiver, e_to) values ('{0}', N'{1}', N'{2}', N'{3}', N'{4}')", DateTime.Now.ToString("yyyy/MM/dd HH:mm"),
                                                     GlobalService.User, fromEmail, user, toEmail);
                        DataService.GetInstance().ExecuteNonQuery(query);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
            }
        }
コード例 #4
0
        public static void DeleteData(DataTable table, string path)
        {
            string sPath = path.Contains("'") ? path.Replace("'", "''") : path;

            //DataRow[] rows = table.Select(string.Format("filepath = '{0}'", sPath));

            DataRow[] rows = (from row in table.AsEnumerable()
                              where row.RowState != DataRowState.Deleted && row.RowState != DataRowState.Deleted && row.Field <string>("filepath") == path
                              select row).ToArray();

            List <string> queryList = new List <string>();

            foreach (DataRow row in rows)
            {
                string owner = row["fileowner"].ToString().Trim();

                if (owner == GlobalService.User)
                {
                    List <string> sharedList = GetSharedList(GlobalService.DbTable, sPath);

                    foreach (string shared in sharedList)
                    {
                        if (shared == "-")
                        {
                            continue;
                        }

                        if (!UserUtil.IsCnMember(shared.Trim()) && !UserUtil.IsVnMember(shared.Trim()) && !UserUtil.IsJpMember(shared.Trim()))
                        {
                            string tableName  = "TB_" + AdUtil.GetUserIdByUsername(shared, "kmhk.local");
                            string sharedText = string.Format("delete from " + tableName + " where r_path = N'{0}'", sPath);
                            queryList.Add(sharedText);
                        }
                        else
                        {
                            string sharedText = string.Format("delete from TB_OUTSIDE_SHARE where o_path = N'{0}'", sPath);
                            queryList.Add(sharedText);
                        }
                    }

                    string ownerText = string.Format("delete from " + GlobalService.DbTable + " where r_path = N'{0}'", sPath);
                    queryList.Add(ownerText);

                    if (File.Exists(path))
                    {
                        if (GlobalService.User == UserUtil.HrUserName1())
                        //if (GlobalService.User == "Ling Wai Man(凌慧敏,Velma)")
                        {
                            string directory = @"\\kdthk-dm1\project\IT System\MyCloud Record\" + DateTime.Today.ToString("yyyyMMdd");
                            if (!Directory.Exists(directory))
                            {
                                Directory.CreateDirectory(directory);
                            }

                            string filename = Path.GetFileName(path);

                            File.Copy(path, directory + @"\" + filename);
                        }

                        File.Delete(path);
                    }

                    string delQuery = string.Format("delete from S_OUT_SHARE where o_path = N'{0}'", sPath);
                    DataServiceMes.GetInstance().ExecuteNonQuery(delQuery);
                }
                else
                {
                    string tableName = "TB_" + AdUtil.GetUserIdByUsername(owner, "kmhk.local");

                    List <string> sharedList = GetSharedList(tableName, sPath);
                    sharedList.Remove(GlobalService.User);

                    string shared = string.Join(";", sharedList.ToArray());

                    if (shared == "")
                    {
                        shared = "-";
                    }

                    string ownerText = string.Format("update " + tableName + " set r_shared = N'{0}' where r_path = N'{1}'", shared, sPath);
                    queryList.Add(ownerText);

                    string sharedText = string.Format("delete from " + GlobalService.DbTable + " where r_path = N'{0}'", sPath);
                    queryList.Add(sharedText);
                }

                if (row.RowState != DataRowState.Deleted)
                {
                    row.Delete();
                }
            }

            string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");

            string query = string.Format("insert into TB_LOG (log_datetime, log_category, log_path, log_by) values ('{0}', '{1}', N'{2}', N'{3}')", now, "Delete", sPath, GlobalService.User);

            queryList.Add(query);

            foreach (string text in queryList)
            {
                DataService.GetInstance().ExecuteNonQuery(text);
            }
            //QueryUtil.InsertDataToLocalDb(text);
        }