示例#1
0
文件: BelugaDb.cs 项目: windygu/haina
        /* 新增一个联系人到数据库,如果该联系人不是四湖用户,则user_id留空串;不填的字段留空串。注意不能为null */
        public void AddNewContact(string user_id, string mobile, string name, string photo,
                                  string home_tel, string work_tel, string other_tel, string fax, string person_email, string work_email,
                                  string other_email, string home_street, string home_city, string home_province, string work_street,
                                  string work_city, string work_province, string other_street, string other_city, string other_province,
                                  string qq, string msn, string other_im, string url, DateTime birthday, string org, string title, string note,
                                  string ring)
        {
            SQLiteCommand cmd = _Connection.CreateCommand("insert into t_contact (cid, src_user_id, dst_user_id, dst_user_mobile, name, name_spell, photo, create_time, delete_flag) " +
                                                          "values (null, @src_user_id, @dst_user_id, @dst_user_mobile, @name, @name_spell, @photo, @create_time, @delete_flag);");

            cmd.Parameters.Add("@src_user_id", DbType.String).Value     = _userconfig.user_id;
            cmd.Parameters.Add("@dst_user_id", DbType.String).Value     = user_id;
            cmd.Parameters.Add("@dst_user_mobile", DbType.String).Value = mobile;
            cmd.Parameters.Add("@name", DbType.String).Value            = name;
            cmd.Parameters.Add("@name_spell", DbType.String).Value      = Han2Pinyin.Chinese2PY(name);
            cmd.Parameters.Add("@photo", DbType.String).Value           = photo;
            cmd.Parameters.Add("@create_time", DbType.DateTime).Value   = DateTime.Now;
            cmd.Parameters.Add("@delete_flag", DbType.Int16).Value      = 0;
            cmd.ExecuteNonQuery();

            int LastContactId = (int)_Connection.CreateCommand("select max(cid) from t_contact;").ExecuteScalar();

            cmd = _Connection.CreateCommand("insert into t_contact_detail (cdid, cid, home_tel, work_tel, other_tel, fax, person_email, work_email, other_email, " +
                                            "home_street, home_city, home_province, work_street, work_city, work_province, other_street, other_city, other_province, qq, msn, other_im, " +
                                            "url, birthday, org, title, note, ring, create_time, delete_flag) " +
                                            "values (null, @cid, @home_tel, @work_tel, @other_tel, @fax, @person_email, @work_email, @other_email, " +
                                            "@home_street, @home_city, @home_province, @work_street, @work_city, @work_province, @other_street, @other_city, @other_province, " +
                                            "@qq, @msn, @other_im, @url, @birthday, @org, @title, @note, @ring, @create_time, @delete_flag);");

            cmd.Parameters.Add("@cid", DbType.Int32).Value             = LastContactId;
            cmd.Parameters.Add("@home_tel", DbType.String).Value       = home_tel;
            cmd.Parameters.Add("@work_tel", DbType.String).Value       = work_tel;
            cmd.Parameters.Add("@other_tel", DbType.String).Value      = other_tel;
            cmd.Parameters.Add("@fax", DbType.String).Value            = fax;
            cmd.Parameters.Add("@person_email", DbType.String).Value   = person_email;
            cmd.Parameters.Add("@work_email", DbType.String).Value     = work_email;
            cmd.Parameters.Add("@other_email", DbType.String).Value    = other_email;
            cmd.Parameters.Add("@home_street", DbType.String).Value    = home_street;
            cmd.Parameters.Add("@home_city", DbType.String).Value      = home_city;
            cmd.Parameters.Add("@home_province", DbType.String).Value  = home_province;
            cmd.Parameters.Add("@work_street", DbType.String).Value    = work_street;
            cmd.Parameters.Add("@work_city", DbType.String).Value      = work_city;
            cmd.Parameters.Add("@work_province", DbType.String).Value  = work_province;
            cmd.Parameters.Add("@other_street", DbType.String).Value   = other_street;
            cmd.Parameters.Add("@other_city", DbType.String).Value     = other_city;
            cmd.Parameters.Add("@other_province", DbType.String).Value = other_province;
            cmd.Parameters.Add("@qq", DbType.String).Value             = qq;
            cmd.Parameters.Add("@msn", DbType.String).Value            = msn;
            cmd.Parameters.Add("@other_im", DbType.String).Value       = other_im;
            cmd.Parameters.Add("@url", DbType.String).Value            = url;
            cmd.Parameters.Add("@birthday", DbType.DateTime).Value     = birthday;
            cmd.Parameters.Add("@org", DbType.String).Value            = org;
            cmd.Parameters.Add("@title", DbType.String).Value          = title;
            cmd.Parameters.Add("@note", DbType.String).Value           = note;
            cmd.Parameters.Add("@ring", DbType.String).Value           = ring;
            cmd.Parameters.Add("@create_time", DbType.DateTime).Value  = DateTime.Now;
            cmd.Parameters.Add("@delete_flag", DbType.Int16).Value     = 0;
            cmd.ExecuteNonQuery();
        }
示例#2
0
文件: BelugaDb.cs 项目: windygu/haina
        /* 根据联系人数据库id,编辑一个联系人到数据库,不修改的字段必须将原字段值传给参数,清空字段值使用空字符串。注意不能为null */
        public void EditContact(int contact_id, string user_id, string mobile, string name, string photo,
                                string home_tel, string work_tel, string other_tel, string fax, string person_email, string work_email,
                                string other_email, string home_street, string home_city, string home_province, string work_street,
                                string work_city, string work_province, string other_street, string other_city, string other_province,
                                string qq, string msn, string other_im, string url, DateTime birthday, string org, string title, string note,
                                string ring)
        {
            Contact       contact = GetContact(contact_id);
            SQLiteCommand cmd     = _Connection.CreateCommand("update t_contact set dst_user_id = @user_id, dst_user_mobile = @mobile, " +
                                                              "name = @name, name_spell = @name_spell, photo = @photo where cid = @contact_id;");

            if (string.IsNullOrEmpty(contact["dst_user_id"].ToString()) || contact["dst_user_mobile"].ToString().Equals(mobile))
            {
                cmd.Parameters.Add("@dst_user_id", DbType.String).Value = user_id;
            }
            else
            {
                cmd.Parameters.Add("@dst_user_id", DbType.String).Value = "";
            }

            cmd.Parameters.Add("@dst_user_mobile", DbType.String).Value = mobile;
            cmd.Parameters.Add("@name", DbType.String).Value            = name;
            cmd.Parameters.Add("@name_spell", DbType.String).Value      = Han2Pinyin.Chinese2PY(name);
            cmd.Parameters.Add("@photo", DbType.String).Value           = photo;
            cmd.Parameters.Add("@contact_id", DbType.Int32).Value       = contact_id;
            cmd.ExecuteNonQuery();

            ContactDetail detail = GetContactDetail(contact_id);

            cmd = _Connection.CreateCommand("update t_contact_detail set home_tel = @home_tel, work_tel = @home_tel, " +
                                            "other_tel = @other_tel, fax = @fax, person_email = @person_email, work_email = @work_email, other_email = @other_email, " +
                                            "home_street = @home_street, home_city = @home_city, home_province = @home_province, work_street = @work_street, " +
                                            "work_city = @work_city, work_province @work_province, other_street = @other_street, other_city = @other_city, " +
                                            "other_province = @other_province, qq = @qq, msn = @msn, other_im = @other_im, url = @url, birthday = @birthday, " +
                                            "org = @org, title = @title, note = @note, ring = @ring where cid = @contact_id;");

            cmd.Parameters.Add("@home_tel", DbType.String).Value       = home_tel;
            cmd.Parameters.Add("@work_tel", DbType.String).Value       = work_tel;
            cmd.Parameters.Add("@other_tel", DbType.String).Value      = other_tel;
            cmd.Parameters.Add("@fax", DbType.String).Value            = fax;
            cmd.Parameters.Add("@person_email", DbType.String).Value   = person_email;
            cmd.Parameters.Add("@work_email", DbType.String).Value     = work_email;
            cmd.Parameters.Add("@other_email", DbType.String).Value    = other_email;
            cmd.Parameters.Add("@home_street", DbType.String).Value    = home_street;
            cmd.Parameters.Add("@home_city", DbType.String).Value      = home_city;
            cmd.Parameters.Add("@home_province", DbType.String).Value  = home_province;
            cmd.Parameters.Add("@work_street", DbType.String).Value    = work_street;
            cmd.Parameters.Add("@work_city", DbType.String).Value      = work_city;
            cmd.Parameters.Add("@work_province", DbType.String).Value  = work_province;
            cmd.Parameters.Add("@other_street", DbType.String).Value   = other_street;
            cmd.Parameters.Add("@other_city", DbType.String).Value     = other_city;
            cmd.Parameters.Add("@other_province", DbType.String).Value = other_province;
            cmd.Parameters.Add("@qq", DbType.String).Value             = qq;
            cmd.Parameters.Add("@msn", DbType.String).Value            = msn;
            cmd.Parameters.Add("@other_im", DbType.String).Value       = other_im;
            cmd.Parameters.Add("@url", DbType.String).Value            = url;
            cmd.Parameters.Add("@birthday", DbType.DateTime).Value     = birthday;
            cmd.Parameters.Add("@org", DbType.String).Value            = org;
            cmd.Parameters.Add("@title", DbType.String).Value          = title;
            cmd.Parameters.Add("@note", DbType.String).Value           = note;
            cmd.Parameters.Add("@ring", DbType.String).Value           = ring;
            cmd.Parameters.Add("@contact_id", DbType.Int32).Value      = contact_id;
            cmd.ExecuteNonQuery();
        }