Exemplo n.º 1
0
        /// <summary>
        /// 创建联系人组树节点
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        private TreeNode CreateTreeNode(TB_ContactPerson source)
        {
            var treeNode = new TreeNode(source.Name)
            {
                Tag                = source,
                ImageIndex         = 1,
                SelectedImageIndex = 1,
                ToolTipText        = string.Format("联系人:{0}", source.Name)
            };

            treeNode.ContextMenu = CreateContextMenu(treeNode);
            return(treeNode);
        }
Exemplo n.º 2
0
        private void ReadData(string fileName)
        {
            using (var stream = new FileStream(fileName, FileMode.Open))
            {
                // 把 Stream 转换成 byte[]
                var bytes = new byte[stream.Length];
                stream.Read(bytes, 0, bytes.Length);
                // 设置当前流的位置为流的开始
                stream.Seek(0, SeekOrigin.Begin);
                string content = System.Text.Encoding.Default.GetString(bytes, 0, bytes.Length);
                if (string.IsNullOrEmpty(content))
                {
                    return;
                }

                var coords = content.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                var count  = coords.Count();
                if (count <= 1)
                {
                    return;
                }

                var line   = coords[0];
                var values = line.Split(',');
                if (!values.Contains("姓名"))
                {
                    return;
                }

                var nameIndex      = Array.IndexOf(values, "姓名");
                var utypeIndex     = Array.IndexOf(values, "组类别");
                var sexIndex       = Array.IndexOf(values, "性别");
                var birthdayIndex  = Array.IndexOf(values, "生日");
                var callphoneIndex = Array.IndexOf(values, "手机");
                var telephoneIndex = Array.IndexOf(values, "电话");
                var emailIndex     = Array.IndexOf(values, "邮箱");
                var addressIndex   = Array.IndexOf(values, "地址");
                var contactPersons = new List <TB_ContactPerson>();
                for (int i = 1; i < count; i++)
                {
                    var      contact = new TB_ContactPerson();
                    string[] list    = coords[i].Split(',');
                    contact.Name = list[nameIndex];
                    var group = _contactPersonGroups.FirstOrDefault(p => p.Name.Equals(list[utypeIndex], StringComparison.CurrentCultureIgnoreCase));
                    contact.UType     = group != null ? group.Id : 0;
                    contact.Sex       = (int)GlobalData.Current.GetSex(list[sexIndex]);
                    contact.Birthday  = list[birthdayIndex];
                    contact.Callphone = list[callphoneIndex];
                    contact.Telephone = list[telephoneIndex];
                    contact.Email     = list[emailIndex];
                    contact.Address   = list[addressIndex];
                    contact.UId       = GlobalData.Current.CurrentUser.Id;
                    contactPersons.Add(contact);
                }
                HandleData(() =>
                {
                    BLLOperate.AddContactPersonsByList(contactPersons);
                    MessageBox.Show(this, "导入成功!");
                    tvItems_AfterSelect(null, null);
                }, s => MessageBox.Show(this, s));
            }
        }