Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            string modetypename = this.txtmodetypename.Text;
            int    typeId       = int.Parse(this.txttypeId.Text);
            int    isOpen       = 0;

            int.TryParse(ddlOpen.SelectedValue, out isOpen);
            int supplier = 0;

            int.TryParse(this.ddlSupplier.SelectedValue, out supplier);

            int supplier2 = 0;

            if (!string.IsNullOrEmpty(this.ddlSupplier2.SelectedValue))
            {
                int.TryParse(this.ddlSupplier2.SelectedValue, out supplier2);
            }

            int  sort    = int.Parse(this.txtsort.Text);
            bool release = this.rblRelease.SelectedValue == "1" ? true :false;
            int  classId = Convert.ToInt32(this.rblType.SelectedValue);

            if (!IsUpdate)
            {
                ItemInfo.modetypename = modetypename;
                ItemInfo.typeId       = typeId;
                ItemInfo.Class        = (ChannelClassEnum)classId;
                ItemInfo.addtime      = DateTime.Now;
            }

            ItemInfo.isOpen = (OpenEnum)isOpen;

            ItemInfo.supplier              = supplier;
            ItemInfo.supplier2             = supplier2;
            ItemInfo.SuppsWhenExceOccurred = txtSuppsWhenExceOccurred.Text.Trim();
            ItemInfo.sort    = sort;
            ItemInfo.release = release;
            ItemInfo.runmode = int.Parse(this.rblrunmode.SelectedValue);
            ItemInfo.timeout = int.Parse(this.txttimeout.Text);



            System.Text.StringBuilder _set = new System.Text.StringBuilder();


            int count = 1;

            foreach (RepeaterItem item in rptsupp.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    HtmlInputCheckBox chkItem   = item.FindControl("chkItem") as HtmlInputCheckBox;
                    HiddenField       hfsuppid  = item.FindControl("hfsuppid") as HiddenField;
                    TextBox           txtweight = item.FindControl("txtweight") as TextBox;

                    if (chkItem != null && hfsuppid != null && txtweight != null)
                    {
                        if (chkItem.Checked)
                        {
                            int weight = 1;
                            try {
                                weight = Convert.ToInt32(txtweight.Text);
                            }
                            catch {
                                weight = 1;
                            }
                            if (count > 1)
                            {
                                _set.AppendFormat("|{0}:{1}", hfsuppid.Value, weight);
                            }
                            else
                            {
                                _set.AppendFormat("{0}:{1}", hfsuppid.Value, weight);
                            }

                            count++;
                        }
                    }
                }
            }
            ItemInfo.runset = _set.ToString();

            if (!this.IsUpdate)
            {
                int id = ChannelType.Add(ItemInfo);
                if (id > 0)
                {
                    AlertAndRedirect("保存成功!", "TypeList.aspx");
                }
                else
                {
                    ShowMessageBox("保存失败!");
                }
            }
            else
            {
                if (ChannelType.Update(ItemInfo))
                {
                    viviapi.WebComponents.WebUtility.ClearCache("CHANNELTYPE_CACHEKEY");

                    AlertAndRedirect("更新成功!", "TypeList.aspx");
                }
                else
                {
                    ShowMessageBox("更新失败!");
                }
            }
        }