private void _ReprintBtn_Click(object sender, EventArgs e)
        {
            DialogResult dialog = MessageBox.Show("Reprint existing label(Yes) or create new label(No)?", "Warning", MessageBoxButtons.YesNo);

            if (dialog == DialogResult.Yes)
            {
                DataRow dr                 = Db.GetShipmentInfoByOrder(this._OrderNumTxt.Text, this._ChannelTxt.Text);
                string  nativeCommand      = dr["LabelCommand"].ToString();
                byte[]  data               = Convert.FromBase64String(nativeCommand);
                string  encodedLabelBinary = Encoding.UTF8.GetString(data);
                RawPrinterHelper.SendStringToPrinter(ConfigurationManager.AppSettings["printerName"], encodedLabelBinary);
            }
            else if (dialog == DialogResult.No)
            {
                if (this._ShipCountry.Text != "US")
                {
                    MessageBox.Show("Not Support Yet!");
                    //Dictionary<string, string> labelDict = ProcessShippingLabel.GetInternationalLabel(this._OrderNumTxt.Text, this._ChannelTxt.Text);
                    //string printResult = PrintShippingLabel.Print(labelDict);
                    //if (printResult == "Error, Email Sent")
                    //{
                    //   MessageBox.Show("Error, Email Sent");
                    //}
                }
                else
                {
                    string customizedWeight = (Interaction.InputBox("Input Weight", this._OrderNumTxt.Text));
                    Dictionary <string, string> labelDict = ProcessShippingLabel.GetDomesticLabel(this._OrderNumTxt.Text, this._ChannelTxt.Text, customizedWeight, "");
                    string printResult = PrintShippingLabel.Print(labelDict);
                    if (printResult == "Error, Email Sent")
                    {
                        MessageBox.Show("Error, Email Sent");
                    }
                }
            }
        }
Example #2
0
        private void _PrintShippingLabelBtn_Click(object sender, EventArgs e)
        {
            DataTable readyToPrintDt = new DataTable();

            readyToPrintDt.Columns.Add("OrderNum", typeof(string));
            readyToPrintDt.Columns.Add("Channel", typeof(string));
            readyToPrintDt.Columns.Add("ShipCountry", typeof(string));
            readyToPrintDt.Columns.Add("CustomizedWeight", typeof(string));
            readyToPrintDt.Columns.Add("CustomizedMessage", typeof(string));


            int selectedRowCount = this._OrderDgv.Rows.GetRowCount(DataGridViewElementStates.Selected);

            if (selectedRowCount > 0)
            {
                List <string> customizedItemKeyWordList = ConfigurationManager.AppSettings["CustomizedItemKeyWord"].Split(',').ToList();
                for (int i = 0; i < selectedRowCount; i++)
                {
                    string  orderNum          = this._OrderDgv.SelectedRows[i].Cells[cellOrderNum].Value.ToString();
                    string  channel           = this._OrderDgv.SelectedRows[i].Cells[cellChannel].Value.ToString();
                    string  shippedDate       = this._OrderDgv.SelectedRows[i].Cells[cellShippedDate].Value.ToString();
                    string  shipCountry       = this._OrderDgv.SelectedRows[i].Cells[cellShipCountry].Value.ToString();
                    string  customizedMessage = this._OrderDgv.SelectedRows[i].Cells[cellCustomizedMessage].Value.ToString();
                    DataRow readyToPrintDr    = readyToPrintDt.NewRow();
                    if (shippedDate == "1/1/1753 12:00:00 AM")
                    {
                        DataTable orderLineTitleDt      = MarketplaceDb.Db.GetOrderLineDtByOrderNum(orderNum, channel);
                        string    orderItems            = "";
                        string    itemCustomizedMessage = "";
                        foreach (DataRow orderLineTitleDr in orderLineTitleDt.Rows)
                        {
                            string itemTitle = orderLineTitleDr["ItemDesc"].ToString();
                            string sku       = orderLineTitleDr["ItemNum"].ToString();
                            string qty       = orderLineTitleDr["Quantity"].ToString();
                            orderItems = orderItems + sku + "(" + qty + ")" + "|";
                            var ifCustomizedItem = customizedItemKeyWordList.Any(w => itemTitle.Contains(w));
                            if (ifCustomizedItem)
                            {
                                itemCustomizedMessage = itemCustomizedMessage + "~~~" + (Interaction.InputBox("Input Customized Message", orderItems, customizedMessage));
                            }
                        }
                        MarketplaceDb.Db.SaveNoteToDb(orderNum, channel, itemCustomizedMessage);
                        DataRow existingWeightDr = MarketplaceDb.Db.CheckDuplicatedCustomizedWeight(orderItems);
                        if (existingWeightDr == null)
                        {
                            string customizedWeight = (Interaction.InputBox("Input Weight", orderItems));

                            while (ConvertUtility.ToInt(customizedWeight) <= 0)
                            {
                                MessageBox.Show("Weight must more than 0! Please re-enter one");
                                customizedWeight = (Interaction.InputBox("Input Weight", orderItems));
                            }
                            MarketplaceDb.Db.SaveCustomizedWeight(orderItems, ConvertUtility.ToInt(customizedWeight));
                            readyToPrintDr["CustomizedWeight"] = customizedWeight;
                        }
                        else
                        {
                            readyToPrintDr["CustomizedWeight"] = existingWeightDr["CustomizedWeight"].ToString();
                        }

                        readyToPrintDr["OrderNum"]          = orderNum;
                        readyToPrintDr["Channel"]           = channel;
                        readyToPrintDr["ShipCountry"]       = shipCountry;
                        readyToPrintDr["CustomizedMessage"] = itemCustomizedMessage;
                        readyToPrintDt.Rows.Add(readyToPrintDr);
                    }
                    else
                    {
                        MessageBox.Show("OrderNum: " + orderNum + " has been printed already. Please go to order details form to reprint it");
                    }
                }
                foreach (DataRow dr in readyToPrintDt.Rows)
                {
                    string orderNum          = dr["OrderNum"].ToString();
                    string channel           = dr["Channel"].ToString();
                    string shipCountry       = dr["ShipCountry"].ToString();
                    string customizedWeight  = dr["CustomizedWeight"].ToString();
                    string customizedMessage = dr["CustomizedMessage"].ToString();
                    if (shipCountry != "US")
                    {
                        MessageBox.Show("Not Support International Shipping Yet!");

                        //Dictionary<string, string> labelDict = ProcessShippingLabel.GetInternationalLabel(orderNum, channel);
                        //string printResult = PrintShippingLabel.Print(labelDict);
                        //if(printResult== "Error, Email Sent")
                        //{
                        //    MessageBox.Show("Error, Email Sent");
                        //}
                    }
                    else
                    {
                        Dictionary <string, string> labelDict = ProcessShippingLabel.GetDomesticLabel(orderNum, channel, customizedWeight, customizedMessage);
                        string printResult = PrintShippingLabel.Print(labelDict);
                        if (printResult == "Error, Email Sent")
                        {
                            MessageBox.Show("Error, Email Sent");
                        }
                    }
                }
                MessageBox.Show("Printed!!");
            }
            else
            {
                MessageBox.Show("Please select an unshipped order at least");
            }
        }