示例#1
0
        public static void SendR3FinishedEmail(string from, string sender, string chaseno, string category, string r3Id, string request, string reason)
        {
            string hostname = "Kdmail.km.local";

            string to = UserUtil.ItMail2();
            //string to = "*****@*****.**";

            string subject = "R3申請 - 經管已承認";

            SmtpClient client = new SmtpClient(hostname);

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            string body2 = "Application no. : " + chaseno + "<br />Category: " + category + "<br />Content: <br />";

            string html = "R3 ID : " + r3Id + "<br /><br />申請依賴 : " + request + "<br /><br />理由 : " + reason;

            MailMessage mail = new MailMessage();

            mail.From = new MailAddress(from, sender, Encoding.UTF8);
            mail.To.Add(to);
            mail.Subject    = subject;
            mail.IsBodyHtml = true;
            mail.Body       = body2 + html;

            client.Send(mail);
        }
示例#2
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);
        }
示例#3
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);
        }
示例#4
0
        public static bool IsSpecialUser(string shared)
        {
            if (shared == "Chow Chi To(周志滔,Sammy)" || shared == "Ling Wai Man(凌慧敏,Velma)" || shared == UserUtil.ItUserName2() || shared == "Ng Lau Yu, Lilith (吳柳如)" ||
                shared == "Lee Miu Wah(李苗華)" || shared == UserUtil.ItUserName3() || shared == UserUtil.ItUserName1() || shared == UserUtil.ItUserName4())
            {
                //if (shared == "Chow Chi To(周志滔,Sammy)" || shared == "Ling Wai Man(凌慧敏,Velma)" || shared == "Chan Fai Lung(陳輝龍,Onyx)" || shared == "Ng Lau Yu, Lilith (吳柳如)" ||
                //        shared == "Lee Miu Wah(李苗華)" || shared == "Lee Ming Fung(李銘峯)" || shared == "Ho Kin Hang(何健恒,Ken)" || shared == "Yeung Wai, Gabriel (楊偉)")
                return(true);
            }

            return(false);
        }
示例#5
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);
            }
        }
        public static void SetPermission(List <string> sharedList, string filePath)
        {
            try
            {
                FileInfo info = new FileInfo(filePath);

                FileSecurity fs = info.GetAccessControl();

                /* Start of Take Ownership by Cato Yeung 2016/04/10 */
                //SecurityIdentifier cu = WindowsIdentity.GetCurrent().User;
                //fs.SetOwner(cu);
                //File.SetAccessControl(filePath, fs);
                /* End of Take Ownership by Cato Yeung 2016/04/10 */

                fs.SetAccessRuleProtection(true, false);
                fs.AddAccessRule(new FileSystemAccessRule(@"kmhk\itadmin", FileSystemRights.FullControl, AccessControlType.Allow));
                fs.AddAccessRule(new FileSystemAccessRule(AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local"), FileSystemRights.FullControl, AccessControlType.Allow));

                foreach (string shared in sharedList)
                {
                    string staffId = AdUtil.GetUserIdByUsername(shared.Trim(), "kmhk.local");

                    //Debug.WriteLine(shared + "  " + filePath);
                    //fs.SetAccessRuleProtection(true, false);
                    fs.AddAccessRule(new FileSystemAccessRule(staffId, FileSystemRights.Modify, AccessControlType.Allow));

                    if (UserUtil.IsSpecialUser(shared))
                    //if (shared == "Chow Chi To(周志滔,Sammy)" || shared == "Ling Wai Man(凌慧敏,Velma)" || shared == "Chan Fai Lung(陳輝龍,Onyx)" || shared == "Ng Lau Yu, Lilith (吳柳如)" ||
                    //        shared == "Lee Miu Wah(李苗華)" || shared == "Lee Ming Fung(李銘峯)" || shared == "Ho Kin Hang(何健恒,Ken)" || shared == "Yeung Wai, Gabriel (楊偉)")
                    {
                        string asText = string.Format("select as_userid from TB_USER_AS where as_user = N'{0}'", shared.Trim());
                        string asId   = DataService.GetInstance().ExecuteScalar(asText).ToString().Trim();

                        fs.AddAccessRule(new FileSystemAccessRule(asId, FileSystemRights.Modify, AccessControlType.Allow));
                    }
                }

                File.SetAccessControl(filePath, fs);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message + ex.StackTrace);
                MessageBox.Show("Errors found when setting permission.");
            }
        }
示例#7
0
        public static void SharedCN(List <string> cnlist, string filePath, string filename, string keyword)
        {
            foreach (string cnPerson in cnlist)
            {
                string staffno = UserUtil.GetCnUserStaffNo(cnPerson);

                string id = AdUtil.GetUserIdByUsername(GlobalService.User, "kmhk.local");

                string directory = @"\\kdthk-dm1\project\KDTHK-DM\littlecloud\";
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                string nfilepath = filePath.Replace("''", "'");

                string newFileName = Path.GetFileName(nfilepath);
                string newFilePath = directory + newFileName;

                if (!File.Exists(newFilePath))
                {
                    File.Copy(nfilepath, newFilePath, true);
                }

                if (newFilePath.Contains("'"))
                {
                    newFilePath = newFilePath.Replace("'", "''");
                }

                string query = string.Format("if not exists (select * from S_OUT_SHARE where o_pathnew = N'{8}' and o_from = N'{4}' and o_toid = '{5}') " +
                                             "insert into S_OUT_SHARE (o_path, o_filename, o_keyword, o_fromid, o_from, o_toid, o_to, o_date, o_pathnew) values (N'{0}', N'{1}', N'{2}', '{3}', N'{4}', '{5}', N'{6}', '{7}', N'{8}')",
                                             filePath, filename, keyword, id, GlobalService.User, staffno, cnPerson, DateTime.Today.ToString("yyyy/MM/dd"), newFilePath);

                //Debug.WriteLine("Query: " + query);

                //DataService.GetInstance().ExecuteNonQuery(query);
                DataServiceMes.GetInstance().ExecuteNonQuery(query);

                UpdateFilePath(filePath, newFilePath);
            }
        }
示例#8
0
        public static void SendNotificationEmail(string chaseno, string category, string sender, string from, string title, string body, int width, int height, RtfPrintUtil rtb)
        {
            string hostname = "Kdmail.km.local";

            string to = UserUtil.ItMail1();
            //string to = "*****@*****.**";
            //string to = "*****@*****.**";

            string subject = "Application received - " + title;

            SmtpClient client = new SmtpClient(hostname);

            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            string body2 = "Application no. : " + chaseno + "<br />Category: " + category + "<br />Content: <br />";

            string html = "";

            if (body != "")
            {
                Image    tmpImg = new Bitmap(width, height + 20);
                Graphics g      = Graphics.FromImage(tmpImg);

                rtb.PrintImage(0, g);

                if (!Directory.Exists(@"C:\temp\images"))
                {
                    Directory.CreateDirectory(@"C:\temp\images");
                }

                tmpImg.Save(@"C:\temp\images\temp.png", System.Drawing.Imaging.ImageFormat.Png);

                g.Dispose();

                var img = new LinkedResource(@"C:\temp\images\temp.png");
                img.ContentId = Guid.NewGuid().ToString();

                html = body2 + string.Format(@"<p></p><img src =""cid:{0}""/>", img.ContentId);

                var view = AlternateView.CreateAlternateViewFromString(html, null, MediaTypeNames.Text.Html);
                view.LinkedResources.Add(img);
                // view.ContentType = new ContentType("text/html");

                MailMessage mail = new MailMessage();
                mail.From = new MailAddress(from, sender, Encoding.UTF8);
                mail.To.Add(to);
                //mail.CC.Add(UserUtil.ItMail1());
                mail.CC.Add(UserUtil.ItMail2());
                mail.CC.Add(UserUtil.ItMail3());
                mail.CC.Add(UserUtil.HkRpsMail1());
                mail.CC.Add(UserUtil.HkHrMail3());
                //mail.CC.Add("*****@*****.**");
                //mail.CC.Add("*****@*****.**");
                //mail.CC.Add("*****@*****.**");
                //mail.CC.Add("*****@*****.**");
                //mail.CC.Add("*****@*****.**");
                mail.Subject    = subject;
                mail.IsBodyHtml = true;
                mail.Body       = html;
                mail.AlternateViews.Add(view);
                client.Send(mail);
            }
            else
            {
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress(from, sender, Encoding.UTF8);
                mail.To.Add(UserUtil.ItMail4());
                mail.CC.Add(UserUtil.ItMail2());
                mail.CC.Add(UserUtil.ItMail3());
                //mail.To.Add("*****@*****.**");
                //mail.CC.Add("*****@*****.**");
                //mail.CC.Add("*****@*****.**");
                //mail.CC.Add("*****@*****.**");
                mail.Subject    = subject;
                mail.IsBodyHtml = true;
                mail.Body       = body2;
                client.Send(mail);
            }
        }
示例#9
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);
        }