protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                IBasicService service = ServiceFactory.GetService<IBasicService>();

                BasicOrganization entity = null;

                if (this.IsInsert)
                {
                    entity = new BasicOrganization()
                    {
                        OrgNumber = this.txtOrgNumber.Text.Trim(),
                        OrgName = this.txtOrgName.Text.Trim(),
                        OrgAddress = this.txtOrgAddress.Text.Trim(),
                        OrgParentId = this.hfOrgParentId.Value.Trim().ToInt(0),
                        OrgFullPath = ""
                    };

                    if (service.CheckExists_Organization(entity))
                    {
                        this.JscriptMsg("网点机构号码已存在", null, "Error");

                        return;
                    }
                }

                else
                {
                    entity = service.GetObject_Organization(this.PkId);

                    if (entity != null)
                    {
                        entity.OrgName = this.txtOrgName.Text.Trim();
                        entity.OrgAddress = this.txtOrgAddress.Text.Trim();
                        entity.OrgParentId = this.hfOrgParentId.Value.Trim().ToInt(0);
                    }
                }

                service.Save_Organization(entity);

                if (this.IsInsert)
                {
                    entity.OrgFullPath = entity.OrgParentId.ToString().GetOrgFullPath() + "[" + entity.PkId + "]";

                    service.Save_Organization(entity);
                }

                if (this.IsInsert && (sender as Button).CommandName == "SubmitContinue")
                {
                    this.ReturnUrl = this.Request.Url.AbsolutePath;
                }

                this.JscriptMsg("数据保存成功", this.ReturnUrl, "Success");
            }

            BasicConvert.ClearCache();
        }
        public bool CheckExists(BasicOrganization objBasicOrganization)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            sql = " select count(1) from tbl_basic_organization where OrgNumber=:OrgNumber ";

            parameterList.Add(new OracleParameter(":OrgNumber", objBasicOrganization.OrgNumber));

            return int.Parse(DbHelper.ExecuteScalar(sql, CommandType.Text, parameterList.ToArray()).ToString()) > 0;
        }
        public bool CheckExists_Organization(BasicOrganization objBasicOrganization)
        {
            var repository = ServiceFactory.GetService<IBasicOrganizationRepository>();

            return repository.CheckExists(objBasicOrganization);
        }
        public void Save_Organization(BasicOrganization objBasicOrganization)
        {
            var repository = ServiceFactory.GetService<IBasicOrganizationRepository>();

            repository.Save(objBasicOrganization);
        }
        public void Save(BasicOrganization objBasicOrganization)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            if (objBasicOrganization.PkId == 0)
            {
                sql = " insert into tbl_basic_organization(PkId, OrgNumber, OrgName, OrgAddress, OrgParentId, OrgFullPath) " +
                      " values(TBO_PKID.NEXTVAL, :OrgNumber, :OrgName, :OrgAddress, :OrgParentId, :OrgFullPath) " +
                      " RETURNING PkId INTO :PkId ";

                parameterList.Add(new OracleParameter(":OrgNumber", objBasicOrganization.OrgNumber));
                parameterList.Add(new OracleParameter(":OrgName", objBasicOrganization.OrgName));
                parameterList.Add(new OracleParameter(":OrgAddress", objBasicOrganization.OrgAddress));
                parameterList.Add(new OracleParameter(":OrgParentId", objBasicOrganization.OrgParentId));
                parameterList.Add(new OracleParameter(":OrgFullPath", objBasicOrganization.OrgFullPath));
                var p = new OracleParameter(":PkId", OracleDbType.Int32, 0, ParameterDirection.Output);
                parameterList.Add(p);

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());

                objBasicOrganization.PkId = Convert.ToInt32(((OracleDecimal)p.Value).Value);
            }

            else
            {
                sql = " update tbl_basic_organization set OrgName=:OrgName, OrgAddress=:OrgAddress, OrgFullPath=:OrgFullPath where PkId=:PkId ";

                parameterList.Add(new OracleParameter(":OrgName", objBasicOrganization.OrgName));
                parameterList.Add(new OracleParameter(":OrgAddress", objBasicOrganization.OrgAddress));
                parameterList.Add(new OracleParameter(":OrgFullPath", objBasicOrganization.OrgFullPath));
                parameterList.Add(new OracleParameter(":PkId", objBasicOrganization.PkId));

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());
            }
        }
Exemple #6
0
        private void InitData()
        {
            IBasicService basicService = ServiceFactory.GetService<IBasicService>();
            IDeviceService deviceService = ServiceFactory.GetService<IDeviceService>();

            int orgCount = this.txtOrgCount.Text.Trim().ToInt();
            int relevanceDeviceCount = this.txtRelevanceDeviceCount.Text.Trim().ToInt();
            int deviceGroup = this.txtDeviceGroup.Text.Trim().ToInt();
            int perGroupOrgCount = orgCount / deviceGroup;

            this.BeginInvoke(new EventHandler((a, b) =>
            {
                this.pbFinish.Minimum = 0;
                this.pbFinish.Maximum = orgCount * relevanceDeviceCount;
                this.pbFinish.Value = 0;
            })).AsyncWaitHandle.WaitOne(10);

            for (int i = 1; i <= deviceGroup; i++)
            {
                int deviceIndex = 0;

                for (int j = 1; j <= perGroupOrgCount; j++)
                {
                    int orgId = (i - 1) * perGroupOrgCount + j;

                    BasicOrganization org = new BasicOrganization()
                    {
                        OrgNumber = "ORG" + orgId.ToString().PadLeft(4, '0'),
                        OrgName = "网点机构" + orgId.ToString().PadLeft(4, '0'),
                        OrgAddress = "网点机构" + orgId.ToString().PadLeft(4, '0'),
                        OrgParentId = 0
                    };

                    basicService.Save_Organization(org);

                    org.OrgFullPath = org.OrgParentId.ToString().GetOrgFullPath() + "[" + org.PkId + "]";

                    basicService.Save_Organization(org);

                    for (int k = 1; k <= relevanceDeviceCount; k++)
                    {
                        deviceIndex += 1;

                        string deviceNumber = "ABCD" + (int.Parse(i + "00000000") + deviceIndex).ToString();

                        DeviceInfo device = new DeviceInfo()
                        {
                            DeviceNumber = deviceNumber,
                            SoftwareVersion = "000000",
                            RegisterIp = "127.0.0.1",
                            KindCode = 1,
                            ModelCode = 1,
                            OrgId = org.PkId,
                            OnLineTime = DateTime.Now,
                            DeviceStatus = 1
                        };

                        deviceService.Save_Info(device);

                        this.BeginInvoke(new EventHandler((a, b) => { this.pbFinish.PerformStep(); }));
                    }
                }
            }

            this.BeginInvoke(new EventHandler((a, b) => { this.btnInit.Enabled = true; }));

            MessageBox.Show("数据初始化完毕", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        public void Save(BasicOrganization objBasicOrganization)
        {
            string sql = null;
            List<DbParameter> parameterList = new List<DbParameter>();

            if (objBasicOrganization.PkId == 0)
            {
                sql = " insert into tbl_basic_organization(OrgNumber, OrgName, OrgAddress, OrgParentId, OrgFullPath) " +
                      " values(@OrgNumber, @OrgName, @OrgAddress, @OrgParentId, @OrgFullPath); " +
                      " select LAST_INSERT_ID(); ";

                parameterList.Add(new MySqlParameter("@OrgNumber", objBasicOrganization.OrgNumber));
                parameterList.Add(new MySqlParameter("@OrgName", objBasicOrganization.OrgName));
                parameterList.Add(new MySqlParameter("@OrgAddress", objBasicOrganization.OrgAddress));
                parameterList.Add(new MySqlParameter("@OrgParentId", objBasicOrganization.OrgParentId));
                parameterList.Add(new MySqlParameter("@OrgFullPath", objBasicOrganization.OrgFullPath));

                objBasicOrganization.PkId = DbHelper.ExecuteScalar(sql, CommandType.Text, parameterList.ToArray()).ToString().ToInt();
            }

            else
            {
                sql = " update tbl_basic_organization set OrgName=@OrgName, OrgAddress=@OrgAddress, OrgFullPath=@OrgFullPath where PkId=@PkId ";

                parameterList.Add(new MySqlParameter("@PkId", objBasicOrganization.PkId));
                parameterList.Add(new MySqlParameter("@OrgName", objBasicOrganization.OrgName));
                parameterList.Add(new MySqlParameter("@OrgAddress", objBasicOrganization.OrgAddress));
                parameterList.Add(new MySqlParameter("@OrgFullPath", objBasicOrganization.OrgFullPath));

                DbHelper.ExecuteNonQuery(sql, CommandType.Text, parameterList.ToArray());
            }
        }