Ejemplo n.º 1
0
        public static void ImportInstrument()
        {
            ImportSqlServerUtility isql = new ImportSqlServerUtility();

            string strsql = "select * from Instrument";

            string insertrsql = "insert Rinstrument(old,new) values('{0}','{1}')";

            DataSet ds = isql.ExecuteSqlDataSet(strsql);

            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Columns.Count > 0)
            {
                CY.CSTS.Core.Business.InstrumentCode header = null;

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    RelationSqlServerUtility rsql = new RelationSqlServerUtility();

                    SqlServerUtility sql = new SqlServerUtility();

                    header = new CY.CSTS.Core.Business.InstrumentCode();

                    header.Id = Guid.NewGuid();

                    header.Save();

                    Guid id = header.Id;

                    sql.AddParameter("@Id", SqlDbType.UniqueIdentifier, id);

                    sql.AddParameter("@InstruCode", SqlDbType.NVarChar, ds.Tables[0].Rows[i][0].ToString());

                    /*******************************/
                    sql.AddParameter("@LaboratoryId", SqlDbType.UniqueIdentifier, CY.CSTS.Import.Core.Business.Lab.TransferLabId(ds.Tables[0].Rows[i][1].ToString()));

                    sql.AddParameter("@MachineGroupId", SqlDbType.UniqueIdentifier, CY.CSTS.Import.Core.Business.Machineset.TransferSetId(ds.Tables[0].Rows[i][2].ToString()));

                    sql.AddParameter("@WorkingforUnitId", SqlDbType.UniqueIdentifier, CY.CSTS.Import.Core.Business.UnitInfo.TransferUnitId(ds.Tables[0].Rows[i][3].ToString()));

                    sql.AddParameter("@PERSONNELID", SqlDbType.UniqueIdentifier, CY.CSTS.Import.Core.Business.User.TransferUserId(ds.Tables[0].Rows[i][4].ToString()));

                    sql.AddParameter("@HNAME", SqlDbType.NVarChar, ds.Tables[0].Rows[i][5].ToString());

                    sql.AddParameter("@ENAME", SqlDbType.NVarChar, ds.Tables[0].Rows[i][6].ToString());

                    sql.AddParameter("@ALIAS", SqlDbType.NVarChar, ds.Tables[0].Rows[i][7].ToString());

                    sql.AddParameter("@CLASSCODE", SqlDbType.NVarChar,
                        TransferClassCode(ds.Tables[0].Rows[i][9].ToString(), ds.Tables[0].Rows[i][10].ToString(), ds.Tables[0].Rows[i][11].ToString()));

                    sql.AddParameter("@SITE", SqlDbType.UniqueIdentifier, CY.CSTS.Import.Core.Business.UnitInfo.TransferProvinceId(ds.Tables[0].Rows[i][15].ToString()));

                    sql.AddParameter("@CITY", SqlDbType.UniqueIdentifier, CY.CSTS.Import.Core.Business.UnitInfo.TransferCityId(ds.Tables[0].Rows[i][16].ToString()));

                    sql.AddParameter("@SPECTYPE", SqlDbType.NVarChar, ds.Tables[0].Rows[i][17].ToString());

                    sql.AddParameter("@GETMODE", SqlDbType.UniqueIdentifier, TransferGetMode(ds.Tables[0].Rows[i][18].ToString()));

                    sql.AddParameter("@MANUFACTURE", SqlDbType.NVarChar, ds.Tables[0].Rows[i][19].ToString());

                    sql.AddParameter("@COUNTRYCODE", SqlDbType.UniqueIdentifier, TransferCountryId(ds.Tables[0].Rows[i][20].ToString()));

                    sql.AddParameter("@PRODUCINGAREA", SqlDbType.NVarChar, ds.Tables[0].Rows[i][21].ToString());

                    sql.AddParameter("@PRODUCESORT", SqlDbType.UniqueIdentifier, TranferProduceSort(ds.Tables[0].Rows[i][22].ToString()));

                    sql.AddParameter("@VALUERMB", SqlDbType.Decimal, ds.Tables[0].Rows[i][23].ToString());

                    sql.AddParameter("@NATIONALPAY", SqlDbType.Decimal, ds.Tables[0].Rows[i][26].ToString());

                    sql.AddParameter("@BUGETSOURCE", SqlDbType.UniqueIdentifier, TransferPurchesource(ds.Tables[0].Rows[i][27].ToString()));

                    sql.AddParameter("@PRODUCEDATE", SqlDbType.DateTime, ds.Tables[0].Rows[i][28].ToString());

                    sql.AddParameter("@PURCHASEDATE", SqlDbType.DateTime, ds.Tables[0].Rows[i][29].ToString());

                    sql.AddParameter("@DISCARDTIME", SqlDbType.DateTime, ds.Tables[0].Rows[i][30].ToString());

                    sql.AddParameter("@GUIDELINE", SqlDbType.NVarChar, ds.Tables[0].Rows[i][31].ToString());

                    sql.AddParameter("@FUNCTIONFEATURES", SqlDbType.NVarChar, ds.Tables[0].Rows[i][32].ToString());

                    sql.AddParameter("@EXAMINATION", SqlDbType.UniqueIdentifier, Guid.Empty);

                    sql.AddParameter("@TOTALLY", SqlDbType.Int, !string.IsNullOrEmpty(ds.Tables[0].Rows[i][34].ToString()) && bool.Parse(ds.Tables[0].Rows[i][34].ToString()) ? 1 : 2);

                    sql.AddParameter("@ACCEPTMISSION", SqlDbType.Int, !string.IsNullOrEmpty(ds.Tables[0].Rows[i][35].ToString()) && bool.Parse(ds.Tables[0].Rows[i][35].ToString()) ? 1 : 2);

                    sql.AddParameter("@EXTERNALSERVICE", SqlDbType.Int, !string.IsNullOrEmpty(ds.Tables[0].Rows[i][36].ToString()) && bool.Parse(ds.Tables[0].Rows[i][36].ToString()) ? 1 : 2);

                    sql.AddParameter("@PICTURE", SqlDbType.Int, !string.IsNullOrEmpty(ds.Tables[0].Rows[i][37].ToString()) && bool.Parse(ds.Tables[0].Rows[i][37].ToString()) ? 1 : 2);

                    sql.AddParameter("@ATTACHMENT", SqlDbType.Int, !string.IsNullOrEmpty(ds.Tables[0].Rows[i][38].ToString()) && bool.Parse(ds.Tables[0].Rows[i][38].ToString()) ? 1 : 2);

                    sql.AddParameter("@MEDIA", SqlDbType.Int, !string.IsNullOrEmpty(ds.Tables[0].Rows[i][39].ToString()) && bool.Parse(ds.Tables[0].Rows[i][39].ToString()) ? 1 : 2);

                    sql.AddParameter("@PURPOSEID", SqlDbType.NVarChar, ds.Tables[0].Rows[i][40].ToString());

                    sql.AddParameter("@REALMID", SqlDbType.NVarChar, ds.Tables[0].Rows[i][41].ToString());

                    sql.AddParameter("@WRITEDATE", SqlDbType.DateTime, ds.Tables[0].Rows[i][42].ToString());

                    sql.AddParameter("@UPDATEDATE", SqlDbType.DateTime, ds.Tables[0].Rows[i][43].ToString());

                    sql.AddParameter("@REMARK", SqlDbType.NVarChar, ds.Tables[0].Rows[i][44].ToString());

                    sql.AddParameter("@AUDITINGSTATE", SqlDbType.Int, ds.Tables[0].Rows[i][45].ToString() == "True" ? 4 : 2);

                    sql.AddParameter("@ASSESSOR", SqlDbType.NVarChar, ds.Tables[0].Rows[i][46].ToString());

                    sql.AddParameter("@AUDITINGDATE", SqlDbType.DateTime, ds.Tables[0].Rows[i][42].ToString());

                    /*****************************/

                    sql.AddParameter("@WorkState", SqlDbType.Int, 1);

                    sql.AddParameter("@UseState", SqlDbType.Int, 1);

                    sql.AddParameter("@HasCMA", SqlDbType.Int, 2);

                    sql.AddParameter("@IsSpecial", SqlDbType.Int, 2);

                    /******************************/

                    sql.AddParameter("@Intrument", SqlDbType.Int, ds.Tables[0].Rows[i][0].ToString());

                    SqlDataReader reader = sql.ExecuteSPReader("usp_InsertINSTRUMENTLegacy");
                    sql.Parameters.Clear();
                    reader.Close();

                    rsql.ExecuteSql(string.Format(insertrsql, ds.Tables[0].Rows[i][0].ToString(), header.Id.ToString()));

                }
            }
        }
Ejemplo n.º 2
0
        protected void BtnAddInstrument_Click(object sender, EventArgs e)
        {
            #region validation
            if (Request.Form["ddlCity"] != null && Request.Form["ddlCity"] != "0")
            {
                hdDdlCity.Value = Request.Form["ddlCity"];//把城市保留下来
            }
            if (ddlMachineBigClass.SelectedValue != "0" && !string.IsNullOrEmpty(Request.Form["ddlMachineMiddleClass"]) && !string.IsNullOrEmpty(Request.Form["ddlMachineSmallClass"]))
            {
                hdMiddleClassID.Value = Request.Form["ddlMachineMiddleClass"];//仪器中类
                hdSmallClassID.Value = Request.Form["ddlMachineSmallClass"];//仪器小类
            }

            if (string.IsNullOrEmpty(tbInstrumentCode.Text))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('自建编号不能为空!');</script>");
                return;
            }
            if (string.IsNullOrEmpty(tbUnit.Text) || string.IsNullOrEmpty(hidUnit.Value) || !CY.Utility.Common.StringHelper.IsGuid(hidUnit.Value))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('单位不能为空!');</script>");
                return;
            }
            if (string.IsNullOrEmpty(tbPersonnal.Text) || string.IsNullOrEmpty(hidPersonnal.Value) || !CY.Utility.Common.StringHelper.IsGuid(hidPersonnal.Value))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器负责人不能为空!');</script>");
                return;
            }
            if (string.IsNullOrEmpty(tbChineseName.Text))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器中文名称不能为空!');</script>");
                return;
            }
            if (string.IsNullOrEmpty(tbValueRMB.Text))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器原值不能为空!');</script>");
                return;
            }
            if (string.IsNullOrEmpty(tbPurchaseDate.Text))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('购进日期不能为空!');</script>");
                return;
            }
            string machineClass = string.Empty;
            if (ddlMachineBigClass.SelectedValue != "0" && !string.IsNullOrEmpty(Request.Form["ddlMachineMiddleClass"]) && !string.IsNullOrEmpty(Request.Form["ddlMachineSmallClass"]))
            {
                machineClass = Request.Form["ddlMachineSmallClass"];
            }
            else
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器分类编号不能为空!');</script>");
                return;
            }
            if (string.IsNullOrEmpty(ddlProvince.SelectedValue) || ddlProvince.SelectedValue.Equals("0") || !CY.Utility.Common.StringHelper.IsGuid(ddlProvince.SelectedValue))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器所在省不能为空'!);</script>");
                return;
            }
            if (string.IsNullOrEmpty(Request.Form["ddlCity"]) || Request.Form["ddlCity"].Equals("0") || !CY.Utility.Common.StringHelper.IsGuid(Request.Form["ddlCity"]))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器所在市不能为空!');</script>");
                return;
            }
            //if (string.IsNullOrEmpty(ddlGetMode.SelectedValue) || ddlGetMode.SelectedValue.Equals("0") || !CY.Utility.Common.StringHelper.IsGuid(ddlGetMode.SelectedValue))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('获取方式不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlWorkState.SelectedValue) || ddlWorkState.SelectedValue.Equals("0"))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('运行状态不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlUseState.SelectedValue) || ddlUseState.SelectedValue.Equals("0"))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('使用状态不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlCountry.SelectedValue) || ddlCountry.SelectedValue.Equals("0") || !CY.Utility.Common.StringHelper.IsGuid(ddlCountry.SelectedValue))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('国别不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlProduceSort.SelectedValue) || ddlProduceSort.SelectedValue.Equals("0") || !CY.Utility.Common.StringHelper.IsGuid(ddlProduceSort.SelectedValue))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器产区类别不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlBudgeSource.SelectedValue) || ddlBudgeSource.SelectedValue.Equals("0") || !CY.Utility.Common.StringHelper.IsGuid(ddlBudgeSource.SelectedValue))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器购置经费来源不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlExamination.SelectedValue) || ddlExamination.SelectedValue.Equals("0") || !CY.Utility.Common.StringHelper.IsGuid(ddlExamination.SelectedValue))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器检定情况不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlHasCMA.SelectedValue) || ddlHasCMA.SelectedValue.Equals("0"))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('是否计量认证不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlIsSpecial.SelectedValue) || ddlIsSpecial.SelectedValue.Equals("0"))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('是否特色仪器不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlTotally.SelectedValue) || ddlTotally.SelectedValue.Equals("0"))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('是否愿意共用不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlAcceptMission.SelectedValue) || ddlAcceptMission.SelectedValue.Equals("0"))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('是否接受任务不能为空!');</script>");
            //    return;
            //}
            //if (string.IsNullOrEmpty(ddlExternalService.SelectedValue) || ddlExternalService.SelectedValue.Equals("0"))
            //{
            //    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('是否对外服务不能为空!');</script>");
            //    return;
            //}
            if (string.IsNullOrEmpty(tbSpecific.Text.Trim()))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('规格型号不能为空!');</script>");
                tbSpecific.Focus();
                return;
            }
            decimal temp = default(decimal);
            if (!decimal.TryParse(tbValueRMB.Text.Trim(), out temp))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('仪器原值不是数字!');</script>");
                return;
            }
            if (tbNationalPay.Text != "")
            {
                if (!decimal.TryParse(tbNationalPay.Text.Trim(), out temp))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('国拨经费不是数字!');</script>");
                    return;
                }
            }
            DateTime tempDate = default(DateTime);
            if (tbDisgardTime.Text != "")
            {
                if (!DateTime.TryParse(tbDisgardTime.Text, out tempDate))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('报废年限格式不对!');</script>");
                    return;
                }
            }
            if (tbProduceDate.Text != "")
            {
                if (!DateTime.TryParse(tbProduceDate.Text, out tempDate))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('生产日期格式不对!');</script>");
                    return;
                }
            }
            if (!DateTime.TryParse(tbPurchaseDate.Text, out tempDate))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('购进日期格式不对!');</script>");
                return;
            }
            if (!string.IsNullOrEmpty(tbLab.Text) && !string.IsNullOrEmpty(hidLab.Value))
            {
                if (!CY.Utility.Common.StringHelper.IsGuid(hidLab.Value))
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('所属实验室输入有误!');</script>");
                    return;
                }
            }
            if (string.IsNullOrEmpty(tbSetName.Text))
            {
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('机组名称不能为空!');</script>");
                return;
            }
            //if (!string.IsNullOrEmpty(tbMachineGroup.Text) && !string.IsNullOrEmpty(hidMachineGroup.Value))
            //{
            //    if (!CY.Utility.Common.StringHelper.IsGuid(hidMachineGroup.Value))
            //    {
            //        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('所属机组输入有误!');</script>");
            //        return;
            //    }
            //}
            #endregion
            try
            {
                CY.CSTS.Core.Business.InstrumentCode instrumentCode = new CY.CSTS.Core.Business.InstrumentCode();
                instrumentCode.Id = Guid.NewGuid();
                instrumentCode.Save();
                string unitTypeName = string.Empty;
                CY.CSTS.Core.Business.UnitInfo unitInfo = CY.CSTS.Core.Business.UnitInfo.Load(new Guid(hidUnit.Value.Trim()));
                CY.CSTS.Core.Business.UnitType unitType = CY.CSTS.Core.Business.UnitType.Load(unitInfo.UnitType);
                if (unitType == null)
                {
                    unitTypeName = "科研单位";
                }
                else
                {
                    unitTypeName = unitType.Name;
                }
                #region 添加仪器基本信息

                #region 添加仪器机组信息
                Guid machinegroupid = default(Guid);

                if (tbSetName.Text != "")
                {
                    CY.CSTS.Core.Business.MACHINESET machineSet = new CY.CSTS.Core.Business.MACHINESET
                    {
                        UnitID = (hidUnit.Value == "" || hidUnit.Value == null) ? Guid.Empty : new Guid(hidUnit.Value),
                        LabID = (hidLab.Value == "" || hidLab.Value == null) ? Guid.Empty : new Guid(hidLab.Value),
                        SetCode = tbInstrumentCode.Text.Trim(),
                        SETNAME = tbSetName.Text,
                        GroupInstance = tbGroupInstance.Text,
                        EMAIL = tbEMAIL.Text,
                        FAX = tbFAX.Text,
                        LINKMAN = tbLinkMan.Text,
                        PHONE = tbPHONE.Text,
                        REMARK = tbMachineSetRemark.Text,
                        WRITEDATE = System.DateTime.Now,
                        UPDATEDATE = System.DateTime.Now
                    };
                    machineSet.Save();
                    machinegroupid = machineSet.Id;
                }

                if (!machinegroupid.Equals(default(Guid)))
                {
                    string[] machineSetUser = Request.Form.GetValues("mgperson");
                    if (machineSetUser != null && machineSetUser.Length > 0)
                    {
                        for (int i = 0; i < machineSetUser.Length; i++)
                        {
                            Guid userId = new Guid(machineSetUser[i]);

                            CY.CSTS.Core.Business.MachineGroupMember machineGroupMember = new CY.CSTS.Core.Business.MachineGroupMember
                            {
                                InstruID = instrumentCode.Id,
                                MachineGroupID = machinegroupid,
                                UserID = userId
                            };
                            machineGroupMember.Save();
                        }
                    }
                }
                #endregion

                //添加仪器用途
                string instrumentPurpose = string.Empty;
                for (int i = 0; i < cblPurpose.Items.Count; i++)
                {
                    if (cblPurpose.Items[i].Selected)
                    {
                        instrumentPurpose += cblPurpose.Items[i].Text;
                        CY.CSTS.Core.Business.PURPOSE purpose = new CY.CSTS.Core.Business.PURPOSE { PURPOSEID = new Guid(cblPurpose.Items[i].Value), InstruId = instrumentCode.Id };
                        purpose.Save();
                    }
                }

                //添加仪器测试及研究领域
                string instrumentDomain = string.Empty;
                for (int i = 0; i < cblRealm.Items.Count; i++)
                {
                    if (cblRealm.Items[i].Selected)
                    {
                        instrumentDomain += cblRealm.Items[i].Text;
                        CY.CSTS.Core.Business.INSTRREALM instrrealm = new CY.CSTS.Core.Business.INSTRREALM { DomainId = new Guid(cblRealm.Items[i].Value), InstruId = instrumentCode.Id };
                        instrrealm.Save();
                    }
                }

                #region 添加仪器信息
                switch (unitTypeName)
                {
                    case "科研单位":
                        CY.CSTS.Core.Business.INSTRUMENT instrument = new CY.CSTS.Core.Business.INSTRUMENT
                        {
                            ACCEPTMISSION = int.Parse(ddlAcceptMission.SelectedValue),
                            ALIAS = tbAlias.Text,
                            ASSESSOR = u.Name,//审核人
                            AUDITINGDATE = System.DateTime.Now,
                            BUGETSOURCE = (ddlBudgeSource.SelectedValue == "0") ? Guid.Empty : new Guid(ddlBudgeSource.SelectedValue),
                            SITE = new Guid(ddlProvince.SelectedValue),
                            CITY = new Guid(Request.Form["ddlCity"]),
                            COUNTRYCODE = (ddlCountry.SelectedValue == "0") ? Guid.Empty : new Guid(ddlCountry.SelectedValue),
                            DISCARDTIME = (tbDisgardTime.Text == "") ? default(DateTime) : DateTime.Parse(tbDisgardTime.Text),
                            ENAME = tbEnglishName.Text,
                            EXAMINATION = (ddlExamination.SelectedValue == "0") ? Guid.Empty : new Guid(ddlExamination.SelectedValue),
                            EXTERNALSERVICE = int.Parse(ddlExternalService.SelectedValue),
                            FUNCTIONFEATURES = tbFunctionFeatures.Text,
                            GETMODE = (ddlGetMode.SelectedValue == "0") ? Guid.Empty : new Guid(ddlGetMode.SelectedValue),
                            GUIDELINE = tbGuidline.Text,
                            HasCMA = int.Parse(ddlHasCMA.SelectedValue),
                            HNAME = tbChineseName.Text,
                            InstruCode = tbInstrumentCode.Text,
                            IsSpecial = int.Parse(ddlIsSpecial.SelectedValue),
                            LaboratoryId = (hidLab.Value == "" || hidLab.Value == null) ? Guid.Empty : new Guid(hidLab.Value),
                            MachineGroupId = machinegroupid,
                            MANUFACTURE = tbManufacturer.Text,
                            NATIONALPAY = (tbNationalPay.Text == "") ? default(decimal) : decimal.Parse(tbNationalPay.Text),
                            PERSONNELID = new Guid(hidPersonnal.Value),
                            PRODUCEDATE = (tbProduceDate.Text == "") ? default(DateTime) : DateTime.Parse(tbProduceDate.Text),
                            PRODUCESORT = (ddlProduceSort.SelectedValue == "0") ? Guid.Empty : new Guid(ddlProduceSort.SelectedValue),
                            PRODUCINGAREA = tbProducingArea.Text,
                            PURCHASEDATE = DateTime.Parse(tbPurchaseDate.Text),
                            PURPOSEID = instrumentPurpose,
                            REALMID = instrumentDomain,
                            REMARK = tbRemark.Text,
                            SPECTYPE = tbSpecific.Text,
                            TOTALLY = int.Parse(ddlTotally.SelectedValue),
                            UPDATEDATE = System.DateTime.Now,
                            VALUERMB = decimal.Parse(tbValueRMB.Text),
                            WorkingforUnitId = new Guid(hidUnit.Value),
                            WRITEDATE = System.DateTime.Now,
                            CLASSCODE = machineClass,
                            Id = instrumentCode.Id,
                            UseState = int.Parse(ddlUseState.SelectedValue),
                            WorkState = int.Parse(ddlWorkState.SelectedValue),
                            AUDITINGSTATE = 2,

                            /**************添加采集盒状态****************/

                            Gather = !string.IsNullOrEmpty(ddlGather.SelectedValue) ? int.Parse(ddlGather.SelectedValue) : 0,

                        };
                        instrument.Save();
                        SaveTag(instrument.Id);
                        break;
                    case "企业":
                        CY.CSTS.Core.Business.EnterpriseInstrument enterpriseInstrument = new CY.CSTS.Core.Business.EnterpriseInstrument
                        {
                            ACCEPTMISSION = int.Parse(ddlAcceptMission.SelectedValue),
                            ALIAS = tbAlias.Text,
                            ASSESSOR = u.Name,// "load from session",
                            AUDITINGDATE = System.DateTime.Now,
                            BUGETSOURCE = (ddlBudgeSource.SelectedValue == "0") ? Guid.Empty : new Guid(ddlBudgeSource.SelectedValue),
                            SITE = new Guid(ddlProvince.SelectedValue),
                            CITY = new Guid(Request.Form["ddlCity"]),
                            COUNTRYCODE = (ddlCountry.SelectedValue == "0") ? Guid.Empty : new Guid(ddlCountry.SelectedValue),
                            DISCARDTIME = (tbDisgardTime.Text == "") ? default(DateTime) : DateTime.Parse(tbDisgardTime.Text),
                            ENAME = tbEnglishName.Text,
                            EXAMINATION = (ddlExamination.SelectedValue == "0") ? Guid.Empty : new Guid(ddlExamination.SelectedValue),
                            EXTERNALSERVICE = int.Parse(ddlExternalService.SelectedValue),
                            FUNCTIONFEATURES = tbFunctionFeatures.Text,
                            GETMODE = (ddlGetMode.SelectedValue == "0") ? Guid.Empty : new Guid(ddlGetMode.SelectedValue),
                            GUIDELINE = tbGuidline.Text,
                            HasCMA = int.Parse(ddlHasCMA.SelectedValue),
                            HNAME = tbChineseName.Text,
                            InstruCode = tbInstrumentCode.Text,
                            IsSpecial = int.Parse(ddlIsSpecial.SelectedValue),
                            LaboratoryId = (hidLab.Value == "" || hidLab.Value == null) ? Guid.Empty : new Guid(hidLab.Value),
                            MachineGroupId = machinegroupid,
                            MANUFACTURE = tbManufacturer.Text,
                            NATIONALPAY = (tbNationalPay.Text == "") ? default(decimal) : decimal.Parse(tbNationalPay.Text),
                            PERSONNELID = new Guid(hidPersonnal.Value),
                            PRODUCEDATE = (tbProduceDate.Text == "") ? default(DateTime) : DateTime.Parse(tbProduceDate.Text),
                            PRODUCESORT = (ddlProduceSort.SelectedValue == "0") ? Guid.Empty : new Guid(ddlProduceSort.SelectedValue),
                            PRODUCINGAREA = tbProducingArea.Text,
                            PURCHASEDATE = DateTime.Parse(tbPurchaseDate.Text),
                            PURPOSEID = instrumentPurpose,
                            REALMID = instrumentDomain,
                            REMARK = tbRemark.Text,
                            SPECTYPE = tbSpecific.Text,
                            TOTALLY = int.Parse(ddlTotally.SelectedValue),
                            UPDATEDATE = System.DateTime.Now,
                            VALUERMB = decimal.Parse(tbValueRMB.Text),
                            WorkingforUnitId = new Guid(hidUnit.Value),
                            WRITEDATE = System.DateTime.Now,
                            CLASSCODE = machineClass,
                            Id = instrumentCode.Id,
                            UseState = int.Parse(ddlUseState.SelectedValue),
                            WorkState = int.Parse(ddlWorkState.SelectedValue),
                            AUDITINGSTATE = 2,
                            Gather = !string.IsNullOrEmpty(ddlGather.SelectedValue) ? int.Parse(ddlGather.SelectedValue) : 0
                        };
                        enterpriseInstrument.Save();
                        SaveTag(enterpriseInstrument.Id);
                        break;
                    case "高校":
                        CY.CSTS.Core.Business.UniversityInstrument universityInstrument = new CY.CSTS.Core.Business.UniversityInstrument
                        {
                            ACCEPTMISSION = int.Parse(ddlAcceptMission.SelectedValue),
                            ALIAS = tbAlias.Text,
                            ASSESSOR = u.Name,// "load from session",
                            AUDITINGDATE = System.DateTime.Now,
                            BUGETSOURCE = (ddlBudgeSource.SelectedValue == "0") ? Guid.Empty : new Guid(ddlBudgeSource.SelectedValue),
                            SITE = new Guid(ddlProvince.SelectedValue),
                            CITY = new Guid(Request.Form["ddlCity"]),
                            COUNTRYCODE = (ddlCountry.SelectedValue == "0") ? Guid.Empty : new Guid(ddlCountry.SelectedValue),
                            DISCARDTIME = (tbDisgardTime.Text == "") ? default(DateTime) : DateTime.Parse(tbDisgardTime.Text),
                            ENAME = tbEnglishName.Text,
                            EXAMINATION = (ddlExamination.SelectedValue == "0") ? Guid.Empty : new Guid(ddlExamination.SelectedValue),
                            EXTERNALSERVICE = int.Parse(ddlExternalService.SelectedValue),
                            FUNCTIONFEATURES = tbFunctionFeatures.Text,
                            GETMODE = (ddlGetMode.SelectedValue == "0") ? Guid.Empty : new Guid(ddlGetMode.SelectedValue),
                            GUIDELINE = tbGuidline.Text,
                            HasCMA = int.Parse(ddlHasCMA.SelectedValue),
                            HNAME = tbChineseName.Text,
                            InstruCode = tbInstrumentCode.Text,
                            IsSpecial = int.Parse(ddlIsSpecial.SelectedValue),
                            LaboratoryId = (hidLab.Value == "" || hidLab.Value == null) ? Guid.Empty : new Guid(hidLab.Value),
                            MachineGroupId = machinegroupid,
                            MANUFACTURE = tbManufacturer.Text,
                            NATIONALPAY = (tbNationalPay.Text == "") ? default(decimal) : decimal.Parse(tbNationalPay.Text),
                            PERSONNELID = new Guid(hidPersonnal.Value),
                            PRODUCEDATE = (tbProduceDate.Text == "") ? default(DateTime) : DateTime.Parse(tbProduceDate.Text),
                            PRODUCESORT = (ddlProduceSort.SelectedValue == "0") ? Guid.Empty : new Guid(ddlProduceSort.SelectedValue),
                            PRODUCINGAREA = tbProducingArea.Text,
                            PURCHASEDATE = DateTime.Parse(tbPurchaseDate.Text),
                            PURPOSEID = instrumentPurpose,
                            REALMID = instrumentDomain,
                            REMARK = tbRemark.Text,
                            SPECTYPE = tbSpecific.Text,
                            TOTALLY = int.Parse(ddlTotally.SelectedValue),
                            UPDATEDATE = System.DateTime.Now,
                            VALUERMB = decimal.Parse(tbValueRMB.Text),
                            WorkingforUnitId = new Guid(hidUnit.Value),
                            WRITEDATE = System.DateTime.Now,
                            CLASSCODE = machineClass,
                            Id = instrumentCode.Id,
                            UseState = int.Parse(ddlUseState.SelectedValue),
                            WorkState = int.Parse(ddlWorkState.SelectedValue),
                            AUDITINGSTATE = 2,
                             Gather = !string.IsNullOrEmpty(ddlGather.SelectedValue) ? int.Parse(ddlGather.SelectedValue) : 0
                        };
                        universityInstrument.Save();
                        SaveTag(universityInstrument.Id);
                        break;
                    default:
                        break;
                }
                #endregion

                //添加仪器图片及视频信息
                SaveFiles(instrumentCode.Id);
                SaveImg(instrumentCode.Id);
                #endregion

                #region 添加仪器附件信息
                //添加仪器附件
                string[] attachModel = Request.Form.GetValues("tbAttachmentModel");
                string[] attachNum = Request.Form.GetValues("tbAttachmentNum");
                string[] mainFunction = Request.Form.GetValues("tbMainFunction");
                string[] attachName = Request.Form.GetValues("tbAttachmentName");
                string[] attachPrice = Request.Form.GetValues("tbAttachmentPrice");
                string[] attachManufacturer = Request.Form.GetValues("tbAttachmentManufacturer");
                string[] attachRemark = Request.Form.GetValues("tbAttachRemark");
                if (attachName.Length != 0)
                {
                    for (int i = 0; i < attachName.Length; i++)
                    {
                        if (attachName[i] != "")
                        {
                            CY.CSTS.Core.Business.INSTRATTACHMENT attachment = new CY.CSTS.Core.Business.INSTRATTACHMENT
                            {
                                InstruId = instrumentCode.Id,
                                ATTACHMENTNAME = attachName[i],
                                //ATTACHMENTAMOUNT = int.Parse(attachNum[i]),
                                //ATTACHMENTPRICE = decimal.Parse(attachPrice[i]),
                                ATTACHMENTSPEC = attachModel[i],
                                MANUFACTURER = attachManufacturer[i],
                                PURPOSE = mainFunction[i],
                                REMARK = attachRemark[i],
                                WRITEDATE = System.DateTime.Now,
                                UPDATEDATE = System.DateTime.Now
                            };
                            attachment.Save();
                        }
                    }
                }
                #endregion

                #region 添加仪器应用信息
                string[] appDate = Request.Form.GetValues("tbApplicationDate");
                string[] famousUser = Request.Form.GetValues("tbFamousUser");
                string[] influentialNum = Request.Form.GetValues("tbInfluentialNum");
                string[] trait = Request.Form.GetValues("tbTrait");
                string[] appFruit = Request.Form.GetValues("tbApplicationFruit");
                string[] appRemark = Request.Form.GetValues("tbApplicationRemark");

                if (appDate.Length != 0)
                {
                    for (int i = 0; i < appDate.Length; i++)
                    {
                        if (appDate[i] != "")
                        {
                            CY.CSTS.Core.Business.INSTRAPPLICATION application = new CY.CSTS.Core.Business.INSTRAPPLICATION
                            {
                                InstruId = instrumentCode.Id,
                                YEAR = DateTime.Parse(appDate[i]),
                                FAMOUSUSERS = famousUser[i],
                                INFLUENTIALNUM = int.Parse(influentialNum[i]),
                                FRUIT = appFruit[i],
                                TRAIT = trait[i],
                                REMARK = appRemark[i],
                                WRITEDATE = System.DateTime.Now,
                                UPDATEDATE = System.DateTime.Now
                            };
                            application.Save();
                        }
                    }
                }
                #endregion

                #region 添加仪器测试项目收费标准信息
                string[] feeType = Request.Form.GetValues("tbFeeType");
                string[] feeStandard = Request.Form.GetValues("tbFeeStandard");
                string[] feeItem = Request.Form.GetValues("tbFeeItem");
                string[] feeRemark = Request.Form.GetValues("tbFeeRemark");

                if (feeItem.Length != 0)
                {
                    for (int i = 0; i < feeItem.Length; i++)
                    {
                        if (feeItem[i] != "")
                        {
                            CY.CSTS.Core.Business.INSTRFEE instrfee = new CY.CSTS.Core.Business.INSTRFEE
                            {
                                InstruId = instrumentCode.Id,
                                FEEITEM = feeItem[i],
                                FEECLASS = feeType[i],
                                FEESTANDARD = feeStandard[i],
                                REMARK = feeRemark[i],
                                WRITEDATE = System.DateTime.Now,
                                UPDATEDATE = System.DateTime.Now
                            };
                            instrfee.Save();
                        }
                    }
                }
                #endregion

                #region 添加仪器服务信息
                string[] outOffered = Request.Form.GetValues("ddlOutOffered");
                string[] serivceType = Request.Form.GetValues("ddlSerivceType");
                string[] serviceIncome = Request.Form.GetValues("tbServiceIncome");
                string[] atlasName = Request.Form.GetValues("tbAtlasName");
                string[] serviceExplain = Request.Form.GetValues("tbServiceExplain");
                string[] offerTime = Request.Form.GetValues("tbOfferTime");
                string[] testSampleNum = Request.Form.GetValues("tbTestSampleNum");
                string[] atlasManufacturer = Request.Form.GetValues("tbAtlasManufacturer");
                string[] serviceRemark = Request.Form.GetValues("tbServiceRemark");

                if (outOffered.Length != 0)
                {
                    for (int i = 0; i < outOffered.Length; i++)
                    {
                        if (offerTime[i] != "" && testSampleNum[i] != "")
                        {
                            CY.CSTS.Core.Business.INSTRSERVICE instrservice = new CY.CSTS.Core.Business.INSTRSERVICE
                            {
                                INSTRUMENTID = instrumentCode.Id,
                                OUTOFFERED = int.Parse(outOffered[i]),
                                SERVICECLASS = serivceType[i],
                                OFFERTIME = int.Parse(offerTime[i]),
                                ATLASMANUFACTURER = atlasManufacturer[i],
                                ATLASNAME = atlasName[i],
                                ServiceIncome = decimal.Parse(serviceIncome[i]),
                                TestSampleNum = int.Parse(testSampleNum[i]),
                                SERVICEEXPLAIN = serviceExplain[i],
                                REMARK = serviceRemark[i],
                                WRITEDATE = System.DateTime.Now,
                                UPDATEDATE = System.DateTime.Now
                            };
                            instrservice.Save();
                        }
                    }
                }
                #endregion

                CY.CSTS.Core.Business.FreshNews fresh = new CY.CSTS.Core.Business.FreshNews();
                fresh.Sponsor = "管理员";
                fresh.FreshEvent = "添加仪器" + tbSetName.Text;
                if (tbEnglishName.Text.Trim() != "")
                {
                    fresh.FreshEvent += "(" + tbEnglishName.Text + ")";
                }
                fresh.Embracer = tbUnit.Text.Trim();

                fresh.EmbracerId = new Guid(hidUnit.Value);
                fresh.UnitId = new Guid(hidUnit.Value);
                fresh.EventType = 3;
                fresh.EventTime = DateTime.Now;
                Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script type='text/javascript'>alert('添加成功!');window.location.href='InstrumentList.aspx';</script>");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }