コード例 #1
0
    /// <summary>
    ///
    /// </summary>
    private void DoMap()
    {
        try
        {
            Dictionary <string, string> itemFileMap = new Dictionary <string, string>();

            // first let's retrieve all the files that have been set which item code to map to
            foreach (string key in Request.Form.AllKeys)
            {
                if (key.EndsWith("cboItemCode"))
                {
                    //
                    string itemCode = Request.Form[key];
                    if (!string.IsNullOrEmpty(itemCode))
                    {
                        if (itemFileMap.ContainsKey(itemCode))
                        {
                            throw new DownloadMappingException("Duplicate mapping exists! please remove the duplicate");
                        }
                        else
                        {
                            // retrieve the file name for this mapping file
                            // since were assuming the id in this format _ctl0:pnlMain:grdList:_ctl18:cboItemCode
                            // we will find our map(which is just a supporting field) through the item code combo box
                            string mapKey = key.Replace("cboItemCode", "map");

                            string mapFile = Request.Form[mapKey];
                            if (string.IsNullOrEmpty(mapFile))
                            {
                                throw new InvalidOperationException("Map file not found!!!");
                            }
                            else
                            {
                                itemFileMap.Add(itemCode, mapFile);
                            }
                        }
                    }
                }
            }

            List <DownloadableItem> mappedDownloads = new List <DownloadableItem>();

            foreach (string itemCode in itemFileMap.Keys)
            {
                string           fileName = itemFileMap[itemCode];
                DownloadableItem item     = DownloadableItem.MapNew(itemCode, fileName);
                mappedDownloads.Add(item);
            }

            if (mappedDownloads.Count > 0)
            {
                grdMapped.Visible    = true;
                grdMapped.DataSource = mappedDownloads;
                grdMapped.DataBind();

                lblError.Text = string.Empty;
            }
            else
            {
                grdMapped.Visible = true;
                lblError.Text     = "Please map one(1) or more files";
            }
        }
        catch (DownloadMappingException dmap)
        {
            lblError.Text = dmap.Message;
        }
    }