コード例 #1
0
        public override int Modify()
        {
            if (Check() == false)
            {
                return(0);
            }

            int sourceCompanyId = _customer.companyId;

            _customer.code = txtCode.Text;
            int companyId = 0;

            if (string.IsNullOrEmpty(txtCompany.Text) == false && txtCompany.Tag != null && txtCompany.Tag is FishEntity.CompanyEntity)
            {
                FishEntity.CompanyEntity company = txtCompany.Tag as FishEntity.CompanyEntity;
                _customer.company   = company.code;
                companyId           = company.id;
                _customer.companyId = company.id;
            }
            else
            {
                _customer.companyId = 0;
                _customer.company   = string.Empty;
            }

            _customer.currentlinkDate = dtpCurrentDate.Value;
            _customer.department      = string.Empty;
            _customer.email           = txtEmail.Text;
            _customer.modifyman       = FishEntity.Variable.User.username;
            _customer.modifytime      = DateTime.Now;
            _customer.name            = txtName.Text;
            _customer.phone1          = txtPhone1.Text;
            _customer.phone2          = txtPhone2.Text;
            _customer.phone3          = txtPhone3.Text;
            _customer.post            = txtPost.Text;
            _customer.Department1     = txtdepartment1.Text;
            _customer.qq        = txtQQ.Text;
            _customer.remark    = txtRemark.Text;
            _customer.telephone = txtTelephone.Text;
            _customer.validate  = cmbValidate.Text.Equals("有效")?1:0;
            _customer.weixin    = txtWeixin.Text;

            _customer.homeaddress   = txtHomeAddress.Text.Trim();
            _customer.officeaddress = txtOfficeAddress.Text.Trim();
            _customer.sex           = rdbMan.Checked?"男":"女";
            _customer.fox           = txtfox.Text.Trim();

            DateTime nextlinkDate;

            if (DateTime.TryParse(txtNextLinkDate.Text, out nextlinkDate))
            {
                _customer.nextlinkdate = nextlinkDate;
            }
            else
            {
                _customer.nextlinkdate = null;
            }

            FishBll.Bll.CustomerBll bll = new FishBll.Bll.CustomerBll();
            bool isOk = bll.Update(_customer);

            if (isOk)
            {
                FishBll.Bll.CustomerOfCompanyBll ccBll = new FishBll.Bll.CustomerOfCompanyBll();
                if (_customer.companyId == 0 && sourceCompanyId > 0)
                {
                    ccBll.Delete(sourceCompanyId, _customer.id);
                }
                else if (_customer.companyId > 0 && sourceCompanyId == 0)
                {
                    FishEntity.CustomerOfCompanyEntity ccEntity = new FishEntity.CustomerOfCompanyEntity();
                    ccEntity.companyid  = _customer.companyId;
                    ccEntity.customerid = _customer.id;
                    ccBll.Add(ccEntity);
                }
                else if (_customer.companyId > 0 && sourceCompanyId > 0)
                {
                    ccBll.Update(sourceCompanyId, _customer.id, _customer.companyId, _customer.id);
                }

                SaveHeaderPicture(_customer.id);

                MessageBox.Show("修改成功。");
            }
            else
            {
                MessageBox.Show("修改失败。");
            }

            return(1);
        }
コード例 #2
0
        public override void Save()
        {
            if (Check() == false)
            {
                return;
            }
            _customer      = new FishEntity.CustomerEntity();
            _customer.code = FishBll.Bll.SequenceUtil.GetCustomerSequence();
            int companyId = 0;

            if (string.IsNullOrEmpty(txtCompany.Text) == false && txtCompany.Tag != null && txtCompany.Tag is FishEntity.CompanyEntity)
            {
                FishEntity.CompanyEntity company = txtCompany.Tag as FishEntity.CompanyEntity;
                _customer.company   = company.code;
                companyId           = company.id;
                _customer.companyId = company.id;
            }
            _customer.createman       = FishEntity.Variable.User.username;
            _customer.createtime      = DateTime.Now;
            _customer.currentlinkDate = dtpCurrentDate.Value;
            _customer.department      = string.Empty;
            _customer.email           = txtEmail.Text;
            _customer.isdelete        = 0;
            _customer.modifyman       = _customer.createman;
            _customer.modifytime      = _customer.createtime;
            _customer.name            = txtName.Text;

            DateTime nextlinkdate;

            if (DateTime.TryParse(txtNextLinkDate.Text, out nextlinkdate))
            {
                _customer.nextlinkdate = DateTime.Parse(txtNextLinkDate.Text);
            }
            else
            {
                _customer.nextlinkdate = null;
            }

            _customer.phone1      = txtPhone1.Text;
            _customer.phone2      = txtPhone2.Text;
            _customer.phone3      = txtPhone3.Text;
            _customer.post        = txtPost.Text;
            _customer.Department1 = txtdepartment1.Text;
            _customer.qq          = txtQQ.Text;
            _customer.remark      = txtRemark.Text;
            _customer.telephone   = txtTelephone.Text;
            _customer.validate    = cmbValidate.Text.Equals("有效") ? 1 : 0;
            _customer.weixin      = txtWeixin.Text;

            _customer.homeaddress   = txtHomeAddress.Text.Trim();
            _customer.officeaddress = txtOfficeAddress.Text.Trim();
            _customer.sex           = rdbMan.Checked?"男":"女";
            _customer.fox           = txtfox.Text.Trim();

            FishBll.Bll.CustomerBll bll = new FishBll.Bll.CustomerBll();

            bool isok = bll.Exists(_customer.code);

            while (isok)
            {
                _customer.code = FishBll.Bll.SequenceUtil.GetCustomerSequence();
                isok           = bll.Exists(_customer.code);
            }

            bool isExistName = bll.ExistsName(_customer.name);

            if (isExistName)
            {
                MessageBox.Show("数据库中存在相同的联系人名称。");
            }

            int id = bll.Add(_customer);

            if (id > 0)
            {
                _customer.id = id;
                txtCode.Text = _customer.code;

                FishBll.Bll.CustomerOfCompanyBll ccbll = new FishBll.Bll.CustomerOfCompanyBll();
                if (false == string.IsNullOrEmpty(_customer.company))
                {
                    FishEntity.CustomerOfCompanyEntity ccEntity = new FishEntity.CustomerOfCompanyEntity();
                    ccEntity.companyid  = companyId;
                    ccEntity.customerid = _customer.id;
                    ccbll.Add(ccEntity);
                }

                SaveHeaderPicture(id);

                tmiAdd.Visible      = true;
                tmiModify.Visible   = true;
                tmiQuery.Visible    = true;
                tmiPrevious.Visible = true;
                tmiNext.Visible     = true;
                tmiSave.Visible     = false;
                tmiCancel.Visible   = false;

                MessageBox.Show("添加成功。");
            }
            else
            {
                txtCode.Text = string.Empty;
                MessageBox.Show("添加失败。");
            }
        }