Beispiel #1
0
 private void PalletsListDg_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
 {
     try
     {
         if (PalletsListDg.SelectedItem != null)
         {
             dtPallet pallet     = PalletsListDg.SelectedItem as dtPallet;
             dynamic  palletData = JsonConvert.DeserializeObject(pallet.dataPallet);
             palletBayId.Text = (palletData.bayId != null) ? (((double)palletData.bayId).ToString()) : "-1";
             palletX.Text     = (palletData.line.x != null) ? (((double)palletData.line.x).ToString()) : "0";
             palletY.Text     = (palletData.line.y != null) ? (((double)palletData.line.y).ToString()) : "0";
             palletA.Text     = (palletData.line.angle != null) ? (((double)palletData.line.angle).ToString()) : "0";
             //palletR.Text = (palletData != null) ? (((double)palletData.pallet.row).ToString()) : "0";
             palletR.Text = pallet.row.ToString();
             //{"line":{"x":-4.19,"y":-13.69,"angle":0.0},"pallet":{"row":0,"bay":0,"dir_main":1,"dir_sub":1,"dir_out":2,"line_ord":0,"hasSubLine":"yes"}}
             //palletR.Text = (palletData.pallet.row != null) ? (((int)palletData.pallet.row).ToString()) : pallet.row.ToString();
             palletB.Text = pallet.bay.ToString();
             //palletB.Text = (palletData.pallet.bay != null) ? (((int)palletData.pallet.bay).ToString()) : pallet.bay.ToString();
             palletRowlb.Content   = pallet.row;
             palletBaylb.Content   = pallet.bay;
             palletD_Main.Text     = (palletData.pallet.dir_main != null) ? ((palletData.pallet.dir_main).ToString()) : "0";
             palletD_Sub.Text      = (palletData.pallet.dir_sub != null) ? ((palletData.pallet.dir_sub).ToString()) : "0";
             palletD_Out.Text      = (palletData.pallet.dir_out != null) ? ((palletData.pallet.dir_out).ToString()) : "0";
             palletL_Ord.Text      = (palletData.pallet.line_ord != null) ? ((palletData.pallet.line_ord).ToString()) : "0";
             palletHasSubLine.Text = (palletData.pallet.hasSubLine != null) ? ((palletData.pallet.hasSubLine).ToString()) : "no";
             //palletX.Focus();
             //palletX.SelectAll();
         }
     }
     catch (Exception ex)
     {
         logFile.Error(ex.Message);
     }
 }
Beispiel #2
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                dtPallet pallet = (sender as System.Windows.Controls.Button).DataContext as dtPallet;
                //if (pallet.palletStatus == "F")
                //{
                //    return;
                //}
                pallet.palletStatus = "W";
                string jsonData = JsonConvert.SerializeObject(pallet);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "pallet/updatePalletStatus");
                request.Method      = "POST";
                request.ContentType = "application/json";

                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    int          result = 0;
                    int.TryParse(reader.ReadToEnd(), out result);
                    if (result == 1)
                    {
                        //System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveSucced), Global_Object.messageTitileInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result == -2)
                    {
                        // System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDuplicated, "Pallets Name"), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        //System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveFail), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                Dispatcher.BeginInvoke(new ThreadStart(() =>
                {
                    stationEditorModel.ReloadListPallets(this.stationShape.props.bufferDb.bufferId);
                }));
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
Beispiel #3
0
 public bool ContainPallet(dtPallet tempOpe, List <dtPallet> List)
 {
     foreach (dtPallet temp in List)
     {
         if (temp.palletId > 0)
         {
             if (temp.palletId == tempOpe.palletId)
             {
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Beispiel #4
0
        public void ReloadListPallets(int bufferId)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                palletsList.Clear();
                HttpWebRequest request =
                    (HttpWebRequest)WebRequest.Create(@"http://" +
                                                      Properties.Settings.Default.serverIp + ":" +
                                                      Properties.Settings.Default.serverPort +
                                                      @"/robot/rest/" + "pallet/getListPalletBufferId");
                request.Method      = "POST";
                request.ContentType = @"application/json";
                dynamic postApiBody = new JObject();
                postApiBody.bufferId = bufferId;
                string jsonData = JsonConvert.SerializeObject(postApiBody);
                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }
                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    string       result = reader.ReadToEnd();

                    DataTable pallets = JsonConvert.DeserializeObject <DataTable>(result);
                    foreach (DataRow dr in pallets.Rows)
                    {
                        dtPallet tempPallet = new dtPallet
                        {
                            creUsrId          = int.Parse(dr["creUsrId"].ToString()),
                            creDt             = dr["creDt"].ToString(),
                            updUsrId          = int.Parse(dr["updUsrId"].ToString()),
                            updDt             = dr["updDt"].ToString(),
                            palletId          = int.Parse(dr["palletId"].ToString()),
                            deviceBufferId    = int.Parse(dr["deviceBufferId"].ToString()),
                            bufferId          = int.Parse(dr["bufferId"].ToString()),
                            planId            = int.Parse(dr["planId"].ToString()),
                            activeDate        = dr["activeDate"].ToString(),
                            row               = int.Parse(dr["row"].ToString()),
                            bay               = int.Parse(dr["bay"].ToString()),
                            dataPallet        = dr["dataPallet"].ToString(),
                            palletStatus      = dr["palletStatus"].ToString(),
                            deviceId          = int.Parse(dr["deviceId"].ToString()),
                            deviceName        = dr["deviceName"].ToString(),
                            productId         = int.Parse(dr["productId"].ToString()),
                            productName       = dr["productName"].ToString(),
                            productDetailId   = int.Parse(dr["productDetailId"].ToString()),
                            productDetailName = dr["productDetailName"].ToString(),
                        };
                        if (!ContainPallet(tempPallet, palletsList))
                        {
                            palletsList.Add(tempPallet);
                        }
                    }
                }
                if (GroupedPallets.IsEditingItem)
                {
                    GroupedPallets.CommitEdit();
                }

                if (GroupedPallets.IsAddingNew)
                {
                    GroupedPallets.CommitNew();
                }

                GroupedPallets.Refresh();
                if (stationEditor.PalletsListDg.HasItems)
                {
                    stationEditor.PalletsListDg.SelectedItem = stationEditor.PalletsListDg.Items[0];
                    //devicesManagement.PalletsListDg.ScrollIntoView(devicesManagement.PalletsListDg.SelectedItem);
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
Beispiel #5
0
        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                dtPallet temp = (sender as System.Windows.Controls.Button).DataContext as dtPallet;
                //dtPallet temp = (sender as System.Windows.Controls.DataGrid).SelectedItem as dtPallet;
                //temp.updUsrId = Global_Object.userLogin;
                //string palletCellEdit = ((e.EditingElement as System.Windows.Controls.TextBox).Text.Trim());
                List <dtPallet> pallets = new List <dtPallet>();

                //dtPallet pallet = PalletsListDg.SelectedItem as dtPallet;
                dtPallet pallet = temp;

                dynamic palletData   = new JObject();
                dynamic palletLine   = new JObject();
                dynamic palletPallet = new JObject();

                palletLine.x     = double.Parse((palletX.Text != "") ? palletX.Text : "0");
                palletLine.y     = double.Parse((palletY.Text != "") ? palletY.Text : "0");
                palletLine.angle = double.Parse((palletA.Text != "") ? palletA.Text : "0");

                palletPallet.row        = int.Parse((palletR.Text != "") ? palletR.Text : "0");
                palletPallet.bay        = int.Parse((palletB.Text != "") ? palletB.Text : "0");
                palletPallet.dir_main   = int.Parse((palletD_Main.Text != "") ? palletD_Main.Text : "0");
                palletPallet.dir_sub    = int.Parse((palletD_Sub.Text != "") ? palletD_Sub.Text : "0");
                palletPallet.dir_out    = int.Parse((palletD_Out.Text != "") ? palletD_Out.Text : "0");
                palletPallet.line_ord   = int.Parse((palletL_Ord.Text != "") ? palletL_Ord.Text : "0");
                palletPallet.hasSubLine = (palletHasSubLine.Text != "") ? palletHasSubLine.Text : "no";

                palletData.line   = palletLine;
                palletData.pallet = palletPallet;

                string jsonBufferData = JsonConvert.SerializeObject(palletData);
                pallet.dataPallet = jsonBufferData;

                pallets.Add(pallet);

                if (pallets.Count == 0)
                {
                    System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageNoDataSave), Global_Object.messageTitileWarning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                string jsonData = JsonConvert.SerializeObject(pallets);

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "pallet/updateListPalletData");
                request.Method      = "POST";
                request.ContentType = "application/json";

                System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                Byte[] byteArray = encoding.GetBytes(jsonData);
                request.ContentLength = byteArray.Length;
                using (Stream dataStream = request.GetRequestStream())
                {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    dataStream.Flush();
                }

                HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                    int          result = 0;
                    int.TryParse(reader.ReadToEnd(), out result);
                    if (result == 1)
                    {
                        //System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveSucced), Global_Object.messageTitileInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (result == -2)
                    {
                        System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDuplicated, "Pallets Name"), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveFail), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }
Beispiel #6
0
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            if (!Global_Object.ServerAlive())
            {
                return;
            }
            try
            {
                dtPallet pallet = (sender as System.Windows.Controls.Button).DataContext as dtPallet;
                if ((stationShape.props.bufferDb.bufferReturn == false) && (pallet.palletStatus == "W"))
                {
                    bool sendToReturn = true;
                    //Any pallet before needed send pallet need to be "Free"
                    foreach (dtPallet palletItem in stationShape.props.bufferDb.pallets)
                    {
                        if ((palletItem.bay == pallet.bay) && (palletItem.row < pallet.row))
                        {
                            if (palletItem.palletStatus != "F")
                            {
                                sendToReturn = false;
                                Console.WriteLine("Khong cho phep Return!");
                                break;
                            }
                        }
                    }
                    if (sendToReturn)
                    {
                        Console.WriteLine("Duoc phep Return!");
                        dynamic postApiBody = new JObject();
                        postApiBody.userName          = "******";
                        postApiBody.bufferId          = pallet.bufferId;
                        postApiBody.productDetailId   = pallet.productDetailId;
                        postApiBody.productDetailName = pallet.productDetailName;
                        postApiBody.productDetailName = pallet.productDetailName;
                        postApiBody.productId         = pallet.productId;
                        //postApiBody.planId = pallet.planId;
                        postApiBody.deviceId = pallet.deviceId;
                        postApiBody.typeReq  = 13;
                        string jsonData = JsonConvert.SerializeObject(postApiBody);
                        BridgeClientRequest bridgeClientRequest = new BridgeClientRequest();
                        bridgeClientRequest.PostCallAPI("http://" + Properties.Settings.Default.serverReturnIp + ":12000", jsonData);

                        pallet.palletStatus = "R";
                        string jsonDataPallet = JsonConvert.SerializeObject(pallet);

                        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://" + Properties.Settings.Default.serverIp + ":" + Properties.Settings.Default.serverPort + @"/robot/rest/" + "pallet/updatePalletStatus");
                        request.Method      = "POST";
                        request.ContentType = "application/json";

                        System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
                        Byte[] byteArray = encoding.GetBytes(jsonDataPallet);
                        request.ContentLength = byteArray.Length;
                        using (Stream dataStream = request.GetRequestStream())
                        {
                            dataStream.Write(byteArray, 0, byteArray.Length);
                            dataStream.Flush();
                        }

                        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
                        using (Stream responseStream = response.GetResponseStream())
                        {
                            StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                            int          result = 0;
                            int.TryParse(reader.ReadToEnd(), out result);
                            if (result == 1)
                            {
                                //System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveSucced), Global_Object.messageTitileInformation, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else if (result == -2)
                            {
                                // System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageDuplicated, "Pallets Name"), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else
                            {
                                //System.Windows.Forms.MessageBox.Show(String.Format(Global_Object.messageSaveFail), Global_Object.messageTitileError, MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                        Dispatcher.BeginInvoke(new ThreadStart(() =>
                        {
                            stationEditorModel.ReloadListPallets(this.stationShape.props.bufferDb.bufferId);
                        }));
                    }
                }
                else
                {
                    Console.WriteLine("Khong cho phep Return!");
                }
            }
            catch (Exception ex)
            {
                logFile.Error(ex.Message);
            }
        }